Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitoring Windows directory size

I'm looking for something that will monitor Windows directories for size and file count over time. I'm talking about a handful of servers and a few thousand folders (millions of files).

Requirements:

  • Notification on X increase in size over Y time
  • Notification on X increase in file count over Y time
  • Historical graphing (or at least saving snapshot data over time) of size and file count
  • All of this on a set of directories and their child directories

I'd prefer a free solution but would also appreciate getting pointed in the right direction. If we were to write our own, how would we go about doing that? Available languages being Ruby, Groovy, Java, Perl, or PowerShell (since I'd be writing it).

like image 393
Instantsoup Avatar asked Oct 08 '08 15:10

Instantsoup


People also ask

What is the fastest way to check folder size in Windows?

You can view folder size in Windows using one of below options. In File explorer, right click on folder for which you want to see folder size, and click on "Properties" in context menu. This will display folder properties dialog showing folder size in "Size" and "Size on disk" display field.

Can Windows display folder size?

Locate the file in Windows File Explorer. Make a right click on it and click on the option "Properties" in the drop-down menu. A window named as "[foldername] Properties" will pop up showing the folder size in "Size" and space occupied on the disk at "Size on disk" boxes respectively.

How do I monitor a folder in Windows?

You can use the ellipsis (...) button to browse for the folder. Select this option to monitor the files and folders in sub-folders in the Folder that you specified.

How do you check size of a directory or file on your system?

Microsoft Windows users Locate and highlight the file(s) or folder that you want to determine the size. Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window.


2 Answers

There are several solutions out there, including some free ones. Some that I have worked with include:

Nagios and Big Brother

A quick google search can probably find more.

like image 92
Joel Avatar answered Sep 29 '22 09:09

Joel


You might want to take a look at PolyMon, which is an open source systems monitoring solution. It allows you to write custom monitors in any .NET language, and allows you to create custom PowerShell monitors.

It stores data on a SQL Server back end and provides graphing. For your purpose, you would just need a script that would get the directory size and file count. Something 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}

In reply to Scott's comment: Sure. you could 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 would not do that for a PowerShell monitor, which you can schedule to run periodically, but for a script to run in the background, the above would work. You could even add some database access code to log the results to a database, or log it to a file.. what ever you want.

like image 29
Steven Murawski Avatar answered Sep 29 '22 07:09

Steven Murawski