System monitoring using perl in linux

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
Who is Participating?
kblack05Connect With a Mentor Commented:
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.

. - 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 (. Simple example may look like this:

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

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)
        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 . (nsExtensions).

Good luck :)
The easiest way to do what you are attempting is to capitalize on already created packages running in perl such as Munin:
zoolluAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.