-
Notifications
You must be signed in to change notification settings - Fork 0
/
sysmetricfire.py
executable file
·58 lines (46 loc) · 1.67 KB
/
sysmetricfire.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
#!/usr/bin/python
# This is an early version of a script, developed under the BSD
# license.
#
# FRLinux - frlinux@frlinux.net
# Thanks to John Hamill for the help on Python :)
#
# you need psutil v0.4 or above - http://code.google.com/p/psutil/
#
# v0.1 - 13/12/11 - basic metrics feeding to metricfire
# v0.2 - 14/12/11 - more metrics gathering based on psutil
import time
import psutil
import metricfire
# send key to server
# add key here in the form of /key
metricfire.init("")
# cpu
cputimes = psutil.cpu_times()
#print type(cputimes),dir(cputimes)
cpus= ['user', 'nice', 'system', 'idle', 'iowait', 'irq', 'softirq']
for cpu in cpus:
metric = getattr(cputimes,cpu)
metricfire.send("cpu." + cpu, str(metric))
# memory
phymemusage = psutil.phymem_usage()
virtmemusage = psutil.virtmem_usage()
mems = ['total', 'used', 'free', 'percent' ]
for mem in mems:
metric = getattr(phymemusage,mem)
metricfire.send("phymem." + mem, str(metric))
metric = getattr(virtmemusage,mem)
metricfire.send("virtmem." + mem, str(metric))
disks = psutil.disk_usage('/')
partitions = ['total', 'used', 'free', 'percent' ]
for partition in partitions:
metric = getattr(disks,partition)
metricfire.send("disk." + partition, str(metric))
interface = psutil.network_io_counters('eth0')
#print type(interface),dir(interface)
nics = ['bytes_sent', 'bytes_recv']
for eth,iostats in interface.iteritems():
if "eth0" in eth:
for nic in nics:
metric = getattr(iostats,nic)
metricfire.send("eth0." + nic, metric)