LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-03-2005, 02:16 AM   #1
sub_moa
LQ Newbie
 
Registered: Dec 2004
Location: Great Falls, Montana
Distribution: Mandrake 10.1, Fedora C3,4. Red Hat 8, LTSP
Posts: 16

Rep: Reputation: 0
Lightbulb 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
 
Old 11-03-2005, 02:40 AM   #2
sub_moa
LQ Newbie
 
Registered: Dec 2004
Location: Great Falls, Montana
Distribution: Mandrake 10.1, Fedora C3,4. Red Hat 8, LTSP
Posts: 16

Original Poster
Rep: Reputation: 0
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
 
Old 11-03-2005, 04:08 AM   #3
sub_moa
LQ Newbie
 
Registered: Dec 2004
Location: Great Falls, Montana
Distribution: Mandrake 10.1, Fedora C3,4. Red Hat 8, LTSP
Posts: 16

Original Poster
Rep: Reputation: 0
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?

Last edited by sub_moa; 11-03-2005 at 04:10 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Process monitor $@ya Programming 5 09-15-2005 11:57 AM
monitor process iclinux Programming 3 01-16-2005 02:00 PM
process monitor iclinux Programming 6 01-14-2005 09:35 PM
script to monitor process on remote machine kencha Linux - Newbie 6 01-07-2005 12:07 PM
How do I monitor a process? mad_ady Linux - General 5 11-07-2003 09:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration