Java – monitor windows directory size
I'm looking for something that can monitor the size of the windows directory and the number of files I'm talking about servers and thousands of folders (millions of files)
requirement:
>Notification size on X exceeds y time > notification on x increases file count in y time > historical graph of size and number of files (or at least save snapshot data over time) > all in a set of directories and subdirectories
I prefer the free solution, but I also hope to point out the right direction If we write it ourselves, what will we do? The available languages are ruby, groovy, Java, Perl or PowerShell (because I can write it)
Solution
You may need to check polymon, an open source system monitoring solution It allows you to use any Net language and allows you to create a custom PowerShell monitor
It stores data in the SQL Server backend and provides graphics For your purposes, you only need a script that can get the directory size and the number of files It's like:
$size = 0 $count = 0 $path = '\\unc\path\to\directory\to\monitor' get-childitem -path $path -recurse | Where-Object {$_ -is [System.IO.FileInfo]} | ForEach-Object {$size += $_.length; $count += 1}
Answer Scott's comment: of course You can wrap it in a while loop
$ESCkey = 27 Write-Host "Press the ESC key to stop sniffing" -foregroundcolor "CYAN" $Running=$true While ($Running) { if ($host.ui.RawUi.KeyAvailable) { $key = $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyUp,IncludeKeyDown") if ($key.VirtualKeyCode -eq $ESCkey) { $Running=$False } #rest of function here }
I will not perform this operation for PowerShell monitor. You can schedule it to run regularly, but the above operation will work if you want the script to run in the background You can even add some database access code to record the results to the database or to a file... What do you want