CLOUDSTACK-3383: Fetch CPU utilization more reliable.

This should fix that we can't gather CPU statistics on hypervisors
> Ubuntu 12.04
This commit is contained in:
Wido den Hollander 2014-11-11 16:49:38 +01:00 committed by Daan Hoogland
parent 713a3590b6
commit ee8facd382
1 changed files with 1 additions and 1 deletions

View File

@ -3255,7 +3255,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
private Answer execute(GetHostStatsCommand cmd) {
final Script cpuScript = new Script("/bin/bash", s_logger);
cpuScript.add("-c");
cpuScript.add("idle=$(top -b -n 1|grep Cpu\\(s\\):|cut -d% -f4|cut -d, -f2);echo $idle");
cpuScript.add("idle=$(top -b -n 1| awk -F, '/^[%]*[Cc]pu/{$0=$4; gsub(/[^0-9.,]+/,""); print }'); echo $idle");
final OutputInterpreter.OneLineParser parser = new OutputInterpreter.OneLineParser();
String result = cpuScript.execute(parser);