# Setup MRTG?

## Legshot

Hi everyone.

I've emerge mrtg and now I'm stuck setting it up. What's the best way to start it? How to I configure it?

I can't even find out what an "SNMP manageable device" is. 

All I want is to be able to monitor the traffic of a nic.

Tia!

----------

## acidreign

SNMP stands for Simple Network Managable Device.  Most routers or intelligent devices allow for SNMP probes to retrieve/set information.

MRTG can query this information, and draw graphs accordingly.  You can get a SNMP server for linux (gentoo in this case) and MRTG can query your gentoo machine for all of its needs.

Hopefully, this helps.

http://www.linuxsecurity.com/feature_stories/dsniff/bandwidthusage.html

----------

## pjp

I thought the 'MP' stood for Management Protocol.

----------

## psp

SNMP = Simple Management Network Protocol.

Is the interface you want to monitor local to the machine or remote? If it is remote and you want to use MRTG you will need to install an SNMP daemon on the remote host. You then configure MRTG to query this host and pull stats from the SNMP daemon. If the interface is local, then there are a couple more lightweight solutions, like iptables and rrdtool.

Hope this helps...

----------

## kashani

finally got most of my machines back on the network so I could do a litle real life testing before posting. 

1. SNMP explained

Simple Network Management Protocol hereafter refered to as snmp is way to poll devices for information. You can also configure devices via snmp, but that's a security hassle so we're going to pretend it doesn't exist. 

A snmp enabled device will have some sort of snmp process running that will respond back with interesting information assuming you ask the correct way. The correct involves the right community string and the correct MIB resource. 

snmp can tell you just about anything about your machine, but you really don't care about 99% of it. So you'll need to query specific things which we'll get to. 

2. Setting up snmp

emerge net-snmp

try to start the daemon /etc/init.d/net-snmp start

It'll kick out some error. Follow the instructions for finding the example snmpd.conf. Following the instructions in the snmp.conf, but you can ignore  anything after setting up access and picking your community strings.

3. How to find cool things in your MIB

     a. google for MIB linux 2.4.x snmp OID ram|cpu|pages|etc

     b. Read the mrtg mail archives

     c. snmpwalk or a nice windows tool called getif

snmpwalk will kick out all 696 possible bit of SNMP querianle data. Use a command line like this:

snmpwalk -v 1 -c <community> localhost 

You'll see something looking like:

filer-01 root # snmpwalk -v 1 -c webfootrw localhost

SNMPv2-MIB::sysDescr.0 = STRING: Linux filer-01.int 2.4.19-gentoo-r7 #4 Tue Jul 16 15:49:25 CDT 2002 i686

SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10

SNMPv2-MIB::sysUpTime.0 = Timeticks: (4731) 0:00:47.31

SNMPv2-MIB::sysContact.0 = STRING: Admin <admin@bob.com>

SNMPv2-MIB::sysName.0 = STRING: filer-01.int

SNMPv2-MIB::sysLocation.0 = STRING: Server room.

SNMPv2-MIB::sysORLastChange.0 = Timeticks: (5) 0:00:00.05

SNMPv2-MIB::sysORID.1 = OID: IF-MIB::ifMIB

SNMPv2-MIB::sysORID.2 = OID: SNMPv2-MIB::snmpMIB

SNMPv2-MIB::sysORID.3 = OID: TCP-MIB::tcpMIB

SNMPv2-MIB::sysORID.4 = OID: IP-MIB::ip

SNMPv2-MIB::sysORID.5 = OID: UDP-MIB::udpMIB

SNMPv2-MIB::sysORID.6 = OID: SNMP-VIEW-BASED-ACM-MIB::vacmBasicGroup

SNMPv2-MIB::sysORID.7 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance

4. MRTG

Being an old school MRTG guy I tend to refer to mrtg as the combined elements of mrtg and rrdtool. Their seperate processes and we'll need both and I'll generally refer to them collectively as MRTG, deal.  :Smile: 

emerge mrtg

emerge rrdtool

5. More MRTG explaination

