?
Solved

System monitoring using perl in linux

Posted on 2009-04-27
4
Medium Priority
?
1,044 Views
Last Modified: 2012-05-06
I am trying to monitor cpu usage (multiple), memory usage and disk usage using perl in Linux (CentOS). I have come across different methods but could not determine the best one. I have SNMP server running but I could not find the right OIDS for monitoring the system. I used mpstat P ALL for cpu monitor  . All of which give conflicting reports when trying to verify with the GUI utility that the OS has. I cannot use any third party software because it has to be tailor made for certain requirements. Also I am looking for something better than -top.

Does any have idea of OIDS available for SNMP or any other effective method to achieve this?

Thanks in advance
0
Comment
Question by:zoollu
  • 2
4 Comments
 
LVL 7

Expert Comment

by:mzalfres
ID: 24248295
Hi,

.1.3.6.1.4.1.8072.1.3.2 - NET-SNMP-EXTEND-MIB::nsExtendObjects may be the way you want.
Look at net-snmp documentation on how to use it. In general, you may monitor anything you want with your own scripts/prorgmas and either check values via snmpget from external machine or set up conditions to fire traps from dismanEventMIBObjects tree (.1.3.6.1.2.1.88). Simple example may look like this:

PERL script listing processes with memory usage visible "ps" command as non-zero:

#!/usr/bin/perl
use strict;
my @list=`ps -e -o "pid user rss %mem args" | grep -v '0.0'`;
my $num=1;
my %output;
my $proc;
for ($num =1; $num<=$#list; ++$num)
{
        chop($list[$num]);
        my @args = split (" ", $list[$num], 5);
        $output{"$args[2]:$args[0]"} = "$args[2] $args[1] $args[0] $args[3] $args[4]";
}
foreach $proc (sort {$b <=> $a} keys %output)
{
        print $output{$proc};
        print "\n";
}

Save this file somewhere and make it executable. In snmpd.conf you put following line::

  extend processes <path/to/your/file>

After that, when you do snmpget on NET-SNMP-EXTEND-MIB::nsExtendOutputFull."processes" you will get output from the script. OID will be created dynamically depending on your extension list.

Keep in mind, that you have to set up your snmp configuration correctly to allow reading OID subtree .1.3.6.1.4.1.8072.1.3 (nsExtensions).

Good luck :)
0
 
LVL 11

Expert Comment

by:kblack05
ID: 24251401
The easiest way to do what you are attempting is to capitalize on already created packages running in perl such as Munin:

http://munin.projects.linpro.no/
0
 

Author Comment

by:zoollu
ID: 24253159
So this means there is no OID already available in SNMP to monitor, cpu, memory and disk usage? I am trying to look for overall usage stats not per processor.  


I have looked into munin and also some of the other projects but mine is too simple to use a 3rd party application also I have different requirements. I have to integrate into an already existing product.
0
 
LVL 11

Accepted Solution

by:
kblack05 earned 150 total points
ID: 24254231
That was what I was getting at. Munin is entirely authored in Perl, perhaps you can look at some of what they have done, incorporate it, and tag them in the credits.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question