From 9be08f011baf05884a60631d63ca6d90a4a735b2 Mon Sep 17 00:00:00 2001 From: Ben Hartshorne Date: Thu, 5 Dec 2013 10:21:12 -0800 Subject: [PATCH] add metric to count connected clients to ganglia zookeeper module --- src/contrib/monitoring/ganglia/zookeeper.pyconf | 1 + .../monitoring/ganglia/zookeeper_ganglia.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/contrib/monitoring/ganglia/zookeeper.pyconf b/src/contrib/monitoring/ganglia/zookeeper.pyconf index 43801a0f2bd..339f44875fc 100644 --- a/src/contrib/monitoring/ganglia/zookeeper.pyconf +++ b/src/contrib/monitoring/ganglia/zookeeper.pyconf @@ -35,6 +35,7 @@ collection_group { metric { name = "zk_min_latency" } metric { name = "zk_packets_received" } metric { name = "zk_packets_sent" } + metric { name = "zk_connected_clients" } metric { name = "zk_outstanding_requests" } metric { name = "zk_znode_count" } metric { name = "zk_watch_count" } diff --git a/src/contrib/monitoring/ganglia/zookeeper_ganglia.py b/src/contrib/monitoring/ganglia/zookeeper_ganglia.py index 82903d1f609..f0fc54b5e58 100644 --- a/src/contrib/monitoring/ganglia/zookeeper_ganglia.py +++ b/src/contrib/monitoring/ganglia/zookeeper_ganglia.py @@ -85,8 +85,18 @@ def _parse_stat(self, data): if version: result['zk_version'] = version[version.index(':')+1:].strip() - # skip all lines until we find the empty one - while h.readline().strip(): pass + # count the number of connected clients till you get to a blank line + line = h.readline().strip() + num_clients=0 + while line: # this will break on the first empty line + # lines that look like this are connected clients: + # /10.0.0.128:38471[1](queued=0,recved=302,sent=302) + m = re.match('/[0-9.]+:\d+.*', line) + if m is not None: + num_clients += 1 + # get the next line and repeat + line = h.readline().strip() + result['zk_connected_clients'] = num_clients for line in h.readlines(): m = re.match('Latency min/avg/max: (\d+)/(\d+)/(\d+)', line) @@ -169,6 +179,7 @@ def metric_init(params=None): 'units': 'packets', 'slope': 'positive' }, + 'zk_connected_clients': {'units': 'connections'}, 'zk_outstanding_requests': {'units': 'connections'}, 'zk_znode_count': {'units': 'znodes'}, 'zk_watch_count': {'units': 'watches'},