forked from pbanaszkiewicz/collectd-ganeti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kvm_net.py
41 lines (32 loc) · 1.12 KB
/
kvm_net.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
# coding: utf-8
import collectd
from discover_vm import discover, discover_nic
def config_net(data=None):
collectd.debug("Configuration: " + repr(data))
def init_net(data=None):
collectd.debug("Initialization: " + repr(data))
def read_net(data=None):
collectd.debug("Reading: " + repr(data))
for pid, host in discover().items():
nics = discover_nic(host)
if len(nics) < 1:
continue
# /var/lib/collectd/rrd/kvm_HOST/net_kvm/net-{in,out}.rrd
M_in = collectd.Values("counter")
M_in.host = "kvm_" + host
M_in.plugin = "net_kvm"
M_in.type_instance = "net_in"
M_out = collectd.Values("counter")
M_out.host = "kvm_" + host
M_out.plugin = "net_kvm"
M_out.type_instance = "net_out"
for line in open("/proc/net/dev", "r"):
if nics[0] in line:
s = line.strip().split()[1:]
M_in.values = [s[0]]
M_out.values = [s[8]]
M_in.dispatch()
M_out.dispatch()
collectd.register_config(config_net)
collectd.register_init(init_net)
collectd.register_read(read_net)