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).
This commit is contained in:
Alois 2021-03-04 16:39:27 +01:00 committed by Lars Kruse
parent acdaeb6d11
commit b6912e7649
1 changed files with 6 additions and 4 deletions

View File

@ -47,7 +47,9 @@ def config(vm_names):
@param vm_names : a list of "cleaned" vms' name
'''
percent = 100 * len(
list(filter(lambda x: x[0:3] == 'cpu' and x[3] != ' ', open('/proc/stat', 'r').readlines())))
list(
filter(
lambda x: x[0:3] == 'cpu' and x[3] != ' ', open('/proc/stat', 'r').readlines())))
base_config = """graph_title KVM Virtual Machine CPU usage
graph_vlabel %%
@ -97,7 +99,7 @@ def find_vm_names(pids):
'''
result = {}
for pid in pids:
cmdline = open("/proc/%s/cmdline" % pid.decode(), "r")
cmdline = open("/proc/%s/cmdline" % pid, "r")
result[pid] = clean_vm_name(
re.sub(r"^.*guest=([a-zA-Z0-9.-_-]*).*$", r"\1", cmdline.readline()))
return result
@ -108,7 +110,7 @@ def list_pids():
@return a list of pids from running kvm
'''
pid = Popen("pidof qemu-kvm qemu-system-x86_64 kvm", shell=True, stdout=PIPE)
return pid.communicate()[0].split()
return pid.communicate()[0].decode().split()
def fetch(vms):
@ -116,7 +118,7 @@ def fetch(vms):
@param dictionary {kvm_pid: cleaned vm name}
'''
for pid, name in vms.items():
user, system = open("/proc/%s/stat" % pid.decode(), 'r').readline().split(' ')[13:15]
user, system = open("/proc/%s/stat" % pid, 'r').readline().split(' ')[13:15]
print('%s_cpu.value %d' % (name, int(user) + int(system)))