Last active
November 8, 2017 08:14
-
-
Save moisseev/6026bb2794b33b2488c65aec9a8a5452 to your computer and use it in GitHub Desktop.
Munin Node for Windows external plugin - Physical memory and paging file usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem Munin Node for Windows external plugin wrapper | |
rem Low physical memory warnings | |
rem | |
rem The default thresholds (usage in percents) are warning=80 critical=90 . | |
rem Set environment variables as shown below to override the defaults. | |
rem | |
rem set mem_used.warning=80 | |
rem set mem_used.critical=90 | |
call %windir%\system32\cscript.exe //NoLogo "%ProgramFiles%\Munin Node for Windows\plugins\wmi-memory.vbs" %1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Munin Node for Windows external plugin | |
' This plugin shows physical memory and paging file usage. | |
Option Explicit | |
Const NAME = "wmi-memory" | |
Const KB = 1024 | |
Const MB = 1048576 | |
Dim args | |
Set args = WScript.Arguments | |
Dim objWMI, instance, total_physical_memory | |
Set objWMI = GetObject("winmgmts:\\.\root\cimv2") | |
if args.Count = 1 then | |
if args.Item(0) = "config" then | |
For Each instance in objWMI.ExecQuery("Select * from Win32_ComputerSystem") | |
total_physical_memory = instance.TotalPhysicalMemory | |
Next | |
Say("graph_title Memory usage") | |
Say("graph_category memory") | |
Say("graph_info This graph shows physical memory and paging file usage.") | |
Say("graph_vlabel Bytes") | |
Say("graph_args --alt-autoscale-max --base 1024 --lower-limit 0") | |
Say("mem_used.label Physical memory used") | |
Say("mem_used.draw AREA") | |
Say("mem_used.warning " & Int(total_physical_memory * GetEnv("mem_used.warning", 80) / 100)) | |
Say("mem_used.critical " & Int(total_physical_memory * GetEnv("mem_used.critical", 90) / 100)) | |
Say("mem_free.label Physical memory free") | |
Say("mem_free.draw STACK") | |
Say("pf_used.label Paging file used") | |
Say("pf_used.draw STACK") | |
Say("pf_free.label Paging file free") | |
Say("pf_free.draw STACK") | |
Say("committed.label Commit charge") | |
Say("commit_limit.label Commit limit") | |
Say(".") | |
elseif args.Item(0) = "name" then | |
Say(NAME) | |
end if | |
WScript.Quit | |
end if | |
Dim Memory | |
Set Memory = GetObject("winmgmts:" &_ | |
"Win32_PerfRawData_PerfOS_Memory=@") | |
Say("commit_limit.value " & Memory.CommitLimit) | |
Say("committed.value " & Memory.CommittedBytes) | |
Say("mem_free.value " & Memory.AvailableBytes) | |
For Each instance in objWMI.ExecQuery("Select * from Win32_ComputerSystem") | |
Say("mem_used.value " & instance.TotalPhysicalMemory - Memory.AvailableBytes) | |
Next | |
Dim pf_allocated, pf_used, pf_free | |
'Sum all paging files | |
For Each instance in objWMI.ExecQuery("Select * from Win32_PageFileUsage") | |
pf_allocated = pf_allocated + cdbl(instance.AllocatedBaseSize) * MB | |
pf_used = pf_used + cdbl(instance.CurrentUsage) * MB | |
Next | |
pf_free = pf_allocated - pf_used | |
Say("pf_used.value " & pf_used) | |
Say("pf_free.value " & pf_free) | |
Say(".") | |
'=== Functions and subroutines === | |
Function GetEnv(varName, defVal) | |
Dim varVal | |
varVal = CreateObject("WScript.Shell").Environment("Process").Item(varName) | |
If varVal = Empty then | |
GetEnv = defVal | |
else | |
GetEnv = varVal | |
end if | |
End Function | |
Sub Say(a) | |
Wscript.StdOut.Write a & vbLf | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To enable the plugin add the following lines to the munin-node.ini :