Skip to content

Instantly share code, notes, and snippets.

@andras-tim
Last active March 15, 2016 15:11
Show Gist options
  • Save andras-tim/6a0aa5a39187dbfa0309 to your computer and use it in GitHub Desktop.
Save andras-tim/6a0aa5a39187dbfa0309 to your computer and use it in GitHub Desktop.
WinPrint Statistics Script for Munin

WinPrint Statistics Script for Munin

Setup

  1. Download files to %ProgramFiles%\Munin Node for Windows
  2. Register winprint.cmd as external plunin in munin-node.ini:
...
[ExternalPlugin]
Winprint=C:\Program Files (x86)\Munin Node for Windows\winprint.cmd
...
@echo off
:: -------------------------------------------------------------------------------
:: WinPrint Statistics Script for Munin
:: Author: Andras Tim <[email protected]>
:: -------------------------------------------------------------------------------
:: cscript //nologo "%ProgramFiles%\Munin Node for Windows\winprint.vbs" %*
cscript //nologo "%ProgramFiles(x86)%\Munin Node for Windows\winprint.vbs" %*
'-------------------------------------------------------------------------------
' WinPrint Statistics Script for Munin
' Author: Andras Tim <[email protected]>
'-------------------------------------------------------------------------------
option explicit
const strServer = "."
const CMD_FETCH = 0
const CMD_NAME = 1
const CMD_CONFIG = 2
main
function main()
dim Cmd: Cmd = ParseCommandLine
dim objWMIService: Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strServer & "\root\cimv2")
dim colPrintQueues: Set colPrintQueues = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_Spooler_PrintQueue WHERE Name <> '_Total'")
if Cmd = CMD_NAME then
StdOut "winprint"
exit function
end if
graph_jobs Cmd, colPrintQueues, _
"winprintJobs", "Jobs", "Jobs", "Jobs statistics", _
"Jobs", 0, Empty, Empty
graph_jobs Cmd, colPrintQueues, _
"winprintJobsSpooling", "Current jobs spooling", "Jobs", "Current jobs spooling statistics", _
"JobsSpooling", 0, 3, 6
graph_jobs Cmd, colPrintQueues, _
"winprintMaxJobsSpooling", "Maximum jobs spooling", "Jobs", "Maximum jobs spooling statistics", _
"MaxJobsSpooling", 0, Empty, Empty
graph_jobs Cmd, colPrintQueues, _
"winprintTotalJobsPrinted", "Total jobs printed", "Jobs", "Total jobs printed statistics", _
"TotalJobsPrinted", 0, Empty, Empty
graph_jobs Cmd, colPrintQueues, _
"winprintJobErrors", "Job errors", "Jobs", "Job errors statistics", _
"JobErrors", 0, Empty, 1
graph_jobs Cmd, colPrintQueues, _
"winprintNotReadyErrors", "Not ready errors", "Jobs", "Not ready errors statistics", _
"NotReadyErrors", 0, 1, 2
graph_jobs Cmd, colPrintQueues, _
"winprintOutOfPaperErrors", "Out of paper errors", "Jobs", "Out of paper errors statistics", _
"OutOfPaperErrors", 0, 1, 2
graph_jobs Cmd, colPrintQueues, _
"winprintTotalPagesPrinted", "Total pages printed", "Pages", "Total pages printed statistics", _
"TotalPagesPrinted", 0, Empty, Empty
graph_jobs Cmd, colPrintQueues, _
"winprintBytesPrintedPersec", "Bytes printed/sec", "Bytes/sec", "Bytes printed/sec statistics", _
"BytesPrintedPersec", 0, Empty, Empty
StdOut "."
end function
function graph_jobs(Cmd, colPrintQueues, strGraphId, strGraphTitle, strGraphVLable, strGraphInfo, valueQueryFunctionName, valueMin, valueWarning, valueCritical)
StdOut "multigraph " & strGraphId
if Cmd = CMD_CONFIG then
StdOut "graph_title " & strGraphTitle
StdOut "graph_vlabel " & strGraphVLable
StdOut "graph_category printing"
StdOut "graph_info " & strGraphInfo
end if
dim objPrintQueue
dim strId
For Each objPrintQueue in colPrintQueues
with objPrintQueue
do
if InStr(1, .Name, "{") > 0 then
exit do
end if
strId = LCase(Replace(Replace(.Name, ".", "_"), " ", "_"))
if Cmd = CMD_CONFIG then
StdOut strId & ".label " & .Name
if not IsEmpty(valueMin) then StdOut strId & ".min " & valueMin
if not IsEmpty(valueWarning) then StdOut strId & ".warning " & valueWarning
if not IsEmpty(valueCritical) then StdOut strId & ".critical " & valueCritical
elseif Cmd = CMD_FETCH then
StdOut strId & ".value " & Eval("objPrintQueue." & valueQueryFunctionName)
end if
loop while False
end with
Next
end function
function ParseCommandLine()
dim oArgs: set oArgs = wscript.Arguments
ParseCommandLine = CMD_FETCH
dim iIndex: iIndex = 0
while iIndex < oArgs.Count
select case oArgs(iIndex)
case "name"
ParseCommandLine = CMD_NAME
case "config"
ParseCommandLine = CMD_CONFIG
end select
iIndex = iIndex + 1
wend
end function
function StdOut(text)
Wscript.StdOut.Write text & vbLf
end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment