LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Process monitor script? (https://www.linuxquestions.org/questions/programming-9/process-monitor-script-379490/)

sub_moa 11-03-2005 02:16 AM

Process monitor script?
 
Hey guys.

My question is pretty simple. I've got a script here that will monitor hard drive usage. Once it gets to 90% i get a snmp alarm. My next project is to monitor CPU usage. With my hard drive script i use df -a to get my hard drive usage in a perl script. Is there any command that will output how much CPU usage is currently being used. Any help is greatly appreciated.

Thanks.

-Moa

sub_moa 11-03-2005 02:40 AM

I guess i posted a little bit early. top -b -n 1 works to get output. Any suggestions how i add up the total in the CPU line ( in perl ).

Thanks again,

Moa

sub_moa 11-03-2005 04:08 AM

To make things a little bit more clear. This is my Script to send the trap after it checks the hda %. I imagine it only needs to be altered just a little bit to get this to work. I just need to add up the %CPU usage column then send if it's above a certain %....

Code:

#!/usr/bin/perl

$above = 11;

use FileHandle;
use BER '0.58';
use SNMP_Session '0.58';
use SNMP_util "0.54";

@check=`df /dev/hda1`;

##### Checks for lines higher than $above
foreach (@check) {
        if (m/(\d+\%)/ and $1 >=$above) {
                push @New,$_;
        }
}

##### If there is anything found, send trap
if (@New) {
        snmptrap("public\@10.64.15.202:162", ".1.2.3.2.1.127.1.0", "localhost", 6, 1,".1.2.3.2.1.127.1.0", "string", "Disk Space Reached $above% full on @New\n!");

}

This one works just fine. Any suggestions on checking CPU usage?


All times are GMT -5. The time now is 04:10 AM.