System monitoring using perl in linux

Posted on 2009-04-27
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
Question by:zoollu
    LVL 7

    Expert Comment


    . - 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 :)
    LVL 11

    Expert Comment

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

    Author Comment

    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.
    LVL 11

    Accepted Solution

    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.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    Suggested Solutions

    Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
    Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
    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…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now