LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Monitoring Script (using mpstat) tip (https://www.linuxquestions.org/questions/programming-9/monitoring-script-using-mpstat-tip-180612/)

ganninu 05-12-2004 05:31 AM

Monitoring Script (using mpstat) tip
 
Hi folks,

I'm in the process of writing a generic script which will monitor CPU usage (in terms of idle time) on a Solaris 8 box (However this would work on any UNIX system). I'm using the 'mpstat' command in the following way:

bash-2.03$ mpstat 1 3 | awk -F" " {'print $16'} > cpu_usage

bash-2.03$ cat cpu_usage
idl
84
85
idl
93
88
idl
100
99

The 'mpstat 1 3' part will display 3 values of CPU statistics per CPU, sampled on a 1 second basis,. The awk part will only grab the "idl" value since mpstat generates much more statistics.

As you can see in the example above, I have 2 CPUs.

My ultimate goal is to provide an average of the 'idl' value for each CPU. I am finding problems extracting the 84,93 and 100 numbers for one CPU and the 85,88, and 99 numbers for the other CPU.... Remember that I have to keep in consideration the fact that the number of CPUs can vary and I want to keep the script as generic as possible.

Thanks for any tips.


All times are GMT -5. The time now is 07:19 AM.