March 21, 2009, 8:31 p.m.
posted by whitehat
Manually Configuring Your MRTG FileThe MRTG cfgmaker program creates configuration files for network interfaces only, simultaneously tracking two OIDs: the NIC's input and output data statistics. The mrtg program then uses these configuration files to determine the type of data to record in its data directory. The indexmaker program also uses this information to create the overview, or Summary View Web page for the MIB OIDs you're monitoring. This Summary View page shows daily statistics only. You have to click on the Summary View graphs to get the Detailed View page behind it with the daily, weekly, monthly, and annual graphs. Some of the parameters in the configuration file refer to the Detailed View, others refer to the Summary View. If you want to monitor any other pairs of OIDs, you have to manually create the configuration files, because cfgmaker isn't aware of any OIDs other than those related to a NIC. The mrtg and indexmaker program can be fed individual OIDs from a customized configuration file and will function as expected if you edit the file correctly. Parameter FormatsMRTG configuration parameters are always followed by a graph name surrounded by square brackets and a colon. The format looks like this:
Parameter[graph name]: value
For ease of editing, the parameters for a particular graph are usually grouped together. Each graph can track two OIDS listed in the Target parameter, which is usually placed at the very top of the graph name list. The two OID values are separated by an & symbol; the first one is the input OID, and the second one is the output OID. Legend ParametersOn the Detailed View Web page, each graph has a legend that shows the max, average, and current values of the graph's OID statistics. You can use the legendI parameter for the description of the input graph (first graph OID) and the legendO for the output graph (second graph OID). The space available under each graph's legend is tiny so MRTG also has legend1 and legend2 parameters that are placed at the very bottom of the page to provide more details. Parameter legend1 is the expansion of legendI, and legend2 is the expansion of legendO. The Ylegend is the legend for the Y axis, the value you are trying to compare. In the case of a default MRTG configuration this would be the data flow through the interface in bits or bytes per second. Here is an example of the legends of a default MRTG configuration:
YLegend[graph1]: Bits per second
Legend1[graph1]: Incoming Traffic in Bits per Second
Legend2[graph1]: Outgoing Traffic in Bits per Second
LegendI[graph1]: In
LegendO[graph1]: Out
You can prevent MRTG from printing the legend at the bottom of the graph by leaving the value of the legend blank like this:
LegendI[graph1]:
Later you'll learn how to match the legends to the OIDs for a variety of situations. Options ParametersOptions parameters provide MRTG with graph formatting information. The growright option makes sure the data at the right of the screen is for the most current graph values. This usually makes the graphs more intuitively easy to read. MRTG defaults to growing from the left. The nopercent option prevents MRTG from printing percentage style statistics in the legends at the bottom of the graph. The gauge option alerts MRTG to the fact that the graphed values are of the gauge type. If the value you are monitoring is in bytes, then you can convert the output to bits using the bits option. Likewise, you can convert per second values to per minute graphs using the perminute option. Here are some examples for two different graphs:
options[graph1]: growright,nopercent,perminute
options[graph2]: gauge,bits
If you place this parameter at the top with a label of [_] it gets applied to all the graphs defined in the file:
options[_]: growright
Title ParametersThe title on the Summary Page is provided by the Title parameter, the PageTop parameter tells the title for the Detailed View page. The PageTop string must start with <H1> and end with </H1>.
Title[graph1]: Interface eth0
PageTop[graph1]: <H1>Detailed Statistics For Interface eth0</H1>
Scaling ParametersThe MaxBytes parameter is the maximum amount of data MRTG will plot on a graph. Anything more than this seems to disappear over the edge of the graph. MRTG also tries to adjust its graphs so that the largest value plotted on the graph is always close to the top. This is so even if you set the MaxBytes parameter. When you are plotting a value that has a known maximum and you always want to have this value at the top of the vertical legend, you may want to turn off MRTG's auto scaling. If you are plotting percentage CPU usage, and the server reaches a maximum of 60%, with scaling, MRTG will have a vertical plot of 0% to 60%, so that the vertical peak is near the top of the graph image. When scaling is off, and MaxBytes is set to 100, then the peak will be only 60% of the way up as the graph plots from 0% to 100%. The example removes scaling from the yearly, monthly, weekly, and daily views on the Detailed View page and gives them a maximum value of 100:
Unscaled[graph1]: ymwd
MaxBytes[graph1]: 100
Defining The MIB Target ParametersAs stated before, MRTG always tries to compare two MIB OID values that are defined by the Target parameter. You have to specify the two MIB OID objectsthe SNMP password and the IP address of the device you are querying in this parameterand separate them with an & character:
Target[graph1]: mib-object-1.0&mib-object-2.0:<SNMP-password>@<IP-address>
The numeric value, in this case .0, at the end of the MIB is required. The next example uses the SNMP command to return the user mode CPU utilization of a Linux server. Notice how the .0 is tagged onto the end of the output.
[root@silent mibs]# snmpwalk -v 1 -c craz33guy localhost ssCpuRawUser
UCD-SNMP-MIB::ssCpuRawUser.0 = Counter32: 926739
[root@silent mibs]#
The MRTG legends map to the MIBs listed in the target as shown in Figure.
So in the example below, legend1 and legendI describe mib-object-1.0, and legend2 and legendO describe mib-object-2.0.
Target[graph1]: mib-object-1.0&mib-object-2.0:<SNMP-password>@<IP-
address>
Plotting Only One MIB ValueIf you want to plot only one MIB value, you can just repeat the target MIB in the definition as in the next example, which plots only mib-object-1. The resulting MRTG graph actually superimposes the input and output graphs one on top of the other.
Target[graph1]: mib-object-1.0&mib-object-1.0:<SNMP-password>@<IP-
address>
Adding MIB Values Together for a GraphYou can use the plus sign between the pairs of MIB object values to add them together. The next example adds mib-object-1.0 and mib-object-3.0 for one graph and adds mib-object-2.0 and mib-object-4.0 for the other.
Target[graph1]: mib-object-1.0&mib-object-2.0:<SNMP-password>@<IP-
address> + mib-object-3.0&mib-object-4.0:<SNMP-password>@<IP-address>
You can use other mathematical operators, such as subtract (-), multiply (*), and divide (%). Left and right parentheses are also valid. There must be white spaces before and after all these operators for MRTG to work correctly. If not, you'll get oddly shaded graphs. Sample Target: Total CPU UsageLinux CPU usage is occupied by system processes, user mode processes, and a few processes running in nice mode. This example adds them all together in a single plot:
Target[graph1]:ssCpuRawUser.0&ssCpuRawUser.0:<SNMP-password>@<IP-
address> + ssCpuRawSystem.0&ssCpuRawSystem.0:<SNMP-password>@<IP-
address> + ssCpuRawNice.0&ssCpuRawNice.0:<SNMP-password>@<IP-address>
Be sure to place this command on a single line. Sample Target: Memory UsageHere is an example for plotting the amount of free memory versus the total RAM installed in the server. Notice that this is a gauge type variable:
Target[graph1]: memAvailReal.0&memTotalReal.0:<SNMP-password>@<IP-
address>
options[graph1]: nopercent,growright,gauge
Next, plot the percentage of available memory. Notice how the mandatory white spaces separate the mathematical operators from the next target element.
Target[graph1]: ( memAvailReal.0& memAvailReal.0:<SNMP-password>@<IP-
Address> ) * 100 / ( memTotalReal.0&memTotalReal.0:<SNMP-
password>@<IP-Address> )
options[graph1]: nopercent,growright,gauge
Sample Target: Newly Created ConnectionsHTTP traffic caused by Web browsing usually consists of many very shortlived connections. The tcpPassiveOpens MIB object tracks newly created connections and is suited for this type of data transfer. The tcpActiveOpens MIB object monitors new connections originating from the server. On smaller Web sites you may want to use the perminute option to make the graphs more meaningful:
Target[graph1]: tcpPassiveOpens.0& tcpPassiveOpens.0:<SNMP-
password>@<IP-address>
MaxBytes[graph1]: 1000000
Options[graph1]: perminute
Sample Target: Total TCP Established ConnectionsOther protocols, such as FTP and SSH, create longer established connections while people download large files or stay logged into the server. The tcpCurrEstab MIB object measures the total number of connections in the established state and is a gauge value:
Target[graph1]: tcpCurrEstab.0&tcpCurrEstab.0:<SNMP-password>@<IP-
address>
MaxBytes[graph1]: 1000000
Options[graph1]: gauge
Sample Target: Disk Partition UsageIn this example, you'll monitor the /var and /home disk partitions on the system: Defining Global VariablesYou have to make sure MRTG knows where the MIBs you're using are located. The default location MRTG uses may not be valid. Specify their locations with the global LoadMIBs parameter. You must also define where the HTML files will be located; the example specifies the default Fedora MRTG HTML directory:
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt,
/usr/share/snmp/mibs/TCP-MIB.txt
workdir: /var/www/mrtg/
|
- Comment