CPU Usage on RH8 false

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
scr
Posts: 7
Joined: Wed Mar 17, 2004 4:08 am

CPU Usage on RH8 false

Post by scr »

the script cpu.sh contains an error which cuases the shown CPU load to be more than 100%
false: Linux) vmstat -n 1 2 | tail -1 | awk '{print $(NF-3)+$(NF-2)}';;
right: Linux) vmstat -n 1 2 | tail -1 | awk '{print $(NF-1)+$(NF-2)}';;


HTH, Rainer
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Are you sure?
Accourding to man pages:

vmstat -n 1 2 | tail -1 | awk '{print $(NF-3)+$(NF-2)}' will retrun user time (NF-3) + system time (NF-2)

vmstat -n 1 2 | tail -1 | awk '{print $(NF-1)+$(NF-2)}' will show idle (NF-1) + system time (NF-2)

Regards
Alex
scr
Posts: 7
Joined: Wed Mar 17, 2004 4:08 am

Post by scr »

[root@TUX root]# vmstat -V
procps version 2.0.7
[root@TUX root]# vmstat -n
procs memory swap io system cpu r b w swpd free buff cache si so bi bo in cs us sy id
0 0 0 0 34300 84804 282404 0 0 4 55 35 162 3 1 96

[root@TUX root]# vmstat -n 1 2 | tail -1 | awk '{print $(NF-3)+$(NF-2)}'
831
[root@TUX root]# vmstat -n 1 2 | tail -1 | awk '{print $(NF-1)+$(NF-2)}'
1

In prectice the one I sent you produces reliable and true results.

HTH, Rainer
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Oh, I see. procps version 2.0 and version 3.1 have different output formats.
Script must check version and use different awk commands. Or we can have different scripts for differents platforms.
Thank you for information.

Regards
Alex
Post Reply