-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzabbix-docker-stats.py
executable file
·49 lines (38 loc) · 1.1 KB
/
zabbix-docker-stats.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
#!/usr/bin/env python
import sys
import simplejson
import os
from docker import Client
not_want=[
"docker.memory_stats.stats",
"docker.blkio_stats",
"docker.cpu_stats.throttling_data"
]
class ErrorSendingValues(RuntimeError):
""" An error occured while sending the values to the Zabbix
server using zabbix_sender.
"""
def send_data(key,value):
print "["+str(key)+"] {"+str(value)+"}"
key=str(key)+"["+str(sys.argv[1])+"]"
r = os.system("%s -c '%s' -k '%s' -o '%s' -vv" % ('/usr/bin/zabbix_sender', '/etc/zabbix/zabbix_agentd.conf', str(key), str(value)))
if r != 0:
pass
#raise ErrorSendingValues, "An error occured sending the values to the server ["+str(key)+"]"
def unfold_data(key,obj):
if key in not_want:
return True
if isinstance(obj,dict):
for k in obj:
lkey=str(key)+"."+str(k)
if lkey in not_want:
continue
unfold_data(lkey,obj[k])
else:
send_data(key,obj)
c = Client(base_url='unix://var/run/docker.sock')
stats_obj = c.stats(sys.argv[1])
for stat in stats_obj:
stat=simplejson.loads(stat)
unfold_data("docker",stat)
sys.exit(0)