[mrtg] Maxbytes issue

Daniel J McDonald dan.mcdonald at austinenergy.com
Fri Jan 18 14:39:27 CET 2008


On Fri, 2008-01-18 at 13:47 +0100, Pili Muñoz Gargallo wrote:
> Hi all,
> 
> I am trying to monitor the percentage of the usage of the a wireless
> link. i know the maximun capacity of the link depends on a parameter,
> which i could obtain by SNMP (reading the OID).
> 
> My question is if it would be possible to obtain the MaxBytes like the
> output of a function which would have like input this SNMP parameter.

Only way to do that is by using a template when cfgmaker is run.  A
template is just a perl program that is run by cfgmaker and alters the
output of it.  I often determine maxbytes by way of polling one or more
snmp OID's, performing some calculation on them, and then adding that to
the config file.

Here's an example for a UPS - I need to determine lots of parameters
(because I have single-phase, two-phase, and three-phase UPS's that all
use the same MIB).  As you can see, I perform calculations on the polled
OID values to come up with reasonable graphs.

[mcdonalddj at ldap ~]$ cat /var/mrtg/cfg/ups.template
$head_lines .= <<ECHO
#.....................................................................
ECHO
;
 
my $target_name=$router_name.".min";
my ( $maxmins, $maxsec, $absmin, $yellowvolts, $redvolts, $absvolts,
@basis );
snmpMIB_to_OID("/usr/share/snmp/mibs/ups.mib");
my ($model) = snmpget($router_connect,"upsIdentModel.0");

push @basis, 'upsEstimatedMinutesRemaining.0';
push @basis, 'upsConfigInputVoltage.0';
push @basis, 'upsConfigOutputVoltage.0';
push @basis, 'upsInputNumLines.0';
push @basis, 'upsOutputNumLines.0';
push @basis, 'upsConfigOutputFreq.0';
push @basis, 'upsConfigOutputVA.0' if $model !~ /Nfinity/;
my ($remain,$volts,$ovolts,$ilines,$olines,$freq,$va) = 
        snmpget($router_connect, at basis);
if ($model =~ /Nfinity/ and not defined($va)) {
        $va =20000;
}
if ($model =~ /GXT2-6000RT208/) {
        $volts = 208;
        $ovolts = 120;
        $ilines = 1;
        $olines = 1;
}
if ($remain) {
        $maxmins = int($remain / .9);
        $maxsec = $maxmins * 60;
        $absmin = $remain * 10;
}
else {
        $maxmins= 510;
        $maxsec= $maxmins * 60;
        $absmin = 1000;
}
if ($volts) {
        if ($volts != $ovolts) {
                $yellowvolts = int($volts/1.10) . ":" . int($volts/.9)
                        . ":" . int($ovolts/1.10) . ":" .
int($ovolts/.9);
                $redvolts = int($volts/1.2) . ":" . int($volts/.8)
                        . ":" . int($ovolts/1.20) . ":" .
int($ovolts/.8);
                $absvolts = $volts*2;
        }
        else {
                $yellowvolts = int($volts/1.10) . ":" . int($volts/.9);
                $redvolts = int($volts/1.2) . ":" . int($volts/.8);
                $absvolts = $volts*2;
        }
}
else {
        $volts=120;
        $yellowvolts = "114:126";
        $redvolts = "109:135";
        $absvolts= 240;
}

$target_lines .= <<MINUTES
Target[$target_name]:
upsEstimatedMinutesRemaining.0&upsEstimatedMinutesRemaining.0:
$router_connect
bb*host[$target_name]: $router_name
bb*svc[$target_name]: upsmin
bb*yellow[$target_name]: 60:$absmin
bb*red[$target_name]: 30:$absmin
routers.cgi*Options[$target_name]: nototal
Directory[$target_name]: $directory_name
MaxBytes[$target_name]: $maxmins
AbsMax[$target_name]: $absmin
RouterUptime[$target_name]: $router_connect
Options[$target_name]: Gauge noi
Title[$target_name]: UPS Estimated Run Time
YLegend[$target_name]: minutes
ShortLegend[$target_name]: m
LegendI[$target_name]: remaining

PageTop[$target_name]: <H1>UPS Estimated Run-Time</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>$sysname  </TD></TR>
   <TR><TD>Location:</TD><TD>$syslocation </TD></TR>
 </TABLE>
