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
This commit is contained in:
parent
f05d3b597b
commit
5e7fe49ff3
@ -20,17 +20,26 @@ RE_MUNIN_NODE_NAME = re.compile(r"^# munin node at\s+(?P<nodename>\S+)$")
|
|||||||
class Munin():
|
class Munin():
|
||||||
"""Munin host object with querying getter functions."""
|
"""Munin host object with querying getter functions."""
|
||||||
def __init__(self, hostname, port=4949, args=None):
|
def __init__(self, hostname, port=4949, args=None):
|
||||||
self.hostname = hostname
|
|
||||||
self.port = port
|
self.hostname = None
|
||||||
self.args = args
|
self.remotenode = None
|
||||||
self.displayname = self.hostname.split(".")[0]
|
|
||||||
self._sock = None
|
self._sock = None
|
||||||
self._conn = None
|
self._conn = None
|
||||||
self._carbon_sock = None
|
self._carbon_sock = None
|
||||||
self.hello_string = 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:
|
if self.args.displayname:
|
||||||
self.displayname = self.args.displayname
|
self.displayname = self.args.displayname
|
||||||
|
else:
|
||||||
|
self.displayname = self.hostname.split(".")[0]
|
||||||
|
|
||||||
|
|
||||||
def go(self):
|
def go(self):
|
||||||
"""Bootstrap method to start processing hosts's Munin stats."""
|
"""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. """
|
"""Return a list of Munin plugins configured on a node. """
|
||||||
self._sock.sendall("cap multigraph\n")
|
self._sock.sendall("cap multigraph\n")
|
||||||
self._readline() # ignore response
|
self._readline() # ignore response
|
||||||
|
|
||||||
|
if self.remotenode:
|
||||||
|
self._sock.sendall("list %s\n" %self.remotenode)
|
||||||
|
else:
|
||||||
self._sock.sendall("list\n")
|
self._sock.sendall("list\n")
|
||||||
|
|
||||||
plugin_list = self._readline().split(" ")
|
plugin_list = self._readline().split(" ")
|
||||||
return plugin_list
|
return plugin_list
|
||||||
|
|
||||||
@ -212,6 +226,11 @@ class Munin():
|
|||||||
prefix = ''
|
prefix = ''
|
||||||
else:
|
else:
|
||||||
prefix = "%s." % self.args.prefix
|
prefix = "%s." % self.args.prefix
|
||||||
|
|
||||||
|
hostname = self.hostname
|
||||||
|
if self.remotenode:
|
||||||
|
hostname = self.remotenode
|
||||||
|
|
||||||
data_list = []
|
data_list = []
|
||||||
logging.info("Creating metric for plugin %s, timestamp: %d",
|
logging.info("Creating metric for plugin %s, timestamp: %d",
|
||||||
plugin_name, timestamp)
|
plugin_name, timestamp)
|
||||||
@ -231,7 +250,7 @@ class Munin():
|
|||||||
return
|
return
|
||||||
|
|
||||||
logging.info("Sending plugin %s data to Carbon for host %s.",
|
logging.info("Sending plugin %s data to Carbon for host %s.",
|
||||||
plugin_name, self.hostname)
|
plugin_name, hostname)
|
||||||
payload = pickle.dumps(data_list)
|
payload = pickle.dumps(data_list)
|
||||||
header = struct.pack("!L", len(payload))
|
header = struct.pack("!L", len(payload))
|
||||||
message = header + payload
|
message = header + payload
|
||||||
@ -252,7 +271,8 @@ def parse_args():
|
|||||||
parser.add_argument("--host",
|
parser.add_argument("--host",
|
||||||
action="store",
|
action="store",
|
||||||
default="localhost",
|
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",
|
parser.add_argument("--displayname",
|
||||||
default=False,
|
default=False,
|
||||||
help="If defined, use this as the name to store metrics in Graphite instead of the Munin"
|
help="If defined, use this as the name to store metrics in Graphite instead of the Munin"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user