Hi,

I have a problem to calculate percentage cpu usage in linux.

As I know that I can calculate the the percentage by this formula,

 

long cpu_diff_total =
            diff( cpu_user1, cpu_user2 ) +
            diff( cpu_syst1, cpu_syst2 ) +
            diff( cpu_nice1, cpu_nice2 ) +
            diff( cpu_idle1, cpu_idle2 );

      long cpu_percent = (long)(((double)((
            diff( cpu_user1, cpu_user2 ) +
            diff( cpu_syst1, cpu_syst2 ) +
            diff( cpu_nice1, cpu_nice2 ) )) / (double)cpu_diff_total) *
100);

Or,

 

Got ssCpuRawIdle twice 60 seconds apart and got a difference of 4327.
Dividing this by 6000 (60 centi-seconds???), I got 0.72. The idle percent of this system is around 72%.

 

Which method gives accurate value?

 

Also polling is required for both of the methods, so will it create problem in getting CPU real time performance values???

Because SNMP agent will have some polling time and again we will poll agent, so adding these two polling period may give slight deviation of real time CPU performance at any specific time.

 

If anybody has idea about these problem , please tell me.

 

 

 

 

 

Reply via email to