-
Notifications
You must be signed in to change notification settings - Fork 18
/
stats-to-datadog.py
70 lines (60 loc) · 2.03 KB
/
stats-to-datadog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import urllib2
import json
import sys
import time
import os
from statsd import statsd
import sys
statsd.connect('localhost', 8125)
def report_stats(host, topology, toporoot, topic):
state = urllib2.urlopen(
"http://{}/api/status?toporoot={}&topic={}".format(
host, toporoot, topic
)
).read()
data = json.loads(state)
total_delta = 0
total_kafka_current = 0
total_spout_current = 0
for looplord in data:
if looplord['amount'] is not None:
partition_tags = [
"topic:{}".format(topic),
"topology:{}".format(topology),
"partition:{}".format(looplord['partition'])
]
statsd.gauge(
'razor.kafkamon.topology.partition',
looplord['amount'],
tags = partition_tags
)
total_delta += looplord['amount']
print "Got amount={}, for {}".format(
total_delta, topology)
total_tags = [
"topic:{}".format(topic),
"topology:{}".format(topology)
]
statsd.gauge(
'razor.kafkamon.total_delta',
total_delta, tags = total_tags
)
statsd.gauge(
'razor.kafkamon.total_kafka_current',
total_kafka_current, tags = total_tags
)
statsd.gauge(
'razor.kafkamon.total_spout_current',
total_spout_current, tags = total_tags
)
host = sys.argv[1]
print "pulling stats from capillary at: {}".format(host)
reports = json.loads(open(sys.argv[2]).read())
print "Reporting on {}".format(json.dumps(reports, indent=4))
for topo, root, topic in reports:
print "querying stats for topo:{} root:{} topic:{}".format(topo, root, topic)
try:
report_stats(host, topo, root, topic)
except Exception as e:
print "Failed to report metrics for {}/{}/{} because: {}".format(topo, root, topic, str(e))
sys.stdout.flush()