diff --git a/docs/collectors/NginxCollector.md b/docs/collectors/NginxCollector.md index 9c38892af..6256c3735 100644 --- a/docs/collectors/NginxCollector.md +++ b/docs/collectors/NginxCollector.md @@ -38,6 +38,7 @@ enabled | False | Enable collecting these metrics | bool measure_collector_time | False | Collect the collector run time in ms | bool metrics_blacklist | None | Regex to match metrics to block. Mutually exclusive with metrics_whitelist | NoneType metrics_whitelist | None | Regex to match metrics to transmit. Mutually exclusive with metrics_blacklist | NoneType +precision | 0 | Number of decimal places to report to | int req_host | localhost | Hostname | str req_host_header | None | HTTP Host header (required for SSL) | NoneType req_path | /nginx_status | Path | str diff --git a/src/collectors/nginx/nginx.py b/src/collectors/nginx/nginx.py index 1e6532b50..41a72dfd6 100644 --- a/src/collectors/nginx/nginx.py +++ b/src/collectors/nginx/nginx.py @@ -37,6 +37,7 @@ class NginxCollector(diamond.collector.Collector): def get_default_config_help(self): config_help = super(NginxCollector, self).get_default_config_help() config_help.update({ + 'precision': 'Number of decimal places to report to', 'req_host': 'Hostname', 'req_port': 'Port', 'req_path': 'Path', @@ -47,6 +48,7 @@ def get_default_config_help(self): def get_default_config(self): default_config = super(NginxCollector, self).get_default_config() + default_config['precision'] = 0 default_config['req_host'] = 'localhost' default_config['req_port'] = 8080 default_config['req_path'] = '/nginx_status' @@ -80,25 +82,41 @@ def collect(self): req = urllib2.Request(url=url, headers=headers) try: handle = urllib2.urlopen(req) + precision = int(self.config['precision']) for l in handle.readlines(): l = l.rstrip('\r\n') if activeConnectionsRE.match(l): self.publish_gauge( 'active_connections', - int(activeConnectionsRE.match(l).group('conn'))) + int(activeConnectionsRE.match(l).group('conn')), + precision) elif totalConnectionsRE.match(l): m = totalConnectionsRE.match(l) req_per_conn = float(m.group('req')) / \ float(m.group('acc')) - self.publish_counter('conn_accepted', int(m.group('conn'))) - self.publish_counter('conn_handled', int(m.group('acc'))) - self.publish_counter('req_handled', int(m.group('req'))) - self.publish_gauge('req_per_conn', float(req_per_conn)) + self.publish_counter('conn_accepted', + int(m.group('conn')), + precision) + self.publish_counter('conn_handled', + int(m.group('acc')), + precision) + self.publish_counter('req_handled', + int(m.group('req')), + precision) + self.publish_gauge('req_per_conn', + float(req_per_conn), + precision) elif connectionStatusRE.match(l): m = connectionStatusRE.match(l) - self.publish_gauge('act_reads', int(m.group('reading'))) - self.publish_gauge('act_writes', int(m.group('writing'))) - self.publish_gauge('act_waits', int(m.group('waiting'))) + self.publish_gauge('act_reads', + int(m.group('reading')), + precision) + self.publish_gauge('act_writes', + int(m.group('writing')), + precision) + self.publish_gauge('act_waits', + int(m.group('waiting')), + precision) except IOError, e: self.log.error("Unable to open %s" % url) except Exception, e: