Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/collectors/NginxCollector.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 26 additions & 8 deletions src/collectors/nginx/nginx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add to the config_help section to

default_config['req_host'] = 'localhost'
default_config['req_port'] = 8080
default_config['req_path'] = '/nginx_status'
Expand Down Expand Up @@ -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:
Expand Down