def metric_handler(name): if time.time() - ZK_LAST_METRICS['time'] > TIME_BETWEEN_QUERIES: zk = ZooKeeperServer(metric_handler.host, metric_handler.port, 5) try: metric_handler.info = zk.get_stats() except Exception, e: print >>sys.stderr, e metric_handler.info = {}
def get_cluster_stats(servers): """ Get stats for all the servers in the cluster """ stats = {} for host, port in servers: try: zk = ZooKeeperServer(host, port) stats["%s:%s" % (host, port)] = zk.get_stats() except socket.error, e: # ignore because the cluster can still work even # if some servers fail completely # this error should be also visible in a variable # exposed by the server in the statistics logging.info('unable to connect to server '\ '"%s" on port "%s"' % (host, port))