[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-users] "xentop -b -i1" always returns 0 for cpuload
Quoting Massimo Canonico's message from 05 sep 2012: >Hi, >I need to save into a file the "cpu load" value for a specific domain >provided by "xentop" command. > >So I decided to write a very simple bash script: >while : >do > sudo xentop -b -i1 | grep <domainName> | awk '{print $4}' > sleep 10 >done I remember back some years people talked about "cat abuse" when someone suggested to do "cat foo | grep bar". So I'll dub this "grep abuse" because awk can do what grep does, and much much more, especially in these instances. >The problem is that with "-i1" I always get 0.0 as output values, even >if when xentop (without "-b -i1") provides me the right cpu load >values. I can confirm this after having tested it myself. The first iteration of xentop has bogative values. >How can I fix this problem? Fixing this requires modifying xentop but you can work around it, awk to the rescue! What we want is the output from xentop's second iteration. Then, just let awk print that. while true; do xentop -b -i2 | awk '$1 == "VMname" && ++iter > 1 {print $4}' sleep 10s done The above awk says "if $1 exactly matches "VMname", and (iter+1) is more than one, print $4." If you want to match with a regular expression, replace the $1 == "VMname" with $1 ~ /regex/. You don't need the while loop at all by the way. xentop has a --delay=SECONDS (-d) parameter. So you could also opt to do: xentop -b -d 10 | awk '/VMname/ && ++iter > 1 {print $4}' I suppose the only downside of the second approach is that you have a 10 second delay at startup. HTH -Mark _______________________________________________ Xen-users mailing list Xen-users@xxxxxxxxxxxxx http://lists.xen.org/xen-users
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |