Hi, Mark Manty Microsoft PFE providing an example Management pack for monitoring MongoDB on Windows Servers.
Get the example MP from TechNet gallery.
This management pack has two monitors configured for monitoring the MongoDB Windows service and monitor and alert when less than 100 connections are available.
The management pack collects many performance counters from a script that runs ServerStatus query every 15 minutes. If you want to disable or add counters to be collected, you must edit the script data source.
Details on removing (disabling a collection) below:
Open the MP with notepad and cut any lines that you do not want collected.
Move them above where the performance counters that are disabled are located and comment out the lines that you move by putting a single quote ‘ character at the front of the line.
Details on adding performance counter to collect that is returned from ServerStatus:
To add counters cut them from the commented out lines and move them to the variable selection. Then uncomment out the line by removing the single quote ‘ character at front of line.
Adding threshold monitors for a given counter details below:
With Management pack already installed in your environment, select Authoring and change Scope to MongoDB 4.x Windows Server.
Select Authoring – Management Pack Objects – Monitors and right click create a monitor – Unit Monitor.
Select Scripting – Generic – Timed Script Two State Monitor. Select the MongoDB MP and select Next.
Provide a name for the new unit monitor and select the target of MongoDB 4.x Windows Server and select Next
Select the frequency to run the monitor (default is 15minutes) and select Next.
Copy script below and paste into next screen for script.
Note at end of script if you want to change <= to >= based on the way you want your threshold check to be less than or greater than the value passed to the script.
‘ SCRIPT NAME: MongoDBServerStatusCheckValue.vbs
‘ PARAMETERS: 10 “asserts.rollovers”
‘ Where 10 is the Threshold to check counter value
‘ and “asserts.rollovers” is the counter value to check from custom perf collection
‘ Returns: State = “Good” or “Bad”
‘ SCOM Parameter Name: Property[@Name=’State’]
‘ Unhealthy: Contains “Bad”
‘ Healthy: Contains “Good”
‘ Return = “Custom Message you want to display in the Alert Message”
‘
‘ ALERT MESSAGE: To display in Alert description “Return” value see below example
‘ Message: $Data/Context/Property[@Name=’Return’]$
‘
dim oArgs, sReturn
sReturn = “”
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oArgs = WScript.Arguments
‘map event types & numbers to friendly names
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_SUCCESS = 4
If oArgs.Count < 2 Then
‘ If the script is called without the required arguments, ‘ create an information event and then quit. ‘
Set objShell = Wscript.CreateObject(“Wscript.Shell”) ‘
objShell.LogEvent EVENT_TYPE_ERROR, “MongoDBServerStatusCheckValue.vbs run with an incorrect number of arguments.”
WScript.Quit -1
End If
dim iThreshold, sCounterCheck
‘GetArgs
‘0 is threshold Example (10)
‘1 is countervalue to check Example (“asserts.rollovers”)
iThreshold = CLng(trim(oArgs.Item(0)))
sCounterCheck = trim(oArgs.Item(1))
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set wshNetwork = WScript.CreateObject( “WScript.Network” )
dim strComputerName,sCommand
strComputerName = wshNetwork.ComputerName
Set objShell = WScript.CreateObject(“WScript.Shell”)
sCommand = “””C:\Program Files\MongoDB\Server\4.0\bin\mongo.exe””” & ” –eval ” & “””db.runCommand( { serverStatus: 1 } ).” & sCounterCheck & “”””
‘Wscript.Echo sCommand
Set objExec = objShell.Exec(sCommand)
line = objExec.StdOut.ReadLine()
line = objExec.StdOut.ReadLine()
line = objExec.StdOut.ReadLine()
line = objExec.StdOut.ReadLine()
Wscript.Echo line
Set oBag = oAPI.CreatePropertyBag()
if Clng(trim(line)) <= iThreshold then
sReturn = “MongoDB ServerStatus Value for ” & sCounterCheck & ” was equal to or exceeded threhsold of ” & iThreshold & “. Current value checked was ” & line & “. Command run to get value: ” & sCommand
‘add data to propertybag and add item
Call oBag.AddValue(“Value”,line)
Call oBag.AddValue(“State”,”Bad”)
Call oBag.AddValue(“Return”,sReturn)
Call oAPI.AddItem(oBag)
else
‘add data to propertybag and add item
Call oBag.AddValue(“Value”,line)
Call oBag.AddValue(“State”,”Good”)
Call oBag.AddValue(“Return”,”Within Threshold Limit”)
Call oAPI.AddItem(oBag)
end if
‘Return all property bags.
oAPI.ReturnItems()
Provide a file name with .vbs extension. Change timeout to 5 minutes.
Use this for parameters: 100 “connections.available”
For your case you would put threshold value as first parameter and then the counter name that you would like to check value of for alerting.
NOTE: Double check is this is correct.
Run script manually to validate that your parameters work asexpected.
Paste in below to check for Good and Bad returned State property bag value for the monitors Unhealthy and Healthy expression checks.
Property[@Name=’State’]
Select warning or critical for unhealthy condition of thenew monitor you are creating.
Paste below string into Alert description to allow for script data to be entered into your alert description.
$Data/Context/Property[@Name=’Return’]$
Select values to generate alert and auto resolve alert monitor. Select priority and severity you would like for the alert.
Select Create to create your new script monitor.
See new monitor created and validate it is targeted to MongoDB target.
MONGODB views in management pack.
MongoDB Monitoring folder contains three views. One for Alerts, performance and discovered MongoDB Servers.
Performance data collected will display similar to below. Select items to see the data collected.
Reporting example on how to configure performance report to display historical data for MongoDB performance counters collected.