Windows
banshee/windows-collection/windows/winrm/
volumes
The space of each local volume of a Windows, and when it will be full, by WinRM and PowerShell
by banshee1 installation2 versions
// The space of each local volume of a Windows, by WinRM: those with a drive letter and those mounted in a
// folder. Network, removable and optical drives are not among them. An expected volume that disappears
// shows through the watch "Volume missing".
// Runs one PowerShell script that only reads Win32_Volume, the volumes of the type "local disk"
// (DriveType 3) that are formatted (a Capacity): Name ("C:\", or the folder of a mount point), Capacity and
// FreeSpace in bytes. The activity of the disks is the collector windows/winrm/diskio.
// The script is the one of windows/ssh/volumes, without the powershell -Command "..." that cmd.exe needs
// there.
need('protocol:winrm');
per('volume', 'Volumes');
output('total', 'number', array('label' => 'Size', 'unit' => 'GiB', 'per' => 'volume'));
output('used', 'number', array('label' => 'Space used', 'unit' => 'GiB', 'per' => 'volume'));
output('free', 'number', array('label' => 'Free space', 'unit' => 'GiB', 'per' => 'volume'));
output('used-percent', 'number', array('label' => 'Space used', 'unit' => '%', 'per' => 'volume'));
watch.above('used', 'Space used', 'used-percent', array('warning' => 80, 'critical' => 90));
watch.above('full-soon', 'Full within the week', 'used-percent', array('warning' => 99, 'ahead' => '7 d'));
watch.below('free', 'Little free space', 'free', array('critical' => 5, 'enabled' => false));
watch.missing('missing', 'Volume missing', 'used-percent');
// A mount point may hold a name outside ASCII: the output is written in UTF-8, without the byte order mark
// that the default UTF-8 encoding of .NET would put first.
$read = winrm.run("[Console]::OutputEncoding = New-Object System.Text.UTF8Encoding; "
. "ConvertTo-Json -Compress -InputObject @(Get-CimInstance Win32_Volume -Filter 'DriveType=3'"
. " | Where-Object Capacity | Select-Object Name, Capacity, FreeSpace)");
$answer = text.trim($read['output']);
if (list.count(text.match($answer, '^\[')) == 0) {
fail('misconfigured', 'PowerShell did not return the volumes', $answer . $read['errors']);
}
$volumes = 0;
foreach (json.read($answer) as $volume) {
// A volume without a letter or a folder is named "\\?\Volume{...}\": a recovery or system partition,
// which no one fills.
if (text.like($volume['Name'], '\\\\?\\*')) {
continue;
}
$volumes = $volumes + 1;
$total = $volume['Capacity'] / 1073741824;
$free = $volume['FreeSpace'] / 1073741824;
value('total', number.round($total, 1), $volume['Name']);
value('used', number.round($total - $free, 1), $volume['Name']);
value('free', number.round($free, 1), $volume['Name']);
value('used-percent', number.round(100 * ($total - $free) / $total, 1), $volume['Name']);
}
// A Windows always has at least its system volume: returning none would be a green light on nothing.
if ($volumes == 0) {
fail('misconfigured', 'No local volume found in Win32_Volume', $answer);
}