From 5e7fe49ff37b6e39fa8978103439f60e6cb57f15 Mon Sep 17 00:00:00 2001 From: Zdenek Pizl Date: Wed, 12 Mar 2014 12:23:53 +0100 Subject: [PATCH] FEATURE: add support for remote node configuration - any munin-node could support remote or indirect fetching of plugin's data - add support for munin-node:remote-node syntax of host parameter - add process logic to ask for remote node data - displayname should be used to correctly identify such metrics --- m2g-poller.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/m2g-poller.py b/m2g-poller.py index d1b76aa..82eaeb3 100755 --- a/m2g-poller.py +++ b/m2g-poller.py @@ -20,17 +20,26 @@ RE_MUNIN_NODE_NAME = re.compile(r"^# munin node at\s+(?P\S+)$") class Munin(): """Munin host object with querying getter functions.""" def __init__(self, hostname, port=4949, args=None): - self.hostname = hostname - self.port = port - self.args = args - self.displayname = self.hostname.split(".")[0] + + self.hostname = None + self.remotenode = None self._sock = None self._conn = None self._carbon_sock = None self.hello_string = None + if ':' in hostname: + self.hostname, self.remotenode = hostname.split(":",1) + else: + self.hostname = hostname + self.port = port + self.args = args + if self.args.displayname: self.displayname = self.args.displayname + else: + self.displayname = self.hostname.split(".")[0] + def go(self): """Bootstrap method to start processing hosts's Munin stats.""" @@ -138,7 +147,12 @@ class Munin(): """Return a list of Munin plugins configured on a node. """ self._sock.sendall("cap multigraph\n") self._readline() # ignore response - self._sock.sendall("list\n") + + if self.remotenode: + self._sock.sendall("list %s\n" %self.remotenode) + else: + self._sock.sendall("list\n") + plugin_list = self._readline().split(" ") return plugin_list @@ -212,6 +226,11 @@ class Munin(): prefix = '' else: prefix = "%s." % self.args.prefix + + hostname = self.hostname + if self.remotenode: + hostname = self.remotenode + data_list = [] logging.info("Creating metric for plugin %s, timestamp: %d", plugin_name, timestamp) @@ -231,7 +250,7 @@ class Munin(): return logging.info("Sending plugin %s data to Carbon for host %s.", - plugin_name, self.hostname) + plugin_name, hostname) payload = pickle.dumps(data_list) header = struct.pack("!L", len(payload)) message = header + payload @@ -252,7 +271,8 @@ def parse_args(): parser.add_argument("--host", action="store", default="localhost", - help="Munin host to query for stats. Default: %(default)s") + help="Munin host to query for stats. You can specify indirect node after ':', " + "i.e. --host localhost:remotenode. Default: %(default)s") parser.add_argument("--displayname", default=False, help="If defined, use this as the name to store metrics in Graphite instead of the Munin"