MRTG will query your snmp enable device and ask for certain bits of data. It will then create graphs based on this. If you dump them into a dir apache can see, you'll be able to see them. You'll have to do some HTML work to get things looking well. 

Really the best how to on this part is on the mrtg and rredtool's author's site. It's really straight forward.

6. other things

    a. Use rrdtool rather then MRTG's data collection

    b. Run MRTG as a daemon instead of a cron

why do I get the idea I just volunteered myself for the Gentoo snmp and mrtg how to?  :Sad: 

kashani

----------

## mglauche

 :Wink:  better yet .. volunteer for a rdrtool howto  :Razz: 

I think mrtg is quite easy to set up, but never managed to get the rdrtool working .. (although i must admit, i didn't try hard  :Razz: )

some more fun examples to do with mrtg:

mysql query/sec:

```

Target[mysql]: `/etc/mrtg/mysql.sh`

MaxBytes[mysql]:100000000

Title[mysql]: Average queries per second

Options[mysql]: growright, nopercent

PageTop[mysql]: Average queries per second

YLegend[mysql]: q/s

LegendI[mysql]: Queries q/s:

LegendO[mysql]: Queries q/s:

XSize[mysql]: 600

YSize[mysql]: 200

ShortLegend[mysql]: q/s

```

```
 

cat /etc/mrtg/mysql.sh

#!/bin/sh

mysqladmin status | awk -F " " '{print $6}' | sed 's/\.//' | sed 's/ //'

mysqladmin status | awk -F " " '{print $6}' | sed 's/\.//' | sed 's/ //'

```

(it must be duplicate, mrtg expects 2 values)

but you get the idea .. you can feed any script providing 2 growing values (webserver hits, mail traffic, nimda hits, etc, etc) into mrtg very easily  :Wink: 

----------

## Legshot

Great! It works now  :Very Happy: 

Thanks a lot everyone and especially you kashani for your tutorial  :Wink: 

----------

## neutcomp

Hello I am trying to get the mysql stats.

But I am using a password so:

```
mysqladmin -u root -p ****** status | awk -F " " '{print $6}' | sed 's/\.//' | sed 's/ //'
```

But when I then run 

```
/etc/cron.mrtg/mysql.sh
```

It keeps asking me my password. How can I change this?

Thanxx

Bjorn   :Cool: 

----------

## kashani

Remove the space between -p and your password.

kashani

----------

## neutcomp

 *kashani wrote:*   

> Remove the space between -p and your password.
> 
> kashani

 

It works great thanxx!!

But now If I want him to add like this

```

/usr/bin/indexmaker --output=/wwwroot/stats.nl/index.html --title="Power Under Control :)" --sort=name --enumerate /etc/mrtg/traffic.cfg /etc/mrtg/cpu.cfg /etc/mrtg/mem.cfg /etc/mrtg/swap.cfg /etc/mrtg/ping.cfg /etc/mrtg/mysql.cfg

```

I get

```
ERROR: no H1 line pagetop property in mysql section

```

Bjorn   :Cool: 

----------

## mglauche

can you post your full mysql section of the mrtg.conf ?

----------

## neutcomp

Hello,

```
find / -name mrtg.conf

```

Result is nothing   :Shocked: 

cat /etc/mrtg/mysql.cfg

```
Target[mysql]: /etc/mrtg/mysql.sh

MaxBytes[mysql]:100000000

Title[mysql]: Average queries per second

Options[mysql]: growright, nopercent

PageTop[mysql]: Average queries per second

YLegend[mysql]: q/s

LegendI[mysql]: Queries q/s:

LegendO[mysql]: Queries q/s:

XSize[mysql]: 600

YSize[mysql]: 200

ShortLegend[mysql]: q/s
```

cat /etc/cron.mrtg/mysql.sh

```
#!/bin/sh

mysqladmin -u root -p******* status | awk -F " " '{print $6}' | sed 's/\.//' | sed 's/ //'

mysqladmin -u root -p******* status | awk -F " " '{print $6}' | sed 's/\.//' | sed 's/ //'
```

Thanxx

Bjorn   :Cool: 

----------

