From b6912e7649af552f12eba8ab039e709edca984cd Mon Sep 17 00:00:00 2001 From: Alois <11095760+AloisKlingler@users.noreply.github.com> Date: Thu, 4 Mar 2021 16:39:27 +0100 Subject: [PATCH] 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/libvirt/kvm_cpu b/plugins/libvirt/kvm_cpu index 7880f78c..3196dc26 100755 --- a/plugins/libvirt/kvm_cpu +++ b/plugins/libvirt/kvm_cpu @@ -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)))