Merge pull request #20 from simonpasquier/add-glusterfs-plugin
Add Glusterfs Python plugin
diff --git a/collectd/files/plugin/collectd_glusterfs.py b/collectd/files/plugin/collectd_glusterfs.py
new file mode 100644
index 0000000..5457ea3
--- /dev/null
+++ b/collectd/files/plugin/collectd_glusterfs.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+# Copyright 2016 Mirantis, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import collectd
+import re
+
+import collectd_base as base
+
+NAME = 'glusterfs'
+GLUSTER_BINARY = '/usr/sbin/gluster'
+
+peer_re = re.compile(r'^Hostname: (?P<peer>.+)$', re.MULTILINE)
+state_re = re.compile(r'^State: (?P<state>.+)$', re.MULTILINE)
+
+
+class GlusterfsPlugin(base.Base):
+
+ def __init__(self, *args, **kwargs):
+ super(GlusterfsPlugin, self).__init__(*args, **kwargs)
+ self.plugin = NAME
+
+ def itermetrics(self):
+ # Collect peers' status
+ out, err = self.execute([GLUSTER_BINARY, 'peer', 'status'])
+ if not out:
+ raise base.CheckException("Failed to execute gluster")
+
+ 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
+ if state_m.group('state') == 'Peer in Cluster (Connected)':
+ v = 1
+ yield {
+ 'type_instance': 'peer',
+ 'values': v,
+ 'meta': {
+ 'peer': peer_m.group('peer')
+ }
+ }
+
+
+plugin = GlusterfsPlugin(collectd)
+
+
+def init_callback():
+ plugin.restore_sigchld()
+
+
+def config_callback(conf):
+ plugin.config_callback(conf)
+
+
+def read_callback():
+ plugin.read_callback()
+
+collectd.register_init(init_callback)
+collectd.register_config(config_callback)
+collectd.register_read(read_callback)