The CPU usage statistics are computed by grepping the top command
output. The top output format as since changed so the CPU usage
statistics were not properly computed.
Fix this by adjusting to the new top command output format.
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
top_line = top_line.replace(",","")
words = top_line.split()[1:]
top_line = top_line.replace(",","")
words = top_line.split()[1:]
- for word in words:
- index = word.find('%')
+
+ for key in top_dict:
+ index = words.index(key)
# Add the value to the dictionnary
# Add the value to the dictionnary
- top_dict[word[index + 1:]] = float(word[:index])
+ val = words[index-1]
+ top_dict[key] = float(val)
# Spawn top process
top = subprocess.Popen(args, stdout = subprocess.PIPE)
# Spawn top process
top = subprocess.Popen(args, stdout = subprocess.PIPE)
- grep = subprocess.Popen(["grep", "^Cpu"], stdin = top.stdout,
+ grep = subprocess.Popen(["grep", "Cpu"], stdin = top.stdout,
stdout = subprocess.PIPE)
top.stdout.close()
stdout = subprocess.PIPE)
top.stdout.close()