Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix for monit if services are set to not be monitored #327

Merged
merged 2 commits into from

2 participants

@mzupan

When monit can't monitor a service, it will display no cpu/memory. So adding a try around where it parses the xml to skip any services that aren't monitored.

@kormoc kormoc merged commit 7cb2dcf into from
@kormoc
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 19 additions and 16 deletions.
  1. +19 −16 src/collectors/monit/monit.py
View
35 src/collectors/monit/monit.py
@@ -71,22 +71,25 @@ def collect(self):
'status')[0].firstChild.data == '0'
and service.getElementsByTagName(
'monitor')[0].firstChild.data == '1'):
- cpu = service.getElementsByTagName(
- 'cpu')[0].getElementsByTagName(
- 'percent')[0].firstChild.data
- mem = int(service.getElementsByTagName(
- 'memory')[0].getElementsByTagName(
- 'kilobyte')[0].firstChild.data)
- uptime = service.getElementsByTagName(
- 'uptime')[0].firstChild.data
-
- metrics["%s.cpu.percent" % name] = cpu
- for unit in self.config['byte_unit']:
- metrics["%s.memory.%s_usage" % (name, unit)] = (
- diamond.convertor.binary.convert(value=mem,
- oldUnit='kilobyte',
- newUnit=unit))
- metrics["%s.uptime" % name] = uptime
+ try:
+ cpu = service.getElementsByTagName(
+ 'cpu')[0].getElementsByTagName(
+ 'percent')[0].firstChild.data
+ mem = int(service.getElementsByTagName(
+ 'memory')[0].getElementsByTagName(
+ 'kilobyte')[0].firstChild.data)
+ uptime = service.getElementsByTagName(
+ 'uptime')[0].firstChild.data
+
+ metrics["%s.cpu.percent" % name] = cpu
+ for unit in self.config['byte_unit']:
+ metrics["%s.memory.%s_usage" % (name, unit)] = (
+ diamond.convertor.binary.convert(value=mem,
+ oldUnit='kilobyte',
+ newUnit=unit))
+ metrics["%s.uptime" % name] = uptime
+ except:
+ pass
for key in metrics:
self.publish(key, metrics[key])
Something went wrong with that request. Please try again.