mirror of
https://github.com/drewkerrigan/nagios-http-json.git
synced 2024-11-22 18:33:49 +01:00
Add support for sending perfdata via StatsD protocol
This commit is contained in:
parent
7bdc802c2d
commit
5851714b27
@ -81,6 +81,12 @@ optional arguments:
|
||||
formats for this parameter are: (key[>alias]),
|
||||
(key[>alias],UnitOfMeasure),
|
||||
(key[>alias],UnitOfMeasure,WarnRange,CriticalRange).
|
||||
--statsd_host STATSD_HOST
|
||||
StatsD host to send performance data.
|
||||
--statsd_port STATSD_PORT
|
||||
StatsD host to send performance data
|
||||
--statsd_prefix STATSD_PREFIX
|
||||
StatsD prefix to send performance data.
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
@ -10,6 +10,7 @@ and determines the status and performance data for that service.
|
||||
import httplib, urllib, urllib2, base64
|
||||
import json
|
||||
import argparse
|
||||
import statsd
|
||||
import sys
|
||||
from pprint import pprint
|
||||
from urllib2 import HTTPError
|
||||
@ -17,7 +18,6 @@ from urllib2 import URLError
|
||||
|
||||
# TEST = False
|
||||
|
||||
|
||||
OK_CODE = 0
|
||||
WARNING_CODE = 1
|
||||
CRITICAL_CODE = 2
|
||||
@ -261,6 +261,20 @@ class JsonRuleProcessor:
|
||||
metrics += ' '
|
||||
return ("%s" % metrics, warning, critical)
|
||||
|
||||
def checkMetricsStatsD(self):
|
||||
"""Return a StatsD specific performance metrics string given keys"""
|
||||
metrics = {}
|
||||
if self.rules.metric_list != None:
|
||||
for metric in self.rules.metric_list:
|
||||
key = metric
|
||||
if ',' in metric:
|
||||
vals = metric.split(',')
|
||||
key = vals
|
||||
key, alias = _getKeyAlias(key)
|
||||
if self.helper.exists(key):
|
||||
metrics[alias] = self.helper.get(key)
|
||||
return metrics
|
||||
|
||||
def parseArgs():
|
||||
parser = argparse.ArgumentParser(description=
|
||||
'Nagios plugin which checks json values from a given endpoint against argument specified rules\
|
||||
@ -295,6 +309,9 @@ def parseArgs():
|
||||
help='Gathers the values of these keys (key[>alias],UnitOfMeasure,WarnRange,CriticalRange,Min,Max) for Nagios performance data.\
|
||||
More information about Range format and units of measure for nagios can be found at nagios-plugins.org/doc/guidelines.html\
|
||||
Additional formats for this parameter are: (key[>alias]), (key[>alias],UnitOfMeasure), (key[>alias],UnitOfMeasure,WarnRange,CriticalRange).')
|
||||
parser.add_argument('--statsd_host', dest='statsd_host', help='StatsD host to send performance data.')
|
||||
parser.add_argument('--statsd_port', dest='statsd_port', type=int, default=8125, help='StatsD host to send performance data')
|
||||
parser.add_argument('--statsd_prefix', dest='statsd_prefix', help='StatsD prefix to send performance data.')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
@ -439,4 +456,9 @@ if __name__ == "__main__":
|
||||
nagios.append_metrics(processor.checkMetrics())
|
||||
# Print Nagios specific string and exit appropriately
|
||||
print nagios.getMessage()
|
||||
if args.statsd_host and args.statsd_port and args.statsd_prefix:
|
||||
stat = statsd.StatsClient(args.statsd_host, args.statsd_port, prefix=args.statsd_prefix)
|
||||
for metric, value in processor.checkMetricsStatsD().iteritems():
|
||||
stat.gauge(metric, value)
|
||||
#pprint(processor.checkMetricsStatsD())
|
||||
exit(nagios.getCode())
|
||||
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
statsd==3.2.1
|
Loading…
Reference in New Issue
Block a user