2

I have been using /proc/stat for calculating the cpu usage. Recently I have been going through sar command for calculating cpu usage. And what I found was that their values were not related (I was considering the time interval in case of sar command that is 10 min).

say via /proc/stat I was getting cpu ussage 99.85% and sometimes 100% . and from sar command i was getting usage of 1-2%

Assuming that cpu usage% =100-cpu idle%

Note- I am having more than 100 cpu's which I am monitoring. Can any body explain why there were such differences in the cpu usage?

  • 100 CPUs on one system?? When you are looking at sar output, are you looking at the output for all? Perhaps you're looking at one CPU. Make sure it's apples-apples comparison. Do sar -P ALL | grep -w all. Also, sar is calculating the use since the last measurement. So if you're using sar to sample once every minute, you should compare that to a minute-to-minute comparison of /proc/stat info. – Otheus May 24 '16 at 12:24
  • yes I am looking at all different cpu's with different cpu id's. And time interval for sar I am using is for 5 min. and for the same interval I am calculating the values for /proc/stat – Abhijeet Kumar Srivastava May 24 '16 at 12:27
  • Why don't you post your algorithm or script that is calculating these values. Perhaps you found a bug in sar. The git page for sar is github.com/sysstat/sysstat. If you see a problem, I encourage you to file an 'issue'. Maybe also check CHANGELOG for indications of bugs between your version and the current project's head. But let's start with your algorithm. – Otheus May 24 '16 at 12:40
  • Look for file rd_stats.c and function read_stat_cpu in that repository. – Otheus May 24 '16 at 12:48
  • I am using cpu usage from the following link stackoverflow.com/questions/23367857/… . – Abhijeet Kumar Srivastava May 25 '16 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.