Talk:Snmp+Mrtg monitoring
From Ubiquiti Wiki
Contents |
Snmp+Mrtg monitoring
Introduction
Often, as network administrator, you have to know how your network worked few hours ago or last night. Generally you need a network monitor.
AirOS has implemented SNMP Agent feature which we could use for network monitoring. Now we need a monitoring software that could use SNMP Agent implemented in our UBNT device for data collecting, tool which do that is Tobi Oetiker's MRTG. So if you want build simple monitoring system for your wireless network in 15 minutes you should read this Tutorial.
Start
What we need:
1.Wireless device(s) with SNMP agent (This tutorial was released on WISP Station 5)
2.Network Monitor, a machine which will do MRTG for data collecting, and have any web server installed for result presentation.
Preparing AirOS device
Open your web browser and type in ip address of your AirOS device as you normally do it for changing configuration. After you have successfully logged in, go to SERVICES Tab. You will see services available for your UBNT device. All of them are disabled by default. Find SNMP Agent section and activate “Enable SNMP Agent” Box. Three options bellow will activate. Community – is a kind of password which is used to log into SNMP device, keep it in secret. Contact and Location are used only for your information and have not impact for data collecting. I entered test data as shown on image bellow.
WARINING: If host which you use for monitoring is in the different logical network you will need to Setup “Network” parameters correctly. Generally, computer which runs MRTG have to “ping” AirOS device, without it monitoring via SNMP will not work correctly.
After setting up SNMP Agent Save configuration - AirOS device is ready. If you need a better explanation SNMP agent is widely described in AirOS User Manual.
Preparing a Network Monitor
In this tutorial Linux Debian based machine will be used, but you could use any other operating system supported by MRTG (Perl). First of all let's check connectivity with AirOS device. Simply use a ping command:
root@test:~# ping 192.168.1.20
You should use an ip address of your device of course. If result is OK, next we will check SNMP Agent. Type in:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20
As a result should get quite large text 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 ...
But if you get:
Timeout: No Response from 192.168.1.20
You should check snmp community and/or ip address on both devices AirOS and Linux.
If everything is OK let's find any interfaces used by our wireless device device:
root@test:~# snmpwalk -v1 -c ubnt2 192.168.1.20 ifDescr
and you should get 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 next two could be different. Interface numbers look like this after 'hard reboot' of device. If you change any parameters of AirOS device, generally wireless network parameters, interface number could change. Always after 'hard reboot' interface numbers come back to it's lower values as shown at the example. You could check it by changing a “Wireless Mode” option from “Link Setup” tab then you got sample result:
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
Why it is important ? It's important because SNMP collect data by interface number not by it's name. Simple and (I think :-) ) not very shame walk around of this problem is to do hard reset after you finish configuring device, generally You rather not reconfigure your AP few times a day. 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 got similar results as shown above go to next point, if you have any error check for misspelled characters.
Setting up MRTG
You could install MRTG in many ways, I do it in easiest way - from default Debian binary:
root@test:~# apt-get install mrtg
If you want to install MRTG in another way should go to it's homepage.
After successful installation edit configuration file via your editor:
root@test:~# vi /etc/mrtg.cfg
Warning: Location of mrtg.cfg file is dependent your installation! Locate file by yourself! 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 statistic 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 could analyze your network traffic all the time!
Note: Last picture is a bit different because it was generated by mrtg but with rrd tool support.
Arbooz



