forked from innogames/igcollect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xen.py
executable file
·40 lines (30 loc) · 1.13 KB
/
xen.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
#!/usr/bin/env python
#
# igcollect - Xen
#
# Copyright (c) 2016, InnoGames GmbH
#
from __future__ import print_function
import socket, time
import subprocess
def get_uptime():
u=open('/proc/uptime','r')
uptime=u.readline().split(' ')[0]
u.close()
return(uptime)
def get_xminfo_dict(xmdata=False):
xminfo={}
for line in xmdata:
xminfo[line.split(':')[0].strip()]=line.split(':')[1].strip()
return(xminfo)
xmdata = subprocess.Popen("/usr/sbin/xm info", shell=True, bufsize=8192, stdout=subprocess.PIPE).stdout.readlines()
graphite_data=''
hostname = socket.gethostname().replace('.','_')
now = str(int(time.time()))
xminfo=get_xminfo_dict(xmdata)
uptime=get_uptime()
graphite_data += 'servers.%s.virtualisation.uptime %s %s\n' % (hostname,uptime, now )
graphite_data += 'servers.%s.virtualisation.xen.nr_cpus %s %s\n' % (hostname,int(xminfo['nr_cpus']), now )
graphite_data += 'servers.%s.virtualisation.xen.total_memory %s %s\n' % (hostname,int(xminfo['total_memory']), now )
graphite_data += 'servers.%s.virtualisation.xen.free_memory %s %s\n' % (hostname,int(xminfo['free_memory']), now )
print(graphite_data)