Révision b6912e76
Update kvm_cpu
the line length change doesn't make the world better... without pyflakes I already wondered, why there is an additional linebreak. now it needs two additional one to stay below 99
changes here are tested and work on Python 3.7.3 (debian buster).
| plugins/libvirt/kvm_cpu | ||
|---|---|---|
| 47 | 47 |
@param vm_names : a list of "cleaned" vms' name |
| 48 | 48 |
''' |
| 49 | 49 |
percent = 100 * len( |
| 50 |
list(filter(lambda x: x[0:3] == 'cpu' and x[3] != ' ', open('/proc/stat', 'r').readlines())))
|
|
| 50 |
list( |
|
| 51 |
filter( |
|
| 52 |
lambda x: x[0:3] == 'cpu' and x[3] != ' ', open('/proc/stat', 'r').readlines())))
|
|
| 51 | 53 |
|
| 52 | 54 |
base_config = """graph_title KVM Virtual Machine CPU usage |
| 53 | 55 |
graph_vlabel %% |
| ... | ... | |
| 97 | 99 |
''' |
| 98 | 100 |
result = {}
|
| 99 | 101 |
for pid in pids: |
| 100 |
cmdline = open("/proc/%s/cmdline" % pid.decode(), "r")
|
|
| 102 |
cmdline = open("/proc/%s/cmdline" % pid, "r")
|
|
| 101 | 103 |
result[pid] = clean_vm_name( |
| 102 | 104 |
re.sub(r"^.*guest=([a-zA-Z0-9.-_-]*).*$", r"\1", cmdline.readline())) |
| 103 | 105 |
return result |
| ... | ... | |
| 108 | 110 |
@return a list of pids from running kvm |
| 109 | 111 |
''' |
| 110 | 112 |
pid = Popen("pidof qemu-kvm qemu-system-x86_64 kvm", shell=True, stdout=PIPE)
|
| 111 |
return pid.communicate()[0].split() |
|
| 113 |
return pid.communicate()[0].decode().split()
|
|
| 112 | 114 |
|
| 113 | 115 |
|
| 114 | 116 |
def fetch(vms): |
| ... | ... | |
| 116 | 118 |
@param dictionary {kvm_pid: cleaned vm name}
|
| 117 | 119 |
''' |
| 118 | 120 |
for pid, name in vms.items(): |
| 119 |
user, system = open("/proc/%s/stat" % pid.decode(), 'r').readline().split(' ')[13:15]
|
|
| 121 |
user, system = open("/proc/%s/stat" % pid, 'r').readline().split(' ')[13:15]
|
|
| 120 | 122 |
print('%s_cpu.value %d' % (name, int(user) + int(system)))
|
| 121 | 123 |
|
| 122 | 124 |
|
Formats disponibles : Unified diff