Page 1 of 2
All file size from a drive nagios xi
Posted: Tue Jul 19, 2016 8:52 am
by Naveed
Hello,
I just need to ask about the subjected problem that Is there any way to monitor all folders/directory sizes using nagios xi for windows servers using below protocols
1-check_nt
2-check_nrpe
If any please help me out.
Thank you very much!
Re: All file size from a drive nagios xi
Posted: Tue Jul 19, 2016 9:27 am
by tmcdonald
You can monitor the drive/partition size, and you can monitor individual directories, but I don't know of a way to monitor all folders without spending a lot of time setting each one up individually.
Here's an example of a plugin to check directory size in Windows:
https://exchange.nagios.org/directory/P ... bs/details
I would suggest checking the Exchange for other plugins that may suit your needs.
Re: All file size from a drive nagios xi
Posted: Tue Jul 19, 2016 10:35 am
by Naveed
Can anyone else let me something know about it.
Thank you!
Re: All file size from a drive nagios xi
Posted: Tue Jul 19, 2016 1:32 pm
by mcapra
Are you able to share more about what exactly your use case is? It's hard to say whether or not a specific thing can be done with a specific plugin without specific details.
If you're using NSClient++ 0.4.3 or greater, you can do some things with CheckDisk and clever filtering:
http://docs.nsclient.org/0.4.3/referenc ... kDisk.html
Re: All file size from a drive nagios xi
Posted: Tue Jul 19, 2016 1:39 pm
by Naveed
Thank you for your reply!
My requirements are as follows:
I have a drive C:\, it contains e.g 20 files are this drive consumed 80 % of space, but we dont know which files are consuming maximum space.
I want to monitor all files are their occupied space status on it.
Like it should state that file abc.txt is of 5 gb etc
Hope so I will be able to make you understand my requirement.
Thank you!
Re: All file size from a drive nagios xi
Posted: Tue Jul 19, 2016 2:40 pm
by mcapra
I am fairly certain this is not something you could do from NSClient without leveraging a custom plugin for it.
The following powershell one-liner can print off the top 10 largest files for a given path:
Code: Select all
gci -r C:\ -ea 0 | sort Length -desc | select -f 10
Replace C:\ with your desired path. You might alter an existing powershell script on the exchange that is checking disk size to include the command above. I was able to have some success with modifying this plugin:
https://exchange.nagios.org/directory/P ... pt/details
The main problem is that getting this sort of data from the disk is going to take an
awfully long time depending on the file count. On my fresh minimal Server 2012 environment, that command by itself took a little shy of 30 seconds to run.
Re: All file size from a drive nagios xi
Posted: Tue Jul 19, 2016 7:05 pm
by Box293
There are some file based checks in NSClient++, have a look at this link which provides examples on "Files Greater Than A Size".
http://sites.box293.com/nagios/guides/c ... es-folders
Re: All file size from a drive nagios xi
Posted: Wed Jul 20, 2016 10:15 am
by Naveed
I have attached the command from which its listing down all the files those are of size greater than 1 gb upon my set thresholds.
I dont want to monitor file size from a directory/folder,
I want to monitor the folder sizes in gb not file size,
Please assist
Thank you!
Re: All file size from a drive nagios xi
Posted: Wed Jul 20, 2016 2:35 pm
by tgriep
Just to be clear, you want to have a check that tells you how much space all of the files in one folder takes up on the system?
Re: All file size from a drive nagios xi
Posted: Wed Jul 20, 2016 2:36 pm
by mcapra
Here's a powershell script I hacked together that might offer some assistance. I make no claims it will solve your use case, only that is does the things described below. Based on this plugin:
https://exchange.nagios.org/directory/P ... pt/details
Code: Select all
# Get fixed drive info for specified server
param([string] $warn, [string] $crit)
###################################
# Top Largest Folders Scan
###################################
Function folderScan($rootLocation) {
$subDirectories = Get-ChildItem $rootLocation | Where-Object{($_.PSIsContainer)} | foreach-object{$_.Name}
foreach ($i in $subDirectories)
{
$targetDir = $rootLocation + $i
$folderSize = (Get-ChildItem $targetDir -Recurse -Force | Measure-Object -Property Length -Sum).Sum 2> $null
$folderSizeComplete = "{0:N0}" -f ($folderSize / 1GB) + "GB"
Write-Host $findFilesFoldersOutput "$targetDir , $folderSizeComplete"
}
}
$alertcrit = 0
$alertwarn = 0
$error.clear()
$disks = Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType = 3";
foreach($disk in $disks)
{
$deviceID = $disk.DeviceID;
[float]$size = $disk.Size;
[float]$freespace = $disk.FreeSpace;
$percentFree = [Math]::Round(($freespace / $size) * 100, 2);
$sizeGB = [Math]::Round($size / 1073741824, 2);
$freeSpaceGB = [Math]::Round($freespace / 1073741824, 2);
if($percentFree -lt $crit -and $freeSpaceGB -lt 5)
{
Write-Host "CRITICAL $deviceID = $percentFree% Free!";
$alertcrit = 1
folderScan "$deviceID\"
}
elseif($percentFree -lt $warn -and $freeSpaceGB -lt 10)
{
Write-Host "WARNING $deviceID = $percentFree% Free!";
$alertwarn = 1
folderScan "$deviceID\"
}
Else
{
Write-Host "$deviceID=$percentFree% Free"
}
}
if ($alertcrit -gt 0)
{
exit 2
}
elseif ($alertwarn -gt 0)
{
exit 1
}
elseif ($error.Count -gt 0)
{
Write-Output $_;
$_="";
exit 3;
}
else
{
exit 0
}
Usage and outputs:
Code: Select all
PS C:\> ./diskcheck.ps1 20 10
C:=71.91% Free
E:=21.44% Free
PS C:\> ./diskcheck.ps1 22 10
C:=71.91% Free
WARNING E: = 21.44 % Free!
E:\big folder , 7GB
E:\small folder , 0GB
PS C:\>
If a disk is in a critical/warning state, it will print the sizes of every top-level folder on that disk. From the original plugin:
[parameters are] warn & crit thresholds (in free %s). It won't alert unless those thresholds are met AND the total free space is less than 10GB for warning, 5GB for critical.