MINUTES
;
$target_name=$router_name.".sec";
$target_lines .= <<SECONDS
#.....................................................................
Target[$target_name]: upsSecondsOnBattery.0&upsSecondsOnBattery.0:
$router_connect
bb*host[$target_name]: $router_name
bb*svc[$target_name]: upsrun
bb*yellow[$target_name]: 300
bb*red[$target_name]: 600
routers.cgi*Options[$target_name]: nototal
Directory[$target_name]: $directory_name
MaxBytes[$target_name]: $maxsec
RouterUptime[$target_name]: $router_connect
Options[$target_name]: Gauge noi
Title[$target_name]: UPS Actual Run Time
YLegend[$target_name]: seconds 
ShortLegend[$target_name]: s
LegendI[$target_name]: run time

PageTop[$target_name]: <H1>UPS Actual Time on Battery</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>$sysname  </TD></TR>
   <TR><TD>Location:</TD><TD>$syslocation </TD></TR>
 </TABLE>
SECONDS
;
my $i = 0;
while ( ++$i le $ilines) {
        $target_name=$router_name.".volt";
        my $phase = ''; 
        $target_name=$router_name.".volt.".$i if $ilines > 1;
        $phase = "Phase # $i" if $ilines > 1;
$target_lines .= <<VOLTAGE
#.....................................................................
Target[$target_name]: upsInputVoltage.$i&upsOutputVoltage.$i:
$router_connect
bb*host[$target_name]: $router_name
bb*svc[$target_name]: voltage
bb*yellow[$target_name]: $yellowvolts
bb*red[$target_name]: $redvolts
routers.cgi*Options[$target_name]: nototal
Directory[$target_name]: $directory_name
MaxBytes[$target_name]: $volts
AbsMax[$target_name]: $absvolts
RouterUptime[$target_name]: $router_connect
Options[$target_name]: Gauge
Title[$target_name]: UPS Voltages $phase
YLegend[$target_name]: volts
ShortLegend[$target_name]: vac
LegendI[$target_name]: input
LegendO[$target_name]: output

PageTop[$target_name]: <H1>UPS Voltages $phase </H1>
 <TABLE>
   <TR><TD>System:</TD><TD>$sysname  </TD></TR>
   <TR><TD>Location:</TD><TD>$syslocation </TD></TR>
 </TABLE>
VOLTAGE
;
}
($volts) = snmpget($router_connect,'upsBatteryVoltage.0');
if ($volts) {
        $yellowvolts = int($volts/10.5) . ":" . int($volts/9.5);
        $redvolts = int($volts/11) . ":" . int($volts/9);
        $absvolts = int($volts/7);
        $volts = int($volts/10);
}
else {
        $volts=55;
        $yellowvolts = "52:57";
        $redvolts = "48:60";
        $absvolts= 80;
}
$target_name=$router_name.".batt";
$target_lines .= <<BATTERY
#.....................................................................
Target[$target_name]: upsBatteryVoltage.0&upsBatteryVoltage.0:
$router_connect / 10
bb*host[$target_name]: $router_name
bb*svc[$target_name]: voltage
bb*red[$target_name]: $redvolts
bb*yellow[$target_name]: $yellowvolts
routers.cgi*Options[$target_name]: nototal
Directory[$target_name]: $directory_name
MaxBytes[$target_name]: $volts
AbsMax[$target_name]: $absvolts
RouterUptime[$target_name]: $router_connect
Options[$target_name]: Gauge noi
Title[$target_name]: UPS Battery Voltage
YLegend[$target_name]: volts
ShortLegend[$target_name]: vdc
LegendI[$target_name]: battery level

PageTop[$target_name]: <H1>UPS Battery Voltage</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>$sysname  </TD></TR>
   <TR><TD>Location:</TD><TD>$syslocation </TD></TR>
 </TABLE>
