Introduction
This document explains the configuration of Python script to define a Custom Monitor.
Python script configuration
The script executes for the metrics at a regular interval. The interval set in OpsRamp.
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
"
Parsing arguments
Use the following block of code in all the custom monitor scripts to parse 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
Variables | Description |
---|---|
arrayLen | Number of metrics to be monitored |
metrics | Array contains all metrics display names |
warning_thres | Array contains all metrics warning threshold values |
critical_thres | Array contains all metrics critical threshold values |
do_alerts | Array contains all metrics alerts flag values |
userParams | Array contains all metrics respective user parameters |
Note
- You need metric display names for graphical data in JSON payload. Example: “metric” : “displayName1”
- Warning and critical thresholds help to calculate the alert state of metric.
Displaying graphs
For graphing the metric values and for alerting, the script must write the output to the console in the following JSON format.
[
{
"metric" : "displayName1",
"component" : "instance1",
"value" : "value1",
"state" : "alert state1",
"alert_desc" : "alert description1",
"hostname/address/id" : "host1"
},
{
"metric" : "displayName2",
"component" : "instance2",
"value" : "value2",
"state" : "alert state2",
"alert_desc" : "alert description2",
"hostname/address/id" : "host2"
}
]
Values | Description |
---|---|
metric (required) | Metric name |
component | Instance name of Metric (only when you have multiple instances) |
value (required) | Value of metric or instance |
state | Alert state of the metric (only if you need Agent to handle alerts) |
alert_desc | Alert Description (only if you need Agent to handle alerts) |
hostname | Hostname of remote host (only for posting metrics to other hosts) |
address | IP address of remote host (only for posting metrics to other hosts) |
id | Resource ID of remote host (only for posting metrics to other hosts) |
Note
Provide one of the following values: hostname, address, or id (only when metrics need to post on remote hosts).
- If a user wants to send metric data to a remote host named
XYZ
, JSON object should be represented as “hostname”:XYZ
. - If a user wants to send metric data to a remote host with IP address
x.x.x.x
, JSON object should be represented as “address”:x.x.x.x
.
Possible values for state are:
- OK
- Warning
- Critical
Viewing graphical representations
To view the graphical representation of the monitoring:
- From All Clients, select a client.
- Go to Infrastructure > Resources, select a resource type.
- Click on the desired resource name. Overview page appears.
- From the left pane, click Metrics. The graph appears with display names:
displayName1
,displayName2
.- The graph of displayName1 consists of 3 values val1, val2, val3 that are plotted against key1, key2 and key3 respectively.
- The graph of displayName2 consists of 2 values val1, val2 that were plotted against key1 and key2 respectively.