[mrtg] Memory Usage with Changing Instances

Steve Shipway s.shipway at auckland.ac.nz
Wed Jul 23 01:47:48 CEST 2008


> I've been trying to graph Physical Memory usage on a Windows 2003 Server
> and run into a problem with changing OIDs.

I know this problem, it's why I ended up first writing a special plug-in that compares hrStorageDescr to find the correct item, and finally used the NSClient agent on the windows server to query the drive (use mrtg-pnsclient.pl to query the NSClient agent).

I don't think this is currently possible with native MRTG.  What you really want is something like WaLK(-1)hrStorageUsed to get the LAST entry (I think WaLKx will only get the Nth entry) but Tobi hasn't implemented this (yet).

Also, you need to be a bit careful about hrStorageAllocationUnits so you'd want to multiply by this as well in order to get bytes.

Probably the best thing is to use a script which retrieves the whole hrStorage tree, then identifies the correct item x by comparing against hrStorageDescr.x, and finally returning hrStorageUsed.x * hrStorageAllocationUnits.x (for space used) and  hrStorageSize.x * hrStorageAllocationUnits.x for the actual object size.

I've quickly knocked together a script to do it in Perl (since I can't find my original script), attached below.  No guarantee for it working but it seems to do what it should here.  Use:

Target[]: `mrtg-storage -H hostname -C snmpcommunity `

to get a list of storage objects and

Target[]: `mrtg-storage -H hostname -C snmpcommunity -v "objectname"`

to get the MRTG output.  Run it from the command line first to make sure you have passed the correct parameters.

HTH

Steve

------------------------------------- start of script
#!/usr/bin/perl -w
#
# mrtg-storage: return storage item usage from SNMP
# Version 0.1: Steve Shipway 2008
#
# usage: mrtg-storage -H hostname -C community -t timeout -d -v storage
#

use strict;
use Net::SNMP;
use Getopt::Std;
use vars qw/$opt_h $opt_H $opt_C $opt_t $opt_v $opt_d/;

my($hrStorage) = "1.3.6.1.2.1.25.2";
my($hrStorageDescr) = "$hrStorage.3.1.3";
my($hrStorageUsed ) = "$hrStorage.3.1.4";
my($hrStorageSize ) = "$hrStorage.3.1.5";
my($hrStorageAllocationUnits) = "$hrStorage.3.1.6";

my($HOSTNAME,$COMMUNITY,$MODULE) = ('localhost','public','');
my($TIMEOUT) = 10;
my($DEBUG) = 0;
my($snmp,$snmperr,$resp);
my($instance) = -1;
my($oid);

sub dohelp {
        print "Usage: mrtg-storage -H hostname -C community [-t timeout][-d][-v item]\n";
        exit 0;
}

# Process the arguments
getopts('H:C:t:v:dh');
if($opt_h) { dohelp(); exit(0); }
$TIMEOUT   = $opt_t if($opt_t);
$COMMUNITY = $opt_C if($opt_C);
$HOSTNAME  = $opt_H if($opt_H);
$MODULE    = $opt_v if($opt_v);
$DEBUG = 1 if($opt_d);

# Open the SNMP connection
($snmp,$snmperr) = Net::SNMP->session( -hostname=>$HOSTNAME,
        -community=>$COMMUNITY, -timeout=>$TIMEOUT );
if($snmperr) { print "UNKNOWN\nUNKNOWN\n\nError: $snmperr\n"; exit 0; }

# Search for matching storage entry
$resp = $snmp->get_table( -baseoid=>$hrStorageDescr );
if(!$resp) { print "UNKNOWN\nUNKNOWN\n\nNo SNMP data available\n"; exit 0; }
foreach $oid ( keys %$resp ) {
        print "Storage ".$resp->{$oid}." found...\n" if($DEBUG);
        if(!$MODULE) { print $resp->{$oid}."\n"; next; }
        if($resp->{$oid} eq $MODULE) {
                $instance=$1 if( $oid =~ /\.(\d+)$/ );
                last;
        }
}
exit 0 if(!$MODULE); # testing mode
if($instance<1) {
        print "UNKNOWN\nUNKNOWN\n\n";
        print "The $MODULE storage item is not present\n";
        exit 0;
}

# Now we know the sequence number, we can get the items
$resp = $snmp->get_request( -varbindlist=>[ "$hrStorageAllocationUnits.$instance", "$hrStorageSize.$instance", "$hrStorageUsed.$instance" ] );
if(!$resp) {
        print "UNKNOWN\nUNKNOWN\n\n";
        print "Plugin error: ".$snmp->errmsg()."\n";
        exit 0;
}

print "".($resp->{"$hrStorageUsed.$instance"}*$resp->{"$hrStorageAllocationUnits.$instance"})."\n";
print "".($resp->{"$hrStorageSize.$instance"}*$resp->{"$hrStorageAllocationUnits.$instance"})."\n";
print "\n";
print "Storage Used/Size for $MODULE\n";
exit 0;

-------------------- END OF SCRIPT
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mrtg-storage
Type: application/octet-stream
Size: 2317 bytes
Desc: mrtg-storage
Url : http://lists.oetiker.ch/pipermail/mrtg/attachments/20080723/5947f25a/attachment.obj 


More information about the mrtg mailing list