BATTERY
;
$i = 0;
while (++$i le $ilines) {
        my $addgraph;
        $target_name=$router_name.".current";
        my $redcurrent = int($va/1.1);
        my $yelcurrent = int($va/1.6);
        my $multgraph = $target_name;
        my $phase = '';
        $target_name=$router_name.".current.".$i if $ilines > 1;
        $phase = "Phase # $i" if $ilines > 1;
        $addgraph = "routers.cgi*Graph[$target_name]: $multgraph total"
                if $ilines > 1;
        my $custarget = <<TARSINGLE
Target[$target_name]: upsOutputVoltage.$i&upsOutputVoltage.$i:
$router_connect
  * upsOutputCurrent.$i&upsOutputCurrent.$i:$router_connect / 10
TARSINGLE
;
        $custarget = <<TARMULTIPLE
Target[$target_name]: upsInputVoltage.$i&upsOutputVoltage.$i:
$router_connect
  * upsInputCurrent.$i&upsOutputCurrent.$i:$router_connect / 10
TARMULTIPLE
        if $ilines > 1;
my $noi ='';
$noi = 'noi' if $ilines >1;

$target_lines .= <<CURRENT
#.....................................................................
$custarget
bb*host[$target_name]: $router_name
bb*svc[$target_name]: current
bb*yellow[$target_name]: $yelcurrent
bb*red[$target_name]: $redcurrent
routers.cgi*Options[$target_name]: nototal
$addgraph
Directory[$target_name]: $directory_name
MaxBytes[$target_name]: $va
RouterUptime[$target_name]: $router_connect
Options[$target_name]: Gauge $noi
Title[$target_name]: UPS Current $phase
YLegend[$target_name]: va
ShortLegend[$target_name]: va
LegendI[$target_name]: input
LegendO[$target_name]: output

PageTop[$target_name]: <H1>UPS Current $phase </H1>
 <TABLE>
   <TR><TD>System:</TD><TD>$sysname  </TD></TR>
   <TR><TD>Location:</TD><TD>$syslocation </TD></TR>
 </TABLE>
CURRENT
;

}
$target_name=$router_name.".freq";
$freq =  $freq / 10;
my $freqlow = $freq - .4;
my $freqyel = $freq - .2;
my $freqhigh = $freq + .4;
my $freqyeh = $freq + .2;
my $freqmax = int($freq /.9);
$target_lines .= <<FREQ
#.....................................................................
Target[$target_name]: upsOutputFrequency.0&upsOutputFrequency.0:
$router_connect / 10
bb*host[$target_name]: $router_name
bb*svc[$target_name]: freq
bb*red[$target_name]: $freqlow:$freqhigh
bb*yellow[$target_name]: $freqyel:$freqyeh
routers.cgi*Options[$target_name]: nototal
Directory[$target_name]: $directory_name
MaxBytes[$target_name]: $freq
AbsMax[$target_name]: $freqmax
RouterUptime[$target_name]: $router_connect
Options[$target_name]: Gauge noi
Title[$target_name]: UPS Frequency
YLegend[$target_name]: Hertz
ShortLegend[$target_name]: Hz
LegendI[$target_name]: Frequency

PageTop[$target_name]: <H1>UPS Output Frequency</H1>
 <TABLE>
   <TR><TD>System:</TD><TD>$sysname  </TD></TR>
   <TR><TD>Location:</TD><TD>$syslocation </TD></TR>
 </TABLE>
FREQ
;
$target_name=$router_name.".source";
$target_lines .= <<SOURCE
#.....................................................................
Target[$target_name]: upsOutputSource.0&upsOutputSource.0:
$router_connect
bb*host[$target_name]: $router_name
bb*svc[$target_name]: source
bb*red[$target_name]: 2:4
routers.cgi*Options[$target_name]: nototal
Directory[$target_name]: $directory_name
MaxBytes[$target_name]: 7
AbsMax[$target_name]:  10
RouterUptime[$target_name]: $router_connect
Options[$target_name]: Gauge noi
Title[$target_name]: Output Source
YLegend[$target_name]: Source
ShortLegend[$target_name]: Source
LegendI[$target_name]: Source

PageTop[$target_name]: <H1>UPS Output Source</H1>
 <TABLE>
        <tr><td>1</td><td>Other</td>
        <tr><td>2</td><td>None</td>
        <tr><td>3</td><td>Normal</td>
        <tr><td>4</td><td>Bypass</td>
        <tr><td>5</td><td>Battery</td>
        <tr><td>6</td><td>Booster</td>
        <tr><td>7</td><td>Reducer</td>
 </TABLE>
SOURCE
;




-- 
Daniel J McDonald, CCIE #2495, CISSP #78281, CNX
Austin Energy
http://www.austinenergy.com



More information about the mrtg mailing list