zookeeper自带监控zookeeper.conf及zookeeper_ganglia.py文件。
稍作修改:
def _parse(self, data):
""" Parse the output from the 'mntr' 4letter word command """
h = StringIO(data)
result = {}
for line in h.readlines():
try:
key, value = self._parse_line(line)
result[key] = value
except ValueError:
pass # ignore broken lines
return result
def _parse(self, data):
""" Parse the output from the 'mntr' 4letter word command """
h = StringIO(data)
result = {}
for line in h.readlines():
try:
key, value = self._parse_line(line)
result[key] = value
except ValueError:
pass # ignore broken lines
if result.get('zk_server_state')=='follower':
result['zk_server_state']='F'
else:
result['zk_server_state']='M'
return result
def metric_init(params=None):
params = params or {}
metric_handler.host = params.get('host', 'localhost')
metric_handler.port = int(params.get('port', 2181))
metric_handler.timestamp = 0
metrics = {
'zk_avg_latency': {'units': 'ms'},
'zk_max_latency': {'units': 'ms'},
'zk_min_latency': {'units': 'ms'},
'zk_packets_received': {
'units': 'packets',
'slope': 'positive'
},
'zk_packets_sent': {
'units': 'packets',
'slope': 'positive'
},
'zk_outstanding_requests': {'units': 'connections'},
'zk_znode_count': {'units': 'znodes'},
'zk_server_state': {'units': 'f/m'},
'zk_watch_count': {'units': 'watches'},
'zk_ephemerals_count': {'units': 'znodes'},
'zk_approximate_data_size': {'units': 'bytes'},
'zk_open_file_descriptor_count': {'units': 'descriptors'},
'zk_max_file_descriptor_count': {'units': 'descriptors'},
'zk_followers': {'units': 'nodes'},
'zk_synced_followers': {'units': 'nodes'},
'zk_pending_syncs': {'units': 'syncs'}
}