Morning All, Please also keep in mind that /proc/stat is ONLY in Linux and Linux-HA despite the name is also used on FreeBSD and Solaris.
Thanks ! Matthew Soffen Lead Computer Scientist ISO New England - http://www.iso-ne.com/ -----Original Message----- From: linux-ha-boun...@lists.linux-ha.org [mailto:linux-ha-boun...@lists.linux-ha.org] On Behalf Of Michael Schwartzkopff Sent: Thursday, February 03, 2011 7:09 AM To: General Linux-HA mailing list Subject: Re: [Linux-HA] pacemaker/HealthCPU On Thursday 03 February 2011 12:35:34 Ulrich Windl wrote: > Hi! > > I'm starting to explore Linux-HA. Examining one of the monitors, I > think things could be made much more efficient. For example: To get > the percent of idle CPU the monitor uses 4 processes: top -b -n2 | > grep Cpu | tail -1 > | awk -F",|\.[0-9]%id" '{ print $4 }' > > However awk can do the effect of grep and tail as well. My first > attempt is > this: top -b -n2 | awk -F",|\.[0-9]%id" '/^Cpu/{ print $4; exit }' > > My second attempt uses /proc/stat instead, avoiding the slow top process: > awk '$1 == "cpu" { print $7; exit }' /proc/stat > > time (top -b -n2 | grep Cpu | tail -1 | awk -F",|\.[0-9]%id" '{ print > $4 > }') awk: warning: escape sequence `\.' treated as plain `.' > 99 > > real 0m3.533s > user 0m0.008s > sys 0m0.008s > > time (top -b -n2| awk -F",|\.[0-9]%id" '/^Cpu/{ print $4; exit }') > awk: warning: escape sequence `\.' treated as plain `.' > 99 > > real 0m0.518s > user 0m0.000s > sys 0m0.008s > > time awk '$1 == "cpu" { print $7; exit }' /proc/stat > 98 > > real 0m0.004s > user 0m0.000s > sys 0m0.000s > > Regards, > Ulrich Hi, good idea. The only problem it that the information in /proc/stats is in ticks and does not give you an absolute value. So you would have to calculate the difference yourself, which makes the task much more difficult. Greetings, -- Dr. Michael Schwartzkopff Guardinistr. 63 81375 München Tel: (0163) 172 50 98 _______________________________________________ Linux-HA mailing list Linux-HA@lists.linux-ha.org http://lists.linux-ha.org/mailman/listinfo/linux-ha See also: http://linux-ha.org/ReportingProblems