Skip to content
Closed
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
6 changes: 5 additions & 1 deletion src/collectors/cpu/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def get_default_config_help(self):
config_help.update({
'percore': 'Collect metrics per cpu core or just total',
'simple': 'only return aggregate CPU% metric',
'extended': 'return aggregate CPU% metric but also complex CPU metrics',
Copy link
Author

Choose a reason for hiding this comment

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

Does anyone have any ideas for a better name for this?

'normalize': 'for cpu totals, divide by the number of CPUs',
})
return config_help
Expand All @@ -57,6 +58,7 @@ def get_default_config(self):
'percore': 'True',
'xenfix': None,
'simple': 'False',
'extended': 'False',
'normalize': 'False',
})
return config
Expand Down Expand Up @@ -96,7 +98,9 @@ def cpu_delta_time(interval):
dt = cpu_delta_time(self.INTERVAL)
cpuPct = 100 - (dt[len(dt) - 1] * 100.00 / sum(dt))
self.publish('percent', str('%.4f' % cpuPct))
return True
# the 'extended' flag tells us to return simple AND complex CPU metrics
if not str_to_bool(self.config['extended']):
return True

results = {}
# Open file
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
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