Skip to content

Commit

Permalink
Update kvm_cpu
Browse files Browse the repository at this point in the history
in python3 filter returns an object, not an list. I think a list is required here? at least the plugin works as soon as list(...) is added.
need to change from pid to pid.decode, as pid is binary and not a string.
  • Loading branch information
AloisKlingler authored and sumpfralle committed Mar 10, 2021
1 parent 9ecd634 commit acdaeb6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/libvirt/kvm_cpu
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def config(vm_names):
@param vm_names : a list of "cleaned" vms' name
'''
percent = 100 * len(
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 +97,7 @@ def find_vm_names(pids):
'''
result = {}
for pid in pids:
cmdline = open("/proc/%s/cmdline" % pid, "r")
cmdline = open("/proc/%s/cmdline" % pid.decode(), "r")
result[pid] = clean_vm_name(
re.sub(r"^.*guest=([a-zA-Z0-9.-_-]*).*$", r"\1", cmdline.readline()))
return result
Expand All @@ -116,7 +116,7 @@ def fetch(vms):
@param dictionary {kvm_pid: cleaned vm name}
'''
for pid, name in vms.items():
user, system = open("/proc/%s/stat" % pid, 'r').readline().split(' ')[13:15]
user, system = open("/proc/%s/stat" % pid.decode(), 'r').readline().split(' ')[13:15]
print('%s_cpu.value %d' % (name, int(user) + int(system)))


Expand Down

0 comments on commit acdaeb6

Please sign in to comment.