Skip to content

Commit

Permalink
Update kvm_cpu
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
AloisKlingler authored and sumpfralle committed Mar 10, 2021
1 parent acdaeb6 commit b6912e7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions plugins/libvirt/kvm_cpu
Original file line number Diff line number Diff line change
Expand Up @@ -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 %%
Expand Down Expand Up @@ -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
Expand All @@ -108,15 +110,15 @@ 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):
''' Fetch values for a list of pids
@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)))


Expand Down

0 comments on commit b6912e7

Please sign in to comment.