This provides an example of how to use a Python script to define a custom monitor.

Python script configuration

The script executes for the metrics at a periodic interval that can be set.

Python sample.py:

    "
    /metricName::metricName1|metricName2
    /metric::displayName1|displayName2
    /warn::warn1|warn2
    /critical::crit1|crit2
    /alert::do_alert1|do_alert2
    /params::args_string1|args_string2
    "

Parse arguments

Use the following code snippet as an example of how to parse custom monitor arguments:

api = None
try:
	sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
	from ScriptMonitorPythonApi import ScriptMonitorPythonApi
	api = ScriptMonitorPythonApi(sys.argv)
except Exception, emsg:
	sys.exit()
arrayLen = len(api.metricNames)
metrics = api.metrics
warning_thres = api.warnings
critical_thres = api.criticals
do_alerts = api.doAlerts
userParams = api.userParams

VariablesDescription
arrayLenNumber of metrics to be monitored.
metricsArray contains all metrics display names. Metric display names are needed to graphically display the JSON payload. For example, "metric" : "displayName1"
warning_thresArray contains all metrics warning threshold values.
critical_thresArray contains all metrics critical threshold values. Critical threshold values help calculate the metric alert state.
do_alertsArray contains all metrics alerts flag values.
userParamsArray contains all metrics respective user parameters.
Note:The user parameters must not contain the following strings:
  • $$$_$$$
  • #

Display graphs

For graphing the metric values and for alerting, the script must write the output to the console, as shown in the following JSON-formatted example:

[
	{
		"metric" : "displayName1",
		"component" : "instance1",
		"value" : "value1",
		"state" : "alert state1",
		"alert_desc" : "alert description1",
		"hostname/address/id/container_id" : "host1/container_id" 
	},
	{
		"metric" : "displayName2",
		"component" : "instance2",
		"value" : "value2",
		"state" : "alert state2",
		"alert_desc" : "alert description2",
		"hostname/address/id/container_id" : "host2/container_id" 
	}
]

ValuesDescriptionRequired
metricMetric name.Yes
componentMetric instance name.Include only when there are multiple instances.
valueMetric or instance value.Yes
stateMetric alert state. Valid state values:
  • OK
  • Warning
  • Critical
Include only if the agent needs to handle alerts.
alert_descAlert description.Include only if the agent needs to handle alerts.
hostnameRemote host hostname. For example, to send metric data to a remote host named XYZ, the JSON object notation is "hostname": 'XYZ'.Include when needed to post metrics to other hosts.
addressRemote host IP address.Include only when needed to post metrics to other hosts.
idRemote host resource ID. For example, to send metric data to a remote host with IP address x.x.x.x, the JSON object notation is "id": 'x.x.x.x'.Include only when needed to post metrics to other hosts.
container_idRemote host container ID.Include only if the metrics need to be plotted against a container. Otherwise, omit this field.

View graphical representations

To view the graphical representation of the monitoring:

  1. From All Clients, select a client.

  2. Go to Infrastructure > Resources and select a resource type.

  3. Click the resource name to view the Overview page.

  4. In the left panel, click Metrics to display a graph with the following display names:

    • displayName1 Displays three values val1, val2, and val3 plotted against key1, key2 and key3, respectively.
    • displayName2 Displays two values val1 and val2 plotted against key1 and key2, respectively.