-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgostats.py
63 lines (53 loc) · 1.62 KB
/
gostats.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
import urlparse
import requests
from util import headers
from checks import AgentCheck
class GoStats(AgentCheck):
GAUGES = [
'cpu_num',
'cgo_call_num',
'goroutine_num',
'gomaxprocs',
'memory_alloc',
'memory_total_alloc',
'memory_lookups',
'memory_mallocs',
'memory_sys',
'memory_frees',
'memory_stack',
'heap_alloc',
'heap_sys',
'heap_idle',
'heap_inuse',
'heap_released',
'heap_objects',
'gc_num',
'gc_per_second',
'gc_pause_per_second',
]
HISTGRAMS = [
'gc_pause'
]
def check(self, instance):
if 'gostats_url' not in instance:
raise Exception("Missing 'gostats_url' in GoStats config")
try:
url = instance.get('gostats_url')
parsed_url = urlparse.urlparse(url)
gostats_host = parsed_url.hostname
gostats_port = parsed_url.port or 8080
r = requests.get(url, headers=headers(self.agentConfig))
r.raise_for_status()
status = r.json()
for metric in self.GAUGES:
if status.get(metric) is None:
continue
self.gauge('gostats.%s' % (metric), status.get(metric))
for metric in self.HISTGRAMS:
if status.get(metric) is None:
continue
for value in status.get(metric):
self.histogram('gostats.%s' % (metric), value)
except Exception, e:
self.log.error('error: %s' % str(e))
raise