args = parser.parse_args() slave_location = args.slave monitor_endpoint = 'http://%s/%s' % (slave_location, args.slave_monitor) metrics_endpoint = 'http://%s/%s' % (slave_location, args.slave_metrics) slave_endpoint = 'http://%s/%s' % (slave_location, args.slave_state) influx_endpoint = 'http://%s/db/%s/series?u=%s&p=%s' % ( args.influxdb_host, args.influxdb_name, args.influxdb_user, args.influxdb_password) # One second sample rate. sample_rate = 1 # Get slave state object once to tag samples. slave_state = nibbler.json_from_url(slave_endpoint) slave_id = slave_state['id'] samples = {} sample_count = 0 # Sample loop. while True: # If InfluxDB failed over, make sure database is available. if sample_count % 10 == 0: create_json = '{"name": "%s"}' % args.influxdb_name create_url = 'http://%s/db?u=%s&p=%s' % (args.influxdb_host, args.influxdb_user, args.influxdb_password) nibbler.post_json(create_url, create_json) # Poor mans GC: We loose one sample per framework every 10.000 iterations. sample_count += 1
master_endpoint = 'http://%s/%s' % (master_location, args.master_state) influx_endpoint = 'http://%s/db/%s/series?u=%s&p=%s' % ( args.influxdb_host, args.influxdb_name, args.influxdb_user, args.influxdb_password) create_json = '{"name": "%s"}' % args.influxdb_name create_url = 'http://%s/db?u=%s&p=%s' % (args.influxdb_host, args.influxdb_user, args.influxdb_password) nibbler.post_json(create_url, create_json) # One second sample rate. sample_rate = 1 # Sample loop. while True: # TODO(nnielsen): Don't fetch state json every iteration. # Get slave state object once to tag samples and determine leader. master_state = nibbler.json_from_url(master_endpoint) if "leader" in master_state and "pid" in master_state: if master_state["leader"] != master_state["pid"]: print "Master is not the current leader - waiting 5 seconds" time.sleep(5) continue master_id = master_state["id"] influx_samples = [] # Collect the latest metrics (gauges and counters). metrics = nibbler.json_from_url(metrics_endpoint) for metric in metrics: influx_samples.append({