def rfunc(info): # info.setdefault('host', '127.0.0.1') info.setdefault('port', 6379) # conn_kwargs = dict( host=info['host'], port=int(info['port']), ) # print('# Connect') print(pformat(conn_kwargs, indent=4, width=1)) # conn = None try: # conn = StrictRedis(**conn_kwargs) # res = '\n'.join('{:<30}: {}'.format(k, v) for k, v in conn.info().items()) # print('# Result') print(res) finally: # conn = None
def run_once(): for port in REDIS_PORT.split(','): if ',' in REDIS_PORT: statsd_prefix = STATSD_PREFIX + '-{}'.format(port) else: statsd_prefix = STATSD_PREFIX redis = StrictRedis(REDIS_HOST, port) stats = redis.info() stats['keyspaces'] = {} for key in stats.keys(): if key.startswith('db'): stats['keyspaces'][key] = stats[key] del stats[key] out_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for g in GAUGES: if g in stats: send_metric(out_sock, '{}.{}'.format(statsd_prefix, g), 'g', float(stats[g])) for c in COUNTERS: if c in stats: send_metric(out_sock, '{}.{}'.format(statsd_prefix, c), 'c', float(stats[c])) for ks in stats['keyspaces']: for kc in KEYSPACE_COUNTERS: if kc in stats['keyspaces'][ks]: send_metric(out_sock, '{}.keyspace.{}'.format(statsd_prefix, kc), 'c', float(stats['keyspaces'][ks][kc])) for kg in KEYSPACE_GAUGES: if kg in stats['keyspaces'][ks]: send_metric(out_sock, '{}.keyspace.{}'.format(statsd_prefix, kg), 'g', float(stats['keyspaces'][ks][kg])) out_sock.close() time.sleep(PERIOD)
def run_once(): for port in REDIS_PORT.split(','): if ',' in REDIS_PORT: statsd_prefix = STATSD_PREFIX + '-{}'.format(port) else: statsd_prefix = STATSD_PREFIX redis = StrictRedis(REDIS_HOST, port) stats = redis.info() stats['keyspaces'] = {} for key in stats.keys(): if key.startswith('db'): stats['keyspaces'][key] = stats[key] del stats[key] out_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for g in GAUGES: if g in stats: send_metric(out_sock, '{}.{}'.format(statsd_prefix, g), 'g', float(stats[g])) for c in COUNTERS: if c in stats: send_metric(out_sock, '{}.{}'.format(statsd_prefix, c), 'c', float(stats[c])) for ks in stats['keyspaces']: for kc in KEYSPACE_COUNTERS: if kc in stats['keyspaces'][ks]: send_metric(out_sock, '{}.keyspace.{}'.format( statsd_prefix, kc), 'c', float(stats['keyspaces'][ks][kc])) for kg in KEYSPACE_GAUGES: if kg in stats['keyspaces'][ks]: send_metric(out_sock, '{}.keyspace.{}'.format( statsd_prefix, kg), 'g', float(stats['keyspaces'][ks][kg])) out_sock.close() time.sleep(PERIOD)