So, I have an Adtran router and I'd like to monitor both CPU and memory utilization in a single graph. Unfortunately Adtran doesn't offer a percentage guage for memory utilization the way it does for CPU utilization. It does offer two OIDs: one that gives you the free memory in bytes and the other that gives you total memory in bytes.
I would like to create a cpu_memory target in my MRTG configuration that does the necessary math but I can't see a way to do it. Ideally it would work something like this:
# CPU Utilization OID: .1.3.6.1.4.1.664.5.53.1.4.1.0
# Total Memory OID: .1.3.6.1.4.1.664.5.53.1.4.7.0 (adGenAOSHeapSize)
# Free Memory OID: .1.3.6.1.4.1.664.5.53.1.4.8.0 (adGenAOSHeapFree)
Target[rtr-cpu_mem]: .1.3.6.1.4.1.664.5.53.1.4.1.0&( 100 - ( .1.3.6.1.4.1.664.5.53.1.4.8.0 / .1.3.6.1.4.1.664.5.53.1.4.7.0 ) ):[email protected]
# ... rest of config
Is this even possible? Or, will I have to have a separate graph for the memory?
This is not really possible to do in a single native Target, since calculations apply to both values. While you can use pseudoZero and pseudoOne to get around this in part, you can't manage it this way.
I would advise that you have one Target for CPU, and a separate Target for the Memory calculation, which makes it much simpler. You can then use the 'dorelpercent' option on the Memory Target and have it fetch the used and total into the separate values.
However, if you really, really, have to have then in the same target, there is an awkward way to kludge it -- custom data conversion functions.
You can define a custom perl function to multiply the second item by 100, if it is less than 1, and store this into a flie 'conversion.pl'
sub topercent {
my $value = shift;
return ($1 * 100) if( $value =~ /([01]\.\d*)/ and ($1<=1));
return $value;
}
Then, define your Target like this (replace cpuoid, totalmemoid and freememoid appropriately):
ConversionCode: /path/to/conversion.pl
Target[cpumem]: ( cpuoid&totalmemoid:comm@rtr - pseudoZero&freememoid:comm&rtr ) / ( pseudoOne&totalmemoid:comm@rtr ) |topercent
This results in In=cpupercent, Out=memusedpercent
I wouldn't advise doing it this way, though; best to stick to separate Targets for Memory and CPU. You can always combine these two targets into a single graph for display if you're using MRTG/RRD with Routers2 anyway.
Another alternative is to write a custom collection script that does the retrieval and processing, and define it like this:
Target[cpumem]: `myscript.sh community router`
and make myscript.sh
output four lines; CPU percent, Memory percent, and two blank lines.