banshee is under active development: collectors will keep changing, and a version you publish will likely need adjustments. For stable use, wait for version 1.0.0.

Windows

banshee/windows-collection/windows/winrm/

memory

The physical memory of a Windows, available and used, by WinRM and PowerShell

  • windows
  • winrm
  • powershell
  • memory

by banshee1 installation2 versions

Keen 1.0.0 · 33 lines
// The physical memory of a Windows, by WinRM: the memory Windows says is available, which counts the standby
// cache it gives back on demand; used memory is the rest, as Task Manager shows it. The paging file is the
// collector windows/winrm/pagefile.
// Runs one PowerShell script that only reads Win32_OperatingSystem: TotalVisibleMemorySize and
// FreePhysicalMemory, in KiB.
// The script is the one of windows/ssh/memory, without the powershell -Command "..." that cmd.exe needs there.
need('protocol:winrm');

output('total', 'number', array('label' => 'Physical memory', 'unit' => 'MiB'));
output('used', 'number', array('label' => 'Used memory', 'unit' => 'MiB'));
output('available', 'number', array('label' => 'Available memory', 'unit' => 'MiB'));
output('used-percent', 'number', array('label' => 'Used memory', 'unit' => '%'));

watch.above('used-percent', 'Memory saturated', 'used-percent', array('warning' => 90, 'critical' => 95, 'for' => '3 runs'));
watch.below('available', 'Little memory available', 'available', array('critical' => 512, 'enabled' => false));

$read = winrm.run("Get-CimInstance Win32_OperatingSystem | Select-Object TotalVisibleMemorySize, FreePhysicalMemory"
    . " | ConvertTo-Json -Compress");
$answer = text.trim($read['output']);
if (list.count(text.match($answer, '^\{')) == 0) {
    fail('misconfigured', 'PowerShell did not return Win32_OperatingSystem', $answer . $read['errors']);
}
$os = json.read($answer);
if ($os['TotalVisibleMemorySize'] <= 0) {
    fail('misconfigured', 'Win32_OperatingSystem gives no physical memory', $answer);
}

$total = $os['TotalVisibleMemorySize'] / 1024;
$available = $os['FreePhysicalMemory'] / 1024;
value('total', number.round($total));
value('available', number.round($available));
value('used', number.round($total - $available));
value('used-percent', number.round(100 * ($total - $available) / $total, 1));