Merge pull request #23 from simonpasquier/improve-glusterfs-plugin
Improve glusterfs plugin
diff --git a/collectd/files/plugin/collectd_glusterfs.py b/collectd/files/plugin/collectd_glusterfs.py
index 5457ea3..1b57984 100644
--- a/collectd/files/plugin/collectd_glusterfs.py
+++ b/collectd/files/plugin/collectd_glusterfs.py
@@ -33,25 +33,52 @@
def itermetrics(self):
# Collect peers' status
- out, err = self.execute([GLUSTER_BINARY, 'peer', 'status'])
+ out, err = self.execute([GLUSTER_BINARY, 'peer', 'status'],
+ shell=False)
if not out:
raise base.CheckException("Failed to execute gluster")
+ total = 0
+ total_by_state = {
+ 'up': 0,
+ 'down': 0
+ }
+
for line in out.split('\n\n'):
peer_m = peer_re.search(line)
state_m = state_re.search(line)
if peer_m and state_m:
- v = 0
+ total += 1
if state_m.group('state') == 'Peer in Cluster (Connected)':
v = 1
+ total_by_state['up'] += 1
+ else:
+ v = 0
+ total_by_state['down'] += 1
yield {
- 'type_instance': 'peer',
+ 'type_instance': 'peer_state',
'values': v,
'meta': {
'peer': peer_m.group('peer')
}
}
+ for state, count in total_by_state.items():
+ yield {
+ 'type_instance': 'peers_count',
+ 'values': count,
+ 'meta': {
+ 'state': state
+ }
+ }
+ yield {
+ 'type_instance': 'peers_percent',
+ 'values': 100.0 * count / total,
+ 'meta': {
+ 'state': state
+ }
+ }
+
plugin = GlusterfsPlugin(collectd)