SNMP and MRTG Monitoring
From Ubiquiti Wiki
Contents |
SNMP and MRTG Monitoring
Introduction
Often, as a network administrator, you'd like to know how well your network performed over the past few hours, or days. This is where a monitor is useful.
AirOS has implemented the SNMP protocol which we can use for network monitoring. In order to read this data, you must use software that can poll the SNMP server running on your AirOS device. A popular tool which do that is Tobi Oetiker's MRTG. So read on in this tutorial to build simple, yet effective monitoring graphs for you network in about 15 minutes of work.
Start
What you will need:
1. Wireless device(s) with SNMP Agent (WispStation5 was used for this tutorial, although any device supporting SNMP will work)
2. The MRTG files, a machine which will run MRTG for collecting data, and a web server installed for showing the results (apache, lighttpd, nginx, etc.).
Preparing your AirOS device
Open your web browser and go to your device's configuration page. After you have logged in, goto the Services tab. Find the SNMP Agent section and check the “Enable SNMP Agent” Box. The three option boxes will become editable. Community – is a kind of password which is used to log into the SNMP device, keep this secret! Contact and Location are used only for your information and have no impact on the data collected. I entered some test values as shown on the image below.
WARNING: If your host you are using for network monitoring (the machine running MRTG) is on a different network than the AirOS device, you will need to setup your network settings accordingly. Generally the machine running MRTG must be able to “ping” the AirOS device in question, if you can't ping the device, chances are SNMP will not work correctly.
After setting the SNMP Agent settings, save the configuration. Your AirOS device is ready! If you need a better explanation, the SNMP Agent is thoroughly described in the AirOS User Manual.
Preparing MRTG
In this tutorial a "Debian" linux based machine will be used, but you may use any other operating system that supports MRTG (MRTG runs on the Perl coding langauge).
First of all let's check for connectivity to the AirOS device. A simple ping will suffice:
root@test:~# ping 192.168.1.20
You should of course use the IP address of your device if that is not the IP you are using.
If you receive replies, then hit Ctrl+C to stop the ping and now we will check for an SNMP connection.
In the terminal:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20
As a result you shold get quite a large amount of output which will look like this:
... IF-MIB::ifSpecific.5 = OID: SNMPv2-SMI::zeroDotZero SNMPv2-MIB::snmpInPkts.0 = Counter32: 484 SNMPv2-MIB::snmpOutPkts.0 = Counter32: 471 SNMPv2-MIB::snmpInBadVersions.0 = Counter32: 0 SNMPv2-MIB::snmpInBadCommunityNames.0 = Counter32: 12 SNMPv2-MIB::snmpInBadCommunityUses.0 = Counter32: 0 SNMPv2-MIB::snmpInASNParseErrs.0 = Counter32: 0 SNMPv2-MIB::snmpInTooBigs.0 = Counter32: 0 SNMPv2-MIB::snmpInNoSuchNames.0 = Counter32: 0 SNMPv2-MIB::snmpInBadValues.0 = Counter32: 0 SNMPv2-MIB::snmpInReadOnlys.0 = Counter32: 0 SNMPv2-MIB::snmpInGenErrs.0 = Counter32: 0 SNMPv2-MIB::snmpInTotalReqVars.0 = Counter32: 0 SNMPv2-MIB::snmpInTotalSetVars.0 = Counter32: 0 SNMPv2-MIB::snmpInGetRequests.0 = Counter32: 0 SNMPv2-MIB::snmpInGetNexts.0 = Counter32: 484 SNMPv2-MIB::snmpInSetRequests.0 = Counter32: 0 SNMPv2-MIB::snmpInGetResponses.0 = Counter32: 0 SNMPv2-MIB::snmpInTraps.0 = Counter32: 0 SNMPv2-MIB::snmpOutTooBigs.0 = Counter32: 0 SNMPv2-MIB::snmpOutNoSuchNames.0 = Counter32: 0 SNMPv2-MIB::snmpOutBadValues.0 = Counter32: 0 SNMPv2-MIB::snmpOutGenErrs.0 = Counter32: 0 SNMPv2-MIB::snmpOutGetRequests.0 = Counter32: 0 SNMPv2-MIB::snmpOutGetNexts.0 = Counter32: 0 ...
If you get the reply:
Timeout: No Response from 192.168.1.20
You should check your SNMP Community and/or the IP address of the AirOS device.
If everything is OK let's find all the interfaces used by our device:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 ifDescr
or
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 .1.3.6.1.2.1.2.2.1.2
You should get a result like this:
IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: eth0 IF-MIB::ifDescr.3 = STRING: wifi0 IF-MIB::ifDescr.4 = STRING: ath0 IF-MIB::ifDescr.5 = STRING: br0
First three lines should be identical, but the next two could be different. Interface numbers look like this after a 'hard reboot' of your device. If you change any parameters of the AirOS device - generally wireless network parameters - the interface numbers could change. Always after a 'hard reboot' interface numbers come back to their default values as shown in the example. You could check it by changing the “Wireless Mode” option in the “Link Setup” tab, then check your results:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 ifDescr IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: eth0 IF-MIB::ifDescr.3 = STRING: wifi0 IF-MIB::ifDescr.12 = STRING: ath0 IF-MIB::ifDescr.13 = STRING: br0
Please note, interface names may differ in different equipment. UBNT M series products will have the following interfaces while operating in bridge mode (once again, the interface number could change after each reboot):
IF-MIB::ifDescr.1 = STRING: lo IF-MIB::ifDescr.2 = STRING: gre0 IF-MIB::ifDescr.3 = STRING: eth0_real IF-MIB::ifDescr.4 = STRING: eth1_real IF-MIB::ifDescr.5 = STRING: wifi0 IF-MIB::ifDescr.6 = STRING: br0 IF-MIB::ifDescr.7 = STRING: ath0
Why is it important? It's important because SNMP collects data by interface number, not by it's name.
So if numbering of interfaces is clear, let's check how many octet's (bytes) our AirOS device transmitted since last reboot:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 ifinOctets IF-MIB::ifInOctets.1 = Counter32: 0 IF-MIB::ifInOctets.2 = Counter32: 186740992 IF-MIB::ifInOctets.3 = Counter32: 4117381100 IF-MIB::ifInOctets.4 = Counter32: 3824919421 IF-MIB::ifInOctets.5 = Counter32: 569163 root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 ifoutOctets IF-MIB::ifOutOctets.1 = Counter32: 0 IF-MIB::ifOutOctets.2 = Counter32: 3824764209 IF-MIB::ifOutOctets.3 = Counter32: 305295003 IF-MIB::ifOutOctets.4 = Counter32: 168468497 IF-MIB::ifOutOctets.5 = Counter32: 172865
If you get similar results as shown above, go to the next point, if you receive an error, check for typos.
Readable labels (like "ifoutOctets") or numeric SNMP object identifiers can be used for gathering data on particular device or particular interface.
After finding the index of wireless interface (ath0):
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 ifDescr | grep ath0 | head -c 17 | tail -c 1
We can use this index (let's say we got the result "7" from the command above) for further requests.
Signal level of 7th interface (ath0) of the device:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 1.3.6.1.4.1.14988.1.1.1.1.1.4.7
TxRate of 7'th interface (ath0) of the device (bps):
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 1.3.6.1.4.1.14988.1.1.1.1.1.2.7
RxRate of 7'th interface (ath0) of the device (bps):
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 1.3.6.1.4.1.14988.1.1.1.1.1.3.7
Channel of 7'th interface (ath0) of the device:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 1.3.6.1.4.1.14988.1.1.1.1.1.7.7
There's large number of other useful OIDs which can be pulled in the same manner, like:
Firmware Version: 1.2.840.10036.3.1.2.1.4 Hostname: 1.3.6.1.4.1.14988.1.1.1.1.1.5 AP MAC: 1.3.6.1.4.1.14988.1.1.1.1.1.6 Station MAC: 1.2.840.10036.1.1.1.1
All the supported OIDs are described in the MIB files.
Setting up MRTG
You could install MRTG in many ways, I did it the easiest way - from the Debian binary package manager:
root@test:~# apt-get install mrtg
If You want to install MRTG in another way should go to it's homepage.
After installation, edit the configuration file via your editor:
root@test:~# vi /etc/mrtg.cfg
Warning:
Location of mrtg.cfg file is dependent on your installation! Locate the file easily by typing the following:
find /etc/ | grep -i mrtg.cfg
You will get a result returned that may look something like:
/etc/mrtg/mrtg.cfg
In that case you would do
root@test:~# vi /etc/mrtg/mrtg.cfg
At the end of your mrtg.cfg file add:
Title[test1_ath0]: Wisp Station 5 PageTop[test1_ath0]: Wisp Station 5 Radio MRTG TEST Target[test1_ath0]: ifInOctets.4&ifOutOctets.4:ubnt@192.168.1.21 MaxBytes[test1_ath0]: 10000000
This will monitor a data flow over wireless interface of your WISP Station, You could also add wired interface eth0:
Title[test1_eth0]: Wisp Station 5 PageTop[test1_eth0]: Wisp Station 5 Radio MRTG TEST Target[test1_eth0]: ifInOctets.2&ifOutOctets.2:ubnt@192.168.1.21 MaxBytes[test1_eth0]: 10000000
MRTG gets ifInOctets and ifOutOctets values for given interface automatically every 5 minutes (by default) then computes a data flow over given time period and draws graph like this:
You could see statistics page by typing ip of your network monitor in web browser:
http://127.0.0.1/mrtg/test1_ath0.html
You should get result like this:
Long time graphs look's much better:
Now you can analyse your network traffic in real-time, any time!
Note: Last picture is a bit different because it was generated by MRTG but with RRDTool support.
SNMP MIBS
The following MIBS are supported by AirOS (SNMP v1):



