20
20
import re , os , sys
21
21
from subprocess import Popen , PIPE
22
22
23
- def config (vm_names ):
23
+ def config (vms ):
24
24
''' Print the plugin's config
25
25
@param vm_names : a list of "cleaned" vms' name
26
26
'''
@@ -31,16 +31,20 @@ graph_info This graph shows the network I/O of the virtual machines
31
31
graph_args --base 1024
32
32
"""
33
33
print base_config
34
- for vm in vm_names :
35
- print "%s_in.label %s" % (vm , vm )
36
- print "%s_in.type COUNTER" % vm
37
- print "%s_in.min 0" % vm
38
- print "%s_in.draw LINE2" % vm
39
- print "%s_out.negative %s_in" % (vm , vm )
40
- print "%s_out.label %s" % (vm , vm )
41
- print "%s_out.type COUNTER" % vm
42
- print "%s_out.min 0" % vm
43
- print "%s_out.draw LINE2" % vm
34
+ for pid in vms :
35
+ macs = get_vm_macs (pid )
36
+ i = 0
37
+ for mac in macs :
38
+ print "%s_eth%s_in.label %s" % (vms [pid ],i , vms [pid ])
39
+ print "%s_eth%s_in.type COUNTER" % (vms [pid ], i )
40
+ print "%s_eth%s_in.min 0" % (vms [pid ],i )
41
+ print "%s_eth%s_in.draw LINE2" % (vms [pid ],i )
42
+ print "%s_eth%s_out.negative %s_in" % (vms [pid ], i , vms [pid ])
43
+ print "%s_eth%s_out.label %s" % (vms [pid ], i , vms [pid ])
44
+ print "%s_eth%s_out.type COUNTER" % (vms [pid ], i )
45
+ print "%s_eth%s_out.min 0" % (vms [pid ], i )
46
+ print "%s_eth%s_out.draw LINE2" % (vms [pid ], i )
47
+ i += 1
44
48
45
49
def clean_vm_name (vm_name ):
46
50
''' Replace all special chars
@@ -67,12 +71,14 @@ def fetch(vms):
67
71
interfaces [s [0 ]] = (s [1 ],s [2 ])
68
72
for pid in vms :
69
73
macs = get_vm_macs (pid )
74
+ i = 0
70
75
for mac in macs :
71
76
inf = macs_to_inf [mac ]
72
77
values = interfaces [inf ]
73
78
if len (values ) == 2 :
74
- print "%s_%s_in.value %s" % (vms [pid ], inf , values [0 ])
75
- print "%s_%s_out.value %s" % (vms [pid ], inf , values [1 ])
79
+ print "%s_eth%s_in.value %s" % (vms [pid ], i , values [0 ])
80
+ print "%s_eth%s_out.value %s" % (vms [pid ], i , values [1 ])
81
+ i += 1
76
82
77
83
def detect_kvm ():
78
84
''' Check if kvm is installed
@@ -135,7 +141,7 @@ if __name__ == "__main__":
135
141
else :
136
142
print "no"
137
143
elif sys .argv [1 ] == "config" :
138
- config (find_vm_names (list_pids ()). values () )
144
+ config (find_vm_names (list_pids ()))
139
145
else :
140
146
fetch (find_vm_names (list_pids ()))
141
147
else :
0 commit comments