# SNMP & MRTG made in easy (Power Under Control ;)

## khazad-dum

Object required:

* [net-analyzer/net-snmp]

* [media-libs/libgd]

* [net-analyzer/mrtg]

* [sys-apps/dcron]

Optionally:

* [net-www/mini_httpd] or [net-www/apache]

WARNING: Do not Cut&Paste commands that begin with:

```

/bin/cat -s > /foo/bar

```

Example: http://www.orson.it/stat

0) Switch User

```

/bin/su -

```

Enter Password

1) Begin

```

/usr/bin/mkdir /etc/mrtg

/usr/bin/mkdir /etc/cron.mrtg

/usr/bin/mkdir /var/www/localhost/mrtg

```

2) Edit

```

/bin/cat -s > /etc/snmp/snmpd.conf

com2sec local     127.0.0.1/32    public

com2sec local     10.10.10.0/24   public

group MyROGroup v1         local

group MyROGroup v2c        local

group MyROGroup usm        local

view all    included  .1                               80

access MyROGroup ""      any       noauth    exact  all    none   none

syslocation MyLocation

syscontact Me <me@somewhere.org>

```

Now just press [ctrl+d].

Edit /etc/conf.d/snmpd file, and add:

```

-c /etc/snmp/snmpd.conf

```

in SNMPD_FLAGS line 

(like this: SNMPD_FLAGS="-c /etc/snmp/snmpd.conf")

3) Daemon

```

/etc/init.d/snmpd start

/sbin/rc-update add snmpd default

```

4) Configuration

Traffic:

```

/usr/bin/cfgmaker  \

--output=/etc/mrtg/traffic.cfg \

--ifdesc=ip \

--ifref=descr \

--global "WorkDir: /var/www/localhost/mrtg" \

--global "Options[_]: bits,growright" \

public@localhost

```

Cpu:

```

/bin/cat -s > /etc/mrtg/cpu.cfg

WorkDir: /var/www/localhost/mrtg

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.

0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost

RouterUptime[localhost.cpu]: public@localhost

MaxBytes[localhost.cpu]: 100

Title[localhost.cpu]: CPU Load

PageTop[localhost.cpu]: <H1>Active CPU Load %</H1>

Unscaled[localhost.cpu]: ymwd

ShortLegend[localhost.cpu]: %

YLegend[localhost.cpu]: CPU Utilization

Legend1[localhost.cpu]: Active CPU in % (Load)

Legend2[localhost.cpu]:

Legend3[localhost.cpu]:

Legend4[localhost.cpu]:

LegendI[localhost.cpu]:  Active

LegendO[localhost.cpu]:

Options[localhost.cpu]: growright,nopercent

```

Now just press [ctrl+d].

Mem:

```

/bin/cat -s > /etc/mrtg/mem.cfg

LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt

Target[localhost.mem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:public@localhost

PageTop[localhost.mem]: <H1>Free Memory </H1>

WorkDir: /var/www/localhost/mrtg

Options[localhost.mem]: nopercent,growright,gauge,noinfo 

Title[localhost.mem]: Free Memory 

MaxBytes[localhost.mem]: 1000000 

kMG[localhost.mem]: k,M,G,T,P,X 

YLegend[localhost.mem]: bytes 

ShortLegend[localhost.mem]: bytes 

LegendI[localhost.mem]:  Free Memory: 

LegendO[localhost.mem]: 

Legend1[localhost.mem]: Free memory, not including swap, in bytes

```

Now just press [ctrl+d].

Swap:

```

/bin/cat -s > /etc/mrtg/swap.cfg

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost.swap]: memAvailSwap.0&memAvailSwap.0:public@localhost

PageTop[localhost.swap]: <H1>Swap Memory</H1>

WorkDir: /var/www/localhost/mrtg

Options[localhost.swap]: nopercent,growright,gauge,noinfo 

Title[localhost.swap]: Free Memory 

MaxBytes[localhost.swap]: 1000000 

kMG[localhost.swap]: k,M,G,T,P,X 

YLegend[localhost.swap]: bytes 

ShortLegend[localhost.swap]: bytes 

LegendI[localhost.swap]:  Free Memory: 

LegendO[localhost.swap]: 

Legend1[localhost.swap]: Swap memory avail, in bytes

```

Now just press [ctrl+d].

Ping:

```

/bin/cat -s > /etc/mrtg/ping.cfg

WorkDir: /var/www/localhost/mrtg

Title[localhost.ping]: Round Trip Time

PageTop[localhost.ping]: <H1>Round Trip Time</H1>

Target[localhost.ping]: `/etc/mrtg/ping.sh`

MaxBytes[localhost.ping]: 2000

Options[localhost.ping]: growright,unknaszero,nopercent,gauge

LegendI[localhost.ping]: Pkt loss %

LegendO[localhost.ping]: Avg RTT

Legend1[localhost.ping]: Maximum Round Trip Time in ms

Legend2[localhost.ping]: Minimum Round Trip Time in ms

Legend3[localhost.ping]: Maximal 5 Minute Maximum Round Trip Time in ms

Legend4[localhost.ping]: Maximal 5 Minute Minimum Round Trip Time in ms

YLegend[localhost.ping]: RTT (ms)

```

Now just press [ctrl+d].

5) Make the jobs

Traffic:

```

/bin/cat -s > /etc/cron.mrtg/traffic.sh

#!/bin/sh

/usr/bin/mrtg /etc/mrtg/traffic.cfg

```

Now just press [ctrl+d].

Cpu:

```

/bin/cat -s > /etc/cron.mrtg/cpu.sh

#!/bin/sh

/usr/bin/mrtg /etc/mrtg/cpu.cfg

```

Now just press [ctrl+d].

Mem:

```

/bin/cat -s > /etc/cron.mrtg/mem.sh

#!/bin/sh

/usr/bin/mrtg /etc/mrtg/mem.cfg

```

Now just press [ctrl+d].

Swap:

```

/bin/cat -s > /etc/cron.mrtg/swap.sh

#!/bin/sh

/usr/bin/mrtg /etc/mrtg/swap.cfg

```

Now just press [ctrl+d].

Ping:

```

/bin/cat -s > /etc/cron.mrtg/ping.sh

#!/bin/sh

/usr/bin/mrtg /etc/mrtg/ping.cfg

```

ping.sh

```

/bin/cat -s > /etc/mrtg/ping.sh

#!/bin/sh

PING="/bin/ping"

# Google, for example

ADDR="google.com"

DATA=`$PING -c10 -s500 $ADDR -q `

LOSS=`echo $DATA | awk '{print $18 }' | tr -d %`

echo $LOSS

if [ $LOSS = 100 ];

then

               echo 0

else

        echo $DATA | awk -F/ '{print $5 }'

fi

```

Now just press [ctrl+d].

```

/bin/chmod +x /etc/cron.mrtg/*.sh

/bin/chmod +x /etc/mrtg/ping.sh

```

Run each script 3 times (don't care warnings)

```

/etc/cron.mrtg/traffic.sh

/etc/cron.mrtg/cpu.sh

/etc/cron.mrtg/mem.sh

/etc/cron.mrtg/swap.sh

/etc/cron.mrtg/ping.sh

```

6) Make the index

```

/usr/bin/indexmaker --output=/var/www/localhost/mrtg/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

```

7) Cronjob

```

/bin/cat >> /var/spool/cron/crontabs/root

*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null

```

Now just press [ctrl+d].

(or /usr/bin/crontab -e)

Power Under Control

Open Mozilla (I love it) and browse:

```

/var/www/localhost/www/index.html

```

(or use yours httpd server)

http://localhost/mrtg

# Advanced Users#

For other targets (and other stat), try with other object identifier (OID)

* Polling:

```

roberto@moira mrtg $ snmpwalk -v 1 -c public localhost mgmt.1.2.2.1.10.2

IF-MIB::ifInOctets.2 = Counter32: 140021440

```

* Translating: 

```

roberto@moria mrtg $ snmptranslate -IR -Td mgmt.1.2.2.1.10.2

IF-MIB::ifInOctets.2

ifInOctets OBJECT-TYPE

  -- FROM       IF-MIB, RFC1213-MIB

  SYNTAX        Counter32

  MAX-ACCESS    read-only

  STATUS        current

  DESCRIPTION   "The total number of octets received on the interface,

            including framing characters.

            Discontinuities in the value of this counter can occur at

            re-initialization of the management system, and at other

            times as indicated by the value of

            ifCounterDiscontinuityTime."

::= { iso(1) org(3) dod(6) internet(1) mgmt(2) mib-2(1) interfaces(2) ifTable(2) ifEntry(1) ifInOctets(

10) 2 }

```

* Most important files:

```

/usr/share/doc/net-snmp

/usr/share/doc/mrtg-*/contrib

- man mrtg

- man snmpd

- man snmpwalk

- man crontab

- man cat

```

Enjoy,

khazad-dumLast edited by khazad-dum on Mon Nov 17, 2003 12:04 am; edited 3 times in total

----------

## Krigare

Great guide! 

Thanks!

----------

## ckdake

Awesome help!  Got me partially up and running pretty quickly, however, I am using a 2.6 kernel and none of the memory stuff or network traffic stuff will work.  Is this just because mrtg/snmp doesnt like 2.6 or is there something I can do?

(in traffic.cfg, all my interfaces are commented out, eth 0 says: 

 *Quote:*   

> ### * it is operationally DOWN
> 
> ### * has a speed of 0 which makes no sense
> 
> 

 

i tried uncommenting it and changing the speed in the cfg file, but still nothing on the graph (which i also added to the index.html file by hand)

Figured i would post this here instead of somewhere else because other people running 2.6 are bound to run into this problem.

----------

## grover

Excellent guide. I've got it all working properly except for mem.cfg, it displays free RAM + free swap. To get it to display only free RAM you need to change this

```
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:public@localhost
```

to this

```
Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost 
```

----------

## zend

I want to get disk usage,memory usage,but can't get it .please help me !!

----------

## ckdake

Just an update on mine.. the network stuff just started working *shrug*  but the mem/swap stuff still is not working.  2.6 kernel issues is my guess..

----------

## khazad-dum

Disk usage:

```

/usr/bin/snmpwalk -v 1 -c public localhost | grep hrStorageDescr

```

Now, you have the map of your disk (for example: hrStorageDescr.1 is /, hrStorageDescr.2 is /home...etc etc)

After that, you can get the value of partitions:

```

/usr/bin/snmpwalk -v 1 -c public localhost hrStorageUsed.1

HOST-RESOURCES-MIB::hrStorageUsed.2 = INTEGER: 1640653

```

Mrtg's config file must have 2 value: hrStorageSize.1 and hrStorageUsed.1.

```

/bin/cat -s > /etc/mrtg/disk.cfg

LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt

WorkDir: /var/www/localhost/mrtg

Target[localhost.partition-name]:hrStorageSize.1&hrStorageUsed.1:public@localhost

MaxBytes[localhost.partition-name]: 3000000

Title[localhost.partition-name]: Disk / Usage

PageTop[localhost.partition-name]: <H1>Disk / Usage</H1>

ShortLegendlocalhost.partition-name[]: B

kMG[localhost.partition-name]: k,M,G,T,P

kilo[localhost.partition-name]: 1024

YLegend[localhost.partition-name]: DISK / Utilization

Legend1localhost.partition-name[]: Root disk size

Legend2[localhost.partition-name]: Root disk usage

Legend3[localhost.partition-name]:

Legend4[localhost.partition-name]:

LegendIlocalhost.partition-name]:  Root disk size

LegendO[localhost.partition-name]:  Root disk usage

Options[localhost.partition-name]: gauge,nopercent

```

Now just press [ctrl+d]

Memory usage was described in the first post.

khazad-dumLast edited by khazad-dum on Mon Nov 17, 2003 12:33 am; edited 1 time in total

----------

## RageX

beautiful guide man, mucho thanks!!!

----------

## innovatel

I have a problem

```

bash-2.05b# emerge sys-apps/dcron

Calculating dependencies ...done!

!!! Error: the virtual/cron package conflicts with another package.

!!!        both can't be installed on the same system together.

!!!        Please use 'emerge --pretend' to determine blockers.

bash-2.05b# emerge --pretend sys-apps/dcron

These are the packages that I would merge, in order:

Calculating dependencies ...done!

[blocks B     ] sys-apps/vcron ("virtual/cron" from pkg sys-apps/dcron-2.9)

[ebuild  N    ] sys-apps/dcron-2.9

bash-2.05b#

```

And now what can I do?   :Sad: 

Bye.

Andrea

----------

## khazad-dum

There are two ways: 

replace your cron's system (not suggested)

```

emerge -C vcron ; emerge dcron

```

or simply

```

crontab -e

```

and add

```

*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null

```

to add the scheduled jobs.

khazad-dumLast edited by khazad-dum on Tue Nov 18, 2003 3:43 pm; edited 1 time in total

----------

## innovatel

I try the second way but I recived another error

```

bash-2.05b# crontab -v

crontab: invalid option -- v

crontab: usage error: unrecognized option

usage:  crontab [-u user] file

        crontab [-u user] { -e | -l | -r }

                (default operation is replace, per 1003.2)

        -e      (edit user's crontab)

        -l      (list user's crontab)

        -r      (delete user's crontab)

```

----------

## khazad-dum

Sorry, I've mistaken.

the correct command is:

```

crontab -e

```

khazad-dum

----------

## frippz

I get this:

```

ERROR: Target[localhost.cpu][_IN_] ' $$target[0]{$mode}  + ssCpuRawSystem.0&ssCpuRawSystem.' (warn): Ambiguous use of & resolved as operator & at (eval 4) line 1.

ERROR: Target[localhost.cpu][_OUT_] ' $$target[0]{$mode}  + ssCpuRawSystem.0&ssCpuRawSystem.' (warn): Ambiguous use of & resolved as operator & at (eval 5) line 1.

WARNING: Skipping Update of localhost.cpu, inlast is not defined

WARNING: Skipping Update of localhost.cpu, outlast is not defined

```

Did I miss anything?

----------

## khazad-dum

I think the Cut&Paste have failed.

Target[localhost.cpu]:

```
ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost

```

a important thing is that the command is in one line only.

Check your "Target" line in the .cfg file.

khazad-dum

----------

## frippz

Aw, should've seen that one coming...  :Wink: 

Works great now. Thanks!

How should I go about getting some graphs showing the amount of traffic over a certain timespan? It would be nice to se how much data that flows to and from my server.  :Smile: 

----------

## nexxai

n/m, got it.

----------

## samegutt

 **Levi* wrote:*   

> I get this:
> 
> ```
> 
> ERROR: Target[localhost.cpu][_IN_] ' $$target[0]{$mode}  + ssCpuRawSystem.0&ssCpuRawSystem.' (warn): Ambiguous use of & resolved as operator & at (eval 4) line 1.
> ...

 

In your cpu.cfg file, just make sure you have 

```
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost
```

on one single line.

----------

## samegutt

Bummer, I'm perhaps a bit slow on my reload-button  :)

----------

## zend

cfgstoragemakerhttp://savannah.nongnu.org/projects/cfgstoragemk/

I've get it work in my debian box.so it will work in gentoo

----------

## lowbatt

I've got everything working but my traffic. It give no errors when i run the traffic script. Also I get 0 traffic png's . I have tried about 15 diffrent mrtg.cfg files. I have verified my snmp works .. ( or so I think it does ) 

I'm using kernel 2.4 does it need something special in the kernel to monitor traffic?

I can figgure out why I can't get a traffic report.  Any one have any idea's.

EDIT

After reading my post maybe I should say. I am unable to get the bandwidth graph. The ping is fine. I was messing with some things and kicked myself outta the box for now. since I'm at work I'll get you the snmp info asap.

----------

## khazad-dum

Please, give me the output of:

```

snmpwalk -v 1 -c public localhost | grep ifDescr

```

and try to:

```

ping www.google.com

```

Do you ping it?

----------

## lowbatt

ok here is the output 

```

[root@localhost]snmpwalk -v 1 -c public localhost | grep ifDescr

IF-MIB::ifDescr.1 = STRING: lo

IF-MIB::ifDescr.2 = STRING: eth0

HOST-RESOURCES-MIB::hrSWRunParameters.2635 = STRING: "ifDescr"

```

----------

## khazad-dum

FIXED

```

/bin/rm /etc/mrtg/traffic.cfg

/bin/cat -s > /etc/mrtg/traffic.cfg

WorkDir: /var/www/localhost/htdocs/mrtg

Options[_]: bits,growright

Target[localhost_eth0]: 2:public@localhost:

SetEnv[localhost_eth0]: MRTG_INT_IP="" MRTG_INT_DESCR="eth0"

MaxBytes[localhost_eth0]: 1250000

Title[localhost_eth0]: Title

PageTop[localhost_eth0]: <H1>PageTop</H1>

 <TABLE>

   <TR><TD>System:</TD>     <TD>System</TD></TR>

   <TR><TD>Maintainer:</TD> <TD>Maintainer</TD></TR>

   <TR><TD>Description:</TD><TD>eth0  </TD></TR>

   <TR><TD>ifType:</TD>     <TD>ethernetCsmacd (6)</TD></TR>

   <TR><TD>ifName:</TD>     <TD></TD></TR>

   <TR><TD>Max Speed:</TD>  <TD>xxx Mbits/s</TD></TR>

   <TR><TD>Ip:</TD>         <TD>Ip()</TD></TR>

 </TABLE>

```

Now just press [ctrl+d].

Try with this configuration. Give me feedback soon.

khazad-dumLast edited by khazad-dum on Fri Nov 21, 2003 2:13 pm; edited 1 time in total

----------

## zend

units in rrdtools and normal log is different!!

----------

## lowbatt

 *khazad-dum wrote:*   

> 
> 
> ```
> 
> /bin/rm /etc/mrtg/cpu.cfg
> ...

 

Ok this worked. Of course I named it traffic.cfg. Sine I figgured cpu.cfg was a typo. Thanks alot. Ill have to compart this to the above output to see what is so diffrent about it.

----------

## decker in flux

Loooking at the CPU output, i am curious if it is possible to set it up ( or rather how would i go about setting mrtg up ) for monitoring multiple CPUs?

So having out put for 

cpu0

cpu1

cpu2

cpu3

...

...

thanks

-d

----------

## khazad-dum

Sorry, but I've just one cpu and I can't try it...anyway, put this in your cpu1.cfg and match the results (cpu0 vs cpu1):

```

Target[localhost.cpu1]:ssCpuRawUser.1&ssCpuRawUser.1:public@localhost + ssCpuRawSystem.1&ssCpuRawSystem.1:public@localhost + ssCpuRawNice.1&ssCpuRawNice.1:public@localhost

```

and go on...

```

Target[localhost.cpuN]:ssCpuRawUser.N&ssCpuRawUser.N:public@localhost + ssCpuRawSystem.N&ssCpuRawSystem.N:public@localhost + ssCpuRawNice.N&ssCpuRawNice.N:public@localhost

```

Let me know (or give me the link)....I'm curious.

Remember:

https://forums.gentoo.org/viewtopic.php?p=657204#657204

khazad-dum

----------

## maomao

I had emerged net-snmp,but when I started snmpd,the system told me as follow:

```

root:/etc/init.d# ./snmpd start

* Starting net-snmpd...

/usr/sbin/snmpd: relocation error: /usr/sbin/snmpd: undefined symbol: smux_listen_sd                           [!!]

                                                                                                                                
```

who can tell me why?how to solve?

----------

## khazad-dum

It's strange...try to:

```

emerge sync

emerge -u system

```

And re-emerge snmpd

khazad-dum

----------

## maomao

I've solve it.

re-emerge perl,version is 5.8.0-r12

download net-snmp source

unzip package and complie source ourself

[/code]

----------

## servermonk

totally awesome walk  through btw  :Wink:  Maybe someone can tackle this one:

I've had snmp/mrtg setup before on this same machine and never had any problems getting it setup to query multiple machines until I installed gentoo.

For some reason I can not make snmpget or snmpwalk requests to other machines OR from other machines to this one, even when snmp/mrtg works localy on all the machines in question.

I've even tried disabling iptables entirely just to make sure it wasn't a botched iptables config... still no response to snmp requests. So far I've run into two other people having this same problem: exact same snmp config works on a machine with redhat, and doesn't in gentoo. Any idea's?

----------

## khazad-dum

You must specify IP class or ip address.

For example:

HostA have 216.239.59.99 ip address (and Netmask 255.255.255.0). It gets statistics from: HostB,HostC and HostD.

In every HOST polled (B,C and D) the

```

/etc/snmp/snmpd.conf

```

must have this line:

```

com2sec local     localhost              public

com2sec public   216.239.59.99/24    public

```

Restart snmpd.

khazad-dum

----------

## servermonk

Here is an example of my snmpd.conf file:

```

com2sec local       local.ip.add.ress/32    mygroup

com2sec mynetwork   my.ip.add.ress/32      mygroup

com2sec mynetwork   my.other.ip.address/32      mygroup

group MyROGroup v1         local

group MyROGroup v2c        local

group MyROGroup usm        local

group MyROGroup v1         mynetwork

group MyROGroup v2c        mynetwork

group MyROGroup usm        mynetwork

view all    included  .1                               80

access MyROGroup ""      any       noauth    exact  all    none   none

syslocation mylocation

syscontact myemailaddress

disk1   /       100000

disk2   /home   100000

disk3   /backup 100000

```

the problem is that even simple snmpget and snmpwalk queries can't exit or enter the machine even with no firewall rules present. Is there anything at teh kernel level I need to be looking for?

----------

## Jeff Poulin

Hmmm, I tried this on one Gentoo system (Dell PE300, Pentium III/800, Linux 2.4.22 vanilla, Intel Pro 100) and it worked perfectly.  I tried it on another system (Dell PE1600SC, Pentium IV/2.8GHz, Linux 2.4.22 vanilla, Intel Pro 1000) and it failed with the following message:

```

--base: Get Device Info on public@localhost:

SNMP Error:

no response received

SNMPv1_Session (remote host: "localhost" [127.0.0.1].161)

                  community: "public"

                 request ID: 1024590663

                PDU bufsize: 8000 bytes

                    timeout: 2s

                    retries: 5

                    backoff: 1)

 at /usr/bin/../lib/mrtg2/SNMP_util.pm line 570

SNMPWALK Problem for 1.3.6.1.2.1.1 on public@localhost:

 at /usr/bin/cfgmaker line 709

```

What's interesting is that these two systems are nearly identical in setup (I created the gentoo system on the 2.8GHz machine and compiled everything for i686, then did a "cp -a" from a rescue CD to image an identical drive for the 2nd system.  I only changed a few config files (hostname, IP address info, etc...), so the two should be the same.

Does snmp not work on the kernel's e1000 driver?  That's the only material difference I can think of.  Anybody know what I can do here?

----------

## Jeff Poulin

Just a little more info on the above post,  I did an "emerge sync" then an "emerge net-snmp libgd mrtg" on both machines before starting and followed the intructions on the first post to the letter.  Googling pointed to articles about the community string, but since the first one (P3/800) worked fine with the same setup, I'm not sure that's the problem.

----------

## khazad-dum

I'm currently use this version:

```

net-analyzer/net-snmp-5.0.9-r1  +ssl -ipv6 +tcpd

net-analyzer/mrtg-2.9.29

media-libs/libgd-2.0.15-r1  -X -gif

dev-lang/perl-5.8.0-r12  +berkdb -doc +gdbm -threads

```

and I've no problems.

Please, try to upgrade/downgrade (only for test) your programs in all machines monitored, and give me a feedback.

khazad-dumLast edited by khazad-dum on Sat Nov 29, 2003 5:06 pm; edited 1 time in total

----------

## servermonk

I recompiled perl, net-snmp, libgd and mrtg with the same USE flags listed above and tried again using this line from the net-snmp.org site under the v5 tutorial:

```

snmpget -v 2c -c demopublic test.net-snmp.org sysUpTime.0

```

Using this line returns a value on all of my machines except for my gentoo box, even with iptables and portsentry turned off.

----------

## Jeff Poulin

 *khazad-dum wrote:*   

> I'm currently use this version:
> 
> ```
> 
> net-analyzer/net-snmp-5.0.9-r1  +ssl -ipv6 +tcpd
> ...

 

I'm running exactly the same versions, but still can't get snmp to work with my Intel Pro/1000.  BTW, what command line did you use to show the USE variables compiled for your packages?

----------

## khazad-dum

 *Quote:*   

> 
> 
> I'm running exactly the same versions, but still can't get snmp to work with my Intel Pro/1000.  BTW, what command line did you use to show the USE variables compiled for your packages?

 

emerge -vp

----------

## khazad-dum

servermonk enable snmp's logging:

```

/etc/conf.d/snmpd

```

and restart the daemon. 

The problem can be solved if we have more log.

khazad-dum

----------

## servermonk

snmpd is logging to /var/log/net-snmpd.log but the only thing listed there is "Connection from (my local ip address)" over and over again.

Is there  a way to enable more verbose logging?

----------

## khazad-dum

Try to increase the level on your logger:

From man klogd

```

-c n   Sets the default log level of console messages to n.

```

and edit the

/etc/conf.d/syslogd

```

KLOGD="-c 9 -2"

```

or try to set a faciity level for snmpd:

```

-S d|0-7 Specifies  the  syslog facility to use when logging to syslog.  'd' means LOG_DAEMON and 0 through 7 mean LOG_LOCAL0 through LOG_LOCAL7.  LOG_DAEMON is the default.

```

and increase the debug option in your syslog file. If you use (for example) local7 try to put 

```

local7.=debug (or local7=* too)

```

into /etc/syslog.conf and restart it.

Another way is the debugging:

from man snmpd

```

-D[TOKEN[,...]] Turn on debugging output for  the  given TOKEN(s).   Without  any  tokens  specified,  it defaults to printing all the tokens (which is equivalent to the keyword "ALL").  You might want to try ALL for extremely verbose output.  Note: You can not put a space  between  the -D flag and the listed TOKENs.

```

and man sysklogd

```

-d     Turns on debug mode.  Using this the daemon will not proceed a fork(2) to set itself in  the  background,but opposite to that stay in the foreground and write much debug information on the current tty.  See the DEBUGGING section for more information.

```

khazad-dum

----------

## Jeff Poulin

I found a solution to my problem (above)

```

--base: Get Device Info on public@localhost: 

 SNMP Error: 

```

If I replace @localhost with @[my hostname] in my /etc/mrtg/*.cfg files, everything works.

----------

## crypt0shite

Thanks to your great guide and the follow-up replies I have MRTG up and running.  Gentoo has the best community!

----------

## hertog

Hmmm... the memory part and the swap part don't seem to work, no matter what I put in the Target line. 

Anyone who can confirm that this has to do with the 2.6.0 kernel?

No value of what I see passingby rings a bell, and those that do have a value of '0' in it  :Sad: 

----------

## chrisyu

I use kernel 2.6, mem and swap didn't work either.  :Confused: 

no error, but just no data output in picture.

----------

## hertog

 *chrisyu wrote:*   

> I use kernel 2.6, mem and swap didn't work either. 
> 
> no error, but just no data output in picture.

 

Exactly what I am seeing, so let's keep it at a kernel version related problem.

Now for a solution  :Smile: ...

Gr.

Hertog

----------

## chrisyu

found something in /var/log/net-snmpd.log

No swap line in /proc/stat

No page line in /proc/stat

maybe this problem??

and my /proc/stat file

```

cpu  155998 0 61383 3568895 29288 0 0

cpu0 155998 0 61383 3568895 29288 0 0

intr 44145554 38155664 8 0 0 0 0 2 0 2 0 5866193 0 92 0 123574 19

ctxt 7036989

btime 1072134446

processes 32760

procs_running 1

procs_blocked 0

```

----------

## khazad-dum

I think we'll have to wait for the new OID (Object IDentifier) from net-snmp.sf.net for 2.6.x branch.

Work around

cat and cut are your friends  :Smile:  !!

```

root@guardian proc # cat /proc/meminfo  | grep SwapFree | cut -d ' ' -f 8

224884

```

Look into /proc/meminfo (and /proc/stat or /proc/* too) and cat&cut your $VARIABLES

```

Target[localhost.mem]: `cat /proc/meminfo  | grep  |MemTotal cut -d ' ' -f 8`

```

Enjoy

 :Very Happy:   :Very Happy: 

----------

## apokalyptik

```
WORKDIR=/home/blah/public_html/svc/`hostname`

PAGETITLE=`hostname`": Statistics"

DELOLDINFO=1

MAKECRON=1

if [ $DELOLDINFO -eq 1 ]

 then

  if [ -d $WORKDIR ]

   then

    rm -rf $WORKDIR

  fi

fi

/usr/bin/mkdir /etc/mrtg

/usr/bin/mkdir /etc/cron.mrtg

/usr/bin/mkdir $WORKDIR

echo 'com2sec local     127.0.0.1/32    public

com2sec local     10.0.0.0/24     public

group MyROGroup v1         local

group MyROGroup v2c        local

group MyROGroup usm        local

view all    included  .1                               80

access MyROGroup ""      any       noauth    exact  all    none   none

syslocation MyLocation

syscontact Me <service@eaglenetworks.net> ' > /etc/snmp/snmpd.conf

echo 'SNMPD_FLAGS="$SNMPD_FLAGS -c /etc/snmp/snmpd.conf"' >> /etc/conf.d/snmpd

/sbin/rc-update add snmpd default 

/etc/init.d/snmpd start

mkdir $WORKDIR

/usr/bin/cfgmaker  \

--output=/etc/mrtg/traffic.cfg \

--ifdesc=ip \

--ifref=descr \

--global "WorkDir: $WORKDIR" \

--global "Options[_]: bits,growright" \

public@localhost 

echo 'WorkDir: '$WORKDIR'

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost + ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost

RouterUptime[localhost.cpu]: public@localhost

MaxBytes[localhost.cpu]: 100

Title[localhost.cpu]: CPU Load

PageTop[localhost.cpu]: <H1>Active CPU Load %</H1>

Unscaled[localhost.cpu]: ymwd

ShortLegend[localhost.cpu]: %

YLegend[localhost.cpu]: CPU Utilization

Legend1[localhost.cpu]: Active CPU in % (Load)

Legend2[localhost.cpu]:

Legend3[localhost.cpu]:

Legend4[localhost.cpu]:

LegendI[localhost.cpu]:  Active

LegendO[localhost.cpu]:

Options[localhost.cpu]: growright,nopercent ' > /etc/mrtg/cpu.cfg

echo 'LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt

Target[localhost.mem]: .1.3.6.1.4.1.2021.4.11.0&.1.3.6.1.4.1.2021.4.11.0:public@localhost

PageTop[localhost.mem]: <H1>Free Memory </H1>

WorkDir: '$WORKDIR'

Options[localhost.mem]: nopercent,growright,gauge,noinfo

Title[localhost.mem]: Free Memory

MaxBytes[localhost.mem]: 1000000

kMG[localhost.mem]: k,M,G,T,P,X

YLegend[localhost.mem]: bytes

ShortLegend[localhost.mem]: bytes

LegendI[localhost.mem]:  Free Memory:

LegendO[localhost.mem]:

Legend1[localhost.mem]: Free memory, not including swap, in bytes ' > /etc/mrtg/mem.cfg

echo 'LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost.swap]: memAvailSwap.0&memAvailSwap.0:public@localhost

PageTop[localhost.swap]: <H1>Swap Memory</H1>

WorkDir: '$WORKDIR'

Options[localhost.swap]: nopercent,growright,gauge,noinfo

Title[localhost.swap]: Free Memory

MaxBytes[localhost.swap]: 1000000

kMG[localhost.swap]: k,M,G,T,P,X

YLegend[localhost.swap]: bytes

ShortLegend[localhost.swap]: bytes

LegendI[localhost.swap]:  Free Memory:

LegendO[localhost.swap]:

Legend1[localhost.swap]: Swap memory avail, in bytes ' > /etc/mrtg/swap.cfg

echo 'WorkDir: '$WORKDIR'

Title[localhost.ping]: Round Trip Time

PageTop[localhost.ping]: <H1>Round Trip Time</H1>

Target[localhost.ping]: `/etc/mrtg/ping.sh`

MaxBytes[localhost.ping]: 2000

Options[localhost.ping]: growright,unknaszero,nopercent,gauge

LegendI[localhost.ping]: Pkt loss %

LegendO[localhost.ping]: Avg RTT

Legend1[localhost.ping]: Maximum Round Trip Time in ms

Legend2[localhost.ping]: Minimum Round Trip Time in ms

Legend3[localhost.ping]: Maximal 5 Minute Maximum Round Trip Time in ms

Legend4[localhost.ping]: Maximal 5 Minute Minimum Round Trip Time in ms

YLegend[localhost.ping]: RTT (ms) ' > /etc/mrtg/ping.cfg

echo '#!/bin/sh

/usr/bin/mrtg /etc/mrtg/traffic.cfg ' > /etc/cron.mrtg/traffic.sh

chmod 751 /etc/cron.mrtg/traffic.sh

echo '#!/bin/sh

/usr/bin/mrtg /etc/mrtg/mem.cfg ' > /etc/cron.mrtg/mem.sh

chmod 751 /etc/cron.mrtg/mem.sh

echo '#!/bin/sh

/usr/bin/mrtg /etc/mrtg/swap.cfg ' > /etc/cron.mrtg/swap.sh

chmod 751 /etc/cron.mrtg/swap.sh

echo '#!/bin/sh

/usr/bin/mrtg /etc/mrtg/ping.cfg ' > /etc/cron.mrtg/ping.sh

chmod 751 /etc/cron.mrtg/ping.sh

echo '#!/bin/sh

/usr/bin/mrtg /etc/mrtg/cpu.cfg ' > /etc/cron.mrtg/cpu.sh

chmod 751 /etc/cron.mrtg/cpu.sh

echo '#!/bin/sh

PING="/bin/ping"

# Google, for example

ADDR="google.com"

DATA=`$PING -c10 -s500 $ADDR -q `

LOSS=`echo $DATA | awk "{print $18 }" | tr -d %`

echo $LOSS

if [ $LOSS = 100 ];

then

               echo 0

else

        echo $DATA | awk -F/ "{print $5 }"

fi

' > /etc/mrtg/ping.sh

chmod 751 /etc/mrtg/ping.sh

/bin/chmod +x /etc/cron.mrtg/*.sh

/bin/chmod +x /etc/mrtg/ping.sh 

/etc/cron.mrtg/traffic.sh

/etc/cron.mrtg/cpu.sh

/etc/cron.mrtg/mem.sh

/etc/cron.mrtg/swap.sh

/etc/cron.mrtg/ping.sh 

/etc/cron.mrtg/traffic.sh

/etc/cron.mrtg/cpu.sh

/etc/cron.mrtg/mem.sh

/etc/cron.mrtg/swap.sh

/etc/cron.mrtg/ping.sh

/etc/cron.mrtg/traffic.sh

/etc/cron.mrtg/cpu.sh

/etc/cron.mrtg/mem.sh

/etc/cron.mrtg/swap.sh

/etc/cron.mrtg/ping.sh 

/usr/bin/indexmaker --output=$WORKDIR/index.html \

--title="$PAGETITLE" \

--sort=name \

--enumerate \

/etc/mrtg/traffic.cfg \

/etc/mrtg/cpu.cfg \

/etc/mrtg/mem.cfg \

/etc/mrtg/swap.cfg \

/etc/mrtg/ping.cfg 

if [ $MAKECRON -eq 1 ]

 then

  echo '*/5 * * * * /bin/run-parts /etc/cron.mrtg 1> /dev/null' >> /var/spool/cron/crontabs/root

fi
```

----------

## tagore

how to add apache stats like your webpage?

----------

## NeuralRelay

 *khazad-dum wrote:*   

> I think we'll have to wait for the new OID (Object IDentifier) from net-snmp.sf.net for 2.6.x branch.
> 
> Work around
> 
> cat and cut are your friends  !!
> ...

 

When trying to use this for both SwapFree and MemFree, I get this error:

```

WARNING: Problem with External get 'cat /proc/meminfo | grep SwapFree | cut -d ' ' -f 7':

   Expected a Number for 'out' but nothing'

ERROR: Target[localhost.swap][_OUT_] ' $$target[0]{$mode} ' did not eval into defined data

WARNING: Skipping Update of localhost.swap, outlast is not defined

```

Any ideas?

----------

## khazad-dum

Tagore:

For your Apache stats download the

Apache Server Status contrib

from

```

http://lab.xpto.org/apache.mrtg/

```

khazad-dum

----------

## khazad-dum

NeuralRelay:

I've found a mistake in your code:

```

 'cat /proc/meminfo | grep SwapFree | cut -d ' ' -f 7'

```

mrtg use the "simple shell syntax" for get a simple result from code like this:

```

`cat /proc/meminfo | grep SwapFree | cut -d ' ' -f 7`

```

Look the inverse apexes.

Use the key:

AltGr and '

or cut&paste this:

```
`cat /proc/meminfo | grep SwapFree | cut -d ' ' -f 8`
```

Let me know.

khazad-dum

----------

## tagore

 *khazad-dum wrote:*   

> Tagore:
> 
> For your Apache stats download the
> 
> Apache Server Status contrib
> ...

 

This not work for my, i'get this :

```

./apache.mrtg.pl -url http://localhost/server-status?auto -info BUSYSERVERS

Undefined subroutine &main::get called at ./apache.mrtg.pl line 61.

```

i'm able to view the status page with lynx.

For mysql load recomend this

http://www.bitbybit.dk/mysqlfaq/mrtg-mysql-load/

Cheers.

----------

## khazad-dum

You need some perl-libs:

```

dev-perl/Getopt-Long

dev-perl/libwww-perl

dev-perl/Digest-MD5

```

Thx for mrtg-mysql link  :Wink: 

You know Squdi-mrtg?

http://howto.aphroland.de/HOWTO/MRTG/SquidMonitoringWithMRTG

khazad-dum

----------

## tagore

Thx i'm installing libraries

WOW, but not using squid  :Sad: 

Thx, cheers.

----------

## Seather

Okay, I have set up the default that khazad-dum wrote.

Now I want to run this on my router/gateway to see which box on the local area network uses how much of our bandwidth and when.

Any help on doing this please?

----------

## khazad-dum

Add your hosts (or network too) in snmpd.conf like step 2 at:

https://forums.gentoo.org/viewtopic.php?p=648066#648066

(for example: com2sec local     10.10.10.0/24   public)

Now, restart your /etc/init.d/snmpd and configure your .cfg files like this:

host1.cfg

```

/usr/bin/cfgmaker  \

--output=/etc/mrtg/traffic.cfg \

--ifdesc=ip \

--ifref=descr \

--global "WorkDir: /var/www/localhost/mrtg/host1" \

--global "Options[_]: bits,growright" \

public@host1

```

host2.cfg

```

/usr/bin/cfgmaker  \

--output=/etc/mrtg/traffic.cfg \

--ifdesc=ip \

--ifref=descr \

--global "WorkDir: /var/www/localhost/mrtg/host2" \

--global "Options[_]: bits,growright" \

public@host2

```

and go ahead....

The most important "area" is:

```
public@host2
```

public = Community string (see man snmpd.conf for other options)

@host = Single host

Look man pages for little examples (or post here  :Razz: )

khazad-dum

----------

## Seather

Sorry for being stupid again,

Went through the mostly-greek manpages again, tried it and still no luck. This is what I have in my /etc/snmp/snmpd.conf at the moment:

```
com2sec local     127.0.0.1/32    public

com2sec local     10.10.10.0/24   public

com2sec local     192.168.0.45/24 public

com2sec local     192.168.0.69/24 public

group MyROGroup v1         local

group MyROGroup v2c        local

group MyROGroup usm        local

view all    included  .1                               80

access MyROGroup ""      any       noauth    exact  all    none   none

syslocation MyLocation

syscontact Me <me@somewhere.org>
```

and the cfgmaker command that I tried to run:

```
/usr/bin/cfgmaker  --output=/etc/mrtg/traffic.cfg --ifdesc=ip --ifref=descr --global "WorkDir: /var/www/localhost/htdocs/mrtg/host1" --global "Options[_]: bits,growright" public@host1
```

If you meant that I have to install snmpd on all of my machines and run it and change public@host1 to say for example public@192.168.0.69, I cannot run snpd on all of the machines unfortunately...

Where am I totally pissing the point?

----------

## khazad-dum

It's necessary snmpd daemon (or another snmp server) in all the machines that you want to get statistics.

Unfortunally it isn't possible to collect statistics from hosts without snmpd daemon.

----------

## Seather

Isn't it possible to let snmp count how many packets were sent to a certain ip address?

----------

## khazad-dum

Is not possible; snmp can only manage (and/or control) machines via snmp query.

But there are many network analyzer on the net (sounds like a sniffer). Surf it (by google, naturally  :Smile:  ) or try to query @sf.net or @freshmeat.net

khazad-dum

----------

## lapaluun

Since I have migrated to kernel 2.6.2-r2, mrtg doesn't show any stats for mem and swap values. Actually, graphs are progressing well, but always returning 0 as "Current Free Memory" details.

However, other informations like CPU or disk usage are updated properly.

I'd like to know if there have been changes in /proc fs with kernel 2.6 versions, that could lead to this problem.

----------

## aab1016

Whats wrong,,, i dont receive anything,,,whyyyy,,,,i configure it like this steps

i

----------

## aab1016

I dont receive nothing,,,,,,,,,,,,,,whats wrong

----------

## Strom

I have 2.6.1-love5, and i got swap, mem and such stuff working, but what i havent got working is CPU.

I recive these messages:

```

SNMP Error:

no response received

SNMPv1_Session (remote host: "localhost" [127.0.0.1].161)

                  community: "public"

                 request ID: 1521672888

                PDU bufsize: 8000 bytes

                    timeout: 2s

                    retries: 5

                    backoff: 1)

 at /usr/bin/../lib/mrtg2/SNMP_util.pm line 487

SNMPGET Problem for ssCpuRawUser.0 ssCpuRawUser.0 sysUptime sysName on public@localhost::::::v4only

 at /usr/bin/mrtg line 1835

WARNING: skipping because at least the query for ssCpuRawUser.0 on  localhost did not succeed

WARNING: no data for ssCpuRawUser&ssCpuRawUser:public@localhost. Skipping further queries for Host localhost in this round.

ERROR: Target[localhost.cpu][_IN_] ' $target->[0]{$mode}  +  $target->[1]{$mode}  +  $target->[2]{$mode} ' (warn): Use of uninitialized value in addition (+) at (eval 6) line 1.

ERROR: Target[localhost.cpu][_OUT_] ' $target->[0]{$mode}  +  $target->[1]{$mode}  +  $target->[2]{$mode} ' (warn): Use of uninitialized value in addition (+) at (eval 7) line 1.

SNMP Error:

no response received

SNMPv1_Session (remote host: "localhost" [127.0.0.1].161)

                  community: "public"

                 request ID: 1142331004

                PDU bufsize: 8000 bytes

                    timeout: 2s

[/                    retries: 5

                    backoff: 1)

 at /usr/bin/../lib/mrtg2/SNMP_util.pm line 487

SNMPGET Problem for sysUptime sysName on public@localhost

 at /usr/bin/mrtg line 518

```

----------

## Strom

When i appended 

```
:::::2
```

 to my targets then i didn't get those errors anymore.

(Now it uses protocol v2)

But the graph doesn't show anything, it's empty .. NO data  :Sad: 

----------

## Strom

OK! I got everything workin the way i like it ...

How? Well i just read the whole f--king manual  :Wink: 

----------

## Naspe

Hi all!

Grats for the very nice how-to!

I have some problems/questions:

1 - My mem and swap graphs doesn't work. I have a 2.6.1-gentoo kernel. I tried with this:

```
`cat /proc/meminfo | grep SwapFree | cut -d ' ' -f 7`
```

but i get this message:

```
plutone txt # /etc/cron.mrtg/mem.sh 

WARNING: Problem with External get 'cat /proc/meminfo | grep SwapFree | cut -d ' ' -f 8':

   Expected a Number for 'out' but nothing'

ERROR: Target[localhost.mem][_OUT_] ' $$target[0]{$mode} ' did not eval into defined data

WARNING: Skipping Update of localhost.mem, outlast is not defined

```

but in the mem.cfg file the apexes are inverted...

How to make it work? Storm told that mem and swap are working with his 2.61 kernel...

2 - I added the disk usage... but i see the graph move from left to right... others are from right to left... how to change it? And i can't see the disk size...

3 - Is it possible to view info from winsux PC and from other network devices like a Router?

4 - Where should i put the option language? In the cfg files?

----------

## axxackall

Excelent guide!

I did not manage to display multiple CPUs individually (SNMP complains on any number if CPU if it is not 0),but I've found more patterns to display more information about CPU usage, namely "User vs Idle CPU usage" and "User vs System CPU usage".

Also I didn't manage to display partition usage (the chart doesn't grow), but I've created my own one for folder sizes. I have two huge folders, one for samba shares, the other for cvs repository and I gotta watch out the growth.

/etc/mrtg/shared.cfg:

```

WorkDir: /var/www/localhost/mrtg

Title[localhost.shared]: shared folders

PageTop[localhost.shared]: <H1>Shared Folders</H1>

Target[localhost.shared]: `/etc/mrtg/shared.sh`

MaxBytes[localhost.shared]: 69972132000

kilo[localhost.shared]: 1000

Options[localhost.shared]: growright,unknaszero,nopercent,gauge

LegendI[localhost.shared]: samba

LegendO[localhost.shared]: cvs

Legend1[localhost.shared]: Maximum size in B

Legend2[localhost.shared]: Minimum size in B

Legend3[localhost.shared]: Maximal 5 Minute Maximum size in B

Legend4[localhost.shared]: Maximal 5 Minute Minimum size in B

YLegend[localhost.shared]: size (B)

ShortLegend[localhost.shared]: B

```

/etc/mrtg/shared.sh:

```

#!/bin/sh

du -sk /opt/files /opt/cvs |awk '{print $1"000"}'

```

The size is not precize - I had too adapt kilobytes to bytes and did not have time for anything smarter. Suggestions for improving it are welcome.

/etc/cron.mrtg/shared.sh:

```

#!/bin/sh

/usr/bin/mrtg /etc/mrtg/shared.cfg

```

I still have to debug why my disk-usage chart from the originally posted guide doesn't grow. Any idea?

----------

## axxackall

Another question: how to process disk-related statistics hourly? 5 minutes is a bit too often IMHO. I mean I know how to change crontab, but is it enough? Will it breake anything in MRTG database?

Edit: I found the option for cfg files:

```

Interval: 60

```

And now I run disk statistics from /etc/cron.hourly instead of /etc/cron.mrtg

But now I am facing another problem: if my interval is 60 minutes, then how will it work for week charts where the average is based on 30 minutes?

----------

## axxackall

I've got various log files growing in my system. Well, they are being rotated. Is it possible to feed such files to MRTG? It would be nice to add stats about mail routing, infection, spam, web-usage and so on. 

I am thinking to write some parsing scripts extractig such statistics, it's not actually that big deal, but the problem is in rotating logs after that. Again, it will be too big overhead to rotate logs once each 5 minutes.

Edit: Can I use "Interval: 1440" option for daily updates?

----------

## lonegd

Anyone have an example config for monitoring disk IO read/write's???   :Smile: 

----------

## khazad-dum

Folks,

i've finally get memory stat with 2.6 kernel IN MY MACHINE

```

guardian proc # cat meminfo 

MemTotal:       321380 kB

MemFree:          6760 kB

Buffers:         14052 kB

Cached:         145624 kB

SwapCached:       7076 kB

Active:         167652 kB

Inactive:        86192 kB

HighTotal:           0 kB

HighFree:            0 kB

LowTotal:       321380 kB

LowFree:          6760 kB

SwapTotal:      248968 kB

SwapFree:       229056 kB

Dirty:               0 kB

Writeback:           0 kB

Mapped:         125376 kB

Slab:            57784 kB

Committed_AS:   137320 kB

PageTables:       1116 kB

VmallocTotal:   712504 kB

VmallocUsed:       284 kB

VmallocChunk:   712116 kB

```

Memory

```

guardian proc # cat /etc/mrtg/mem2.sh

#!/bin/sh

cat /proc/meminfo | grep MemTotal | cut -d ' ' -f 8

cat /proc/meminfo | grep MemFree | cut -d ' ' -f 11

```

```

guardian proc #  /etc/mrtg/mem2.sh

321380

6760

```

Swap

```

guardian proc # cat /etc/mrtg/swap2.sh

#!/bin/sh

cat /proc/meminfo | grep SwapFree | cut -d ' ' -f 8

cat /proc/meminfo | grep SwapTotal | cut -d ' ' -f 7

```

```

guardian proc #  /etc/mrtg/swap2.sh

248968

229056

```

This is a workaround. A bug request is opened at official snmp-net mailing list. A "little" info here:

Memory support missing for linux 2.6

The 2.6 kernel changed the /proc/stat interface, breaking memory statistics.

http://sourceforge.net/mailarchive/message.php?msg_id=7091107

IMPORTANT: man cut !!! The value of fields are different for every /proc/stat.

REMEMBER:

```

guardian contrib # pwd

/usr/doc/mrtg-2.9.29/contrib

guardian contrib # ls

00INDEX.gz         ascendget           distrib              ircstats2             mrtg.php         portmasters

14all              atmmaker            gentcucci-1.0.0      jm                    mrtg_php_portal  procmem

GetSNMPLinesUP     cfgmaker_ATM        get-active           linux_stat            mrtgidx          rdlog2

IxDisk             cfgmaker_cisco      get-equi             meminfo               mrtgindex.cgi    routers

NSI                cfgmaker_dlci       get-multiserial      monitor               mrtglog          rumb-stat

PMLines            cisco_BPX_MGX       ipchainacc           mrtg-archiver         mrtgmk           snmpping

TCH                cisco_ipaccounting  ipchains             mrtg-archiver-script  mrtgrq           stat

TTrafic            cisco_tftp          ipfilter             mrtg-blast            net-hosts        stfc

TotalControlModem  ciscoindex          iptables-accounting  mrtg-dynip            nt-services      switchmaker

accesslistmon      cpuinfo             iptables_acc         mrtg-ipacc            nt_n_cisco       whodo

adm-mrtg           cpumon              iptables_acc_snmp    mrtg-ipget            ovmrtg           xlsummary

apc_ups            diskmon             ircstats             mrtg-mail             ping-probe

```

Look into this dir! Many powerful scripts for your stat!

Link

A good pdf:

http://www.enterastream.com/whitepapers/mrtg/mrtg-implementation-manual.pdf

Another important link:

http://www.snmplink.org/

Ehy..man google  :Wink: 

Enjoy

@lonegd

Look here:

```

/usr/share/snmp/mibs/UCD-DISKIO-MIB.txt

```

----------

## jamesrt

 *khazad-dum wrote:*   

> 
> 
> ```
> guardian proc # cat /etc/mrtg/mem2.sh
> 
> ...

 

Perhaps not as elegant, but it saves all the mucking about with trying to work out cut fields if you do this:

```
# cat /etc/mrtg/swap2.sh

#!/bin/sh

cat /proc/meminfo | grep SwapFree | awk '{print $2}'

cat /proc/meminfo | grep SwapTotal | awk '{print $2}'

```

and

```
# cat /etc/mrtg/mem2.sh

#!/bin/sh

cat /proc/meminfo | grep MemTotal | awk '{print $2}'

cat /proc/meminfo | grep MemFree | awk '{print $2}'

```

----------

## PedroKiefer

Folk's don't use cut, the value of free memory changes over time, and cut doesn't work. so, use awk   :Very Happy: 

```

cat /etc/mrtg/mem.sh

#!/bin/sh

cat /proc/meminfo | awk '/MemTotal/{print $2}'

cat /proc/meminfo | awk '/MemFree/{print $2}'

```

works perfectly  :Smile: 

----------

## Strom

Oh btw, if someone hasn't got the CPU graph working or hasn't got multi-cpu graphs working then you may get some ideas from my cpu load script:

```

#!/bin/sh

#

# This script calculates CPU usage in %

# (C) 2004 Kaur Kuut

#

# CPU name: (default: cpu0)

CPU_NAME="cpu0"

# Temp dir yo use (default: /tmp/)

TEMP_DIR="/tmp/"

# Sleep time if temp file doesn't exist (default: 10)

SLEEP_TIME="10"

# Output accuracy (default: 0)

ACCURACY="0"

TEMP_FILE="$TEMP_DIR""$CPU_NAME""calc"

# When CPU_NAME is just "cpu" without a number then we need to

# parse data in a different way

if [ $CPU_NAME == "cpu" ]

then

  KNOWN_ISSUE=1

else

  KNOWN_ISSUE=0

fi

USER_CUT=`echo "(2+$KNOWN_ISSUE)" | bc -l`

NICE_CUT=`echo "(3+$KNOWN_ISSUE)" | bc -l`

SYSTEM_CUT=`echo "(4+$KNOWN_ISSUE)" | bc -l`

IDLE_CUT=`echo "(5+$KNOWN_ISSUE)" | bc -l`

# If temp file doesn't exist -> create it and put user,nice,system,idle there

if [ ! -s $TEMP_FILE ]

then

  cat /proc/stat | grep -m1 "^$CPU_NAME" | cut -d ' ' -f 3,4,5,6 > $TEMP_FILE 

  sleep $SLEEP_TIME # Sleep for $SLEEP_TIME seconds, otherwise the results will be very ugly

fi

# Loading vars from temp file...

USER_1=`cat $TEMP_FILE | cut -d ' ' -f 1`

NICE_1=`cat $TEMP_FILE | cut -d ' ' -f 2`

SYSTEM_1=`cat $TEMP_FILE | cut -d ' ' -f 3`

IDLE_1=`cat $TEMP_FILE | cut -d ' ' -f 4`

# Geting current ticks..

USER_2=`cat /proc/stat | grep -m1 "^$CPU_NAME" | cut -d ' ' -f $USER_CUT`

NICE_2=`cat /proc/stat | grep -m1 "^$CPU_NAME" | cut -d ' ' -f $NICE_CUT`

SYSTEM_2=`cat /proc/stat | grep -m1 "^$CPU_NAME" | cut -d ' ' -f $SYSTEM_CUT`

IDLE_2=`cat /proc/stat | grep -m1 "^$CPU_NAME" | cut -d ' ' -f $IDLE_CUT`

# Calculating avarage values

USER=`echo "($USER_2-$USER_1)" | bc -l`

NICE=`echo "($NICE_2-$NICE_1)" | bc -l`

SYSTEM=`echo "($SYSTEM_2-$SYSTEM_1)" | bc -l`

IDLE=`echo "($IDLE_2-$IDLE_1)" | bc -l`

# Doing final calculations

IDLE_PERCENT=`echo "(($NICE+$IDLE)/($USER+$NICE+$SYSTEM+$IDLE)*100)" | bc -l`

#echo "(`echo "(101-$IDLE_PERCENT)" | bc -l | cut -d '.' -f 1`-1)" | bc -l

CPU_USAGE=`echo "print round(100-$IDLE_PERCENT,$ACCURACY)" | python`

# Echoing the CPU usage

echo $CPU_USAGE

echo $CPU_USAGE

# Saving current ticks to temp file for another run :)

echo $USER_2 $NICE_2 $SYSTEM_2 $IDLE_2 > $TEMP_FILE

```

----------

## Drunkula

I got mrtg working on my Sun Ultra 2, with one exception.  The CPU is not showing any activity on the graph.  I have a dual cpu UltraSparc II box.  I DID try to get the second CPU to display as well but was getting errors so I deleted that config and went back to single for now.  And, yes, I did see the other post in this thread about additional processors.

Incidentally I saw this on the net-smtp docs webpage..

```
    Sorry - the CPU statistics (both original percentages, and the

  newer raw statistics) both refer to the system as a whole.  There

  is currently no way to access individual statistics for a particular

  processor.

    Note that although the Host Resources table includes a hrProcessorTable,

  the current implementation suffers from two major flaws.  Firstly, it

  doesn't currently recognise the presence of multiple processors, and

  simply assumes that all systems have precisely one CPU.  Secondly, it

  doesn't calculate the hrProcessorLoad value correctly, and either returns

  a dummy value (based on the load average) or nothing at all.

    If you want to monitor a multi-processor system, you're currently

  out of luck.  We hope to address this in a future release of the agent.

  But you've got the source, so you can always have a go yourself :-)
```

----------

## Rooney

Why does snmp report the wrong disk size and does any one know how i can set this right.

HOST-RESOURCES-MIB::hrStorageDescr.2 = STRING: /

HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: /home

HOST-RESOURCES-MIB::hrStorageSize.2 = INTEGER: 4611420

HOST-RESOURCES-MIB::hrStorageSize.3 = INTEGER: 19487056

HOST-RESOURCES-MIB::hrStorageUsed.2 = INTEGER: 837368

HOST-RESOURCES-MIB::hrStorageUsed.3 = INTEGER: 9316812

but this is the reslut of a df

/dev/hda3             18445680   3349352  14159340  20% /

/dev/hdb3             77948224  37267248  36721356  51% /home

Ive tried snmpset but this just reports an error

beaver root # snmpset -v 2c -c root localhost HOST-RESOURCES-MIB::hrStorageSize.3 i 77948224

Error in packet.

Reason: notWritable (that object does not support modification)

Failed object: HOST-RESOURCES-MIB::hrStorageSize.3

----------

## Rooney

sorry people found a fix by opening my eyes

https://forums.gentoo.org/viewtopic.php?t=109817&highlight=snmp+disk

----------

## matt2413

*EDIT* Solved swap on 2.4

So, 2 things.

1. Thanks for the nice guide.  Mucho help.

2. So what's the final status of getting mem/swap to work in 2.6+?

Anyone have a solution for multiple CPU's yet?

Thanks for any help.

Matt

----------

## Popsikle

```

asuka mrtg # mrtg --debug cfg,log  mems.cfg

--cfg: mems.cfg[1]: LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt

--cfg: mems.cfg[2]: Target[localhost.mems]: `/etc/mrtg/swap.sh`

--cfg: mems.cfg[3]: PageTop[localhost.mems]: <H1>Free Swap Memory </H1>

--cfg: mems.cfg[4]: WorkDir: /var/www/localhost/asuka

--cfg: mems.cfg[5]: Options[localhost.mems]: nopercent,growright,gauge,noinfo

--cfg: mems.cfg[6]: Title[localhost.mems]: Free Swap

--cfg: mems.cfg[7]: MaxBytes[localhost.mems]: 1000000

--cfg: mems.cfg[8]: kMG[localhost.mems]: k,M,G,T,P,X

--cfg: mems.cfg[9]: YLegend[localhost.mems]: bytes

--cfg: mems.cfg[10]: ShortLegend[localhost.mems]: bytes

--cfg: mems.cfg[11]: LegendI[localhost.mems]:  Swap Memory:

--cfg: mems.cfg[12]: LegendO[localhost.mems]:

--cfg: mems.cfg[13]: Legend1[localhost.mems]: Swap memory in bytes

--log: Called /usr/bin/rateup /var/www/localhost/asuka/ localhost.mems 1081694833 -Z g 2008116 0 1000000 c #00cc00 #0000ff #006600 #ff00ff l [bytes] k 1000 K k,M,G,T,P,X i /var/www/localhost/asuka/localhost.mems-day.png -1000000 -1000000 400 100 1 1 1 300 0 4 1

```

When I run the rateup manually:

```

asuka mrtg # /usr/bin/rateup /var/www/localhost/asuka/ localhost.mems 1081694833 -Z g 2008116 0 1000000 c #00cc00 #0000ff #006600 #ff00ff l [bytes] k 1000 K k,M,G,T,P,X i /var/www/localhost/asuka/localhost.mems-day.png -1000000 -1000000 400 100 1 1 1 300 0 4 1

Segmentation fault
```

Is all I get.

```
asuka mrtg # cat mem.cfg

LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt

Target[localhost.mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@localhost

PageTop[localhost.mem]: <H1>Free Memory </H1>

WorkDir: /var/www/localhost/asuka

Options[localhost.mem]: nopercent,growright,gauge,noinfo

Title[localhost.mem]: Free Memory

MaxBytes[localhost.mem]: 1000000

kMG[localhost.mem]: k,M,G,T,P,X

YLegend[localhost.mem]: bytes

ShortLegend[localhost.mem]: bytes

LegendI[localhost.mem]:  Free Memory:

LegendO[localhost.mem]:

Legend1[localhost.mem]: Free memory, not including swap, in bytes
```

```
asuka mrtg # cat swap.sh

cat /proc/meminfo  | grep SwapFree | awk '{print $2}'

cat /proc/meminfo  | grep SwapCached | awk '{print $2}'

echo "00:00:00"

echo "Swap Memory"
```

```
asuka mrtg # ./swap.sh

2008116

0

00:00:00

Swap Memory
```

 Any Ideas?

----------

## his_royal_evilness

smtp root # uname -rsv

Linux 2.6.4-gentoo-r1 #1 Sat Apr 3 09:05:56 CEST 2004

I managed to produce graphs for mem/swap  :Smile: 

My .cfg's : 

Mem.cfg : 

WorkDir: /var/www/localhost/htdocs/mrtg

Title[mem]: memory used/free - FQDN

Target[mem]: `free | /usr/bin/awk '/Mem: /{print $3*1000; print $4*1000; print ""; print ""}'`

PageTop[mem]: <H1> memory used/free - FQDN </H1>

Options[mem]: gauge

MaxBytes[mem]: 50000000000

Ylegend[mem]: mem

ShortLegend[mem]: mem

XSize[mem]: 350

YSize[mem]: 150

Legend1[mem]: mem&nbsp;

LegendI[mem]: used&nbsp;

LegendO[mem]: free&nbsp;

WithPeak[mem]: ymwd

swap.cfg:

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost.swap]: `free | /usr/bin/awk '/Swap: /{print $3; print $3; print ""; print ""}'`

PageTop[localhost.swap]: <H1>Swap Memory</H1>

WorkDir: /var/www/localhost/htdocs/mrtg

Options[localhost.swap]: nopercent,growright,gauge,noinfo

Title[localhost.swap]: Free Memory

MaxBytes[localhost.swap]: 1000000

kMG[localhost.swap]: k,M,G,T,P,X

YLegend[localhost.swap]: bytes

ShortLegend[localhost.swap]: bytes

LegendI[localhost.swap]:  Free Memory:

LegendO[localhost.swap]:

Legend1[localhost.swap]: Swap memory avail, in bytes

Hope i helped ya out  :Smile: 

----------

## thejayjay

I am getting strange results from one of my graphs -- I followed the directions exactly but something isn't coming up right.  The numbers for my cable connection fluctuate and are no where near correct, it currently thinks I am downloading at 40-50k a second and seems to only "flatline" around 12-16k a second.  If i unplug the cable modem it still sits around 5-8kb a second, what gives?

----------

## his_royal_evilness

 *thejayjay wrote:*   

> I am getting strange results from one of my graphs -- I followed the directions exactly but something isn't coming up right.  The numbers for my cable connection fluctuate and are no where near correct, it currently thinks I am downloading at 40-50k a second and seems to only "flatline" around 12-16k a second.  If i unplug the cable modem it still sits around 5-8kb a second, what gives?

 

is that pc directly connected to the cable modem?

----------

## thejayjay

Yes -- direct cat5 cable straight to the modem.  When the machine ran debian and mrtg before it didn't have a problem.  I guess that snmp is capturing strange data, how do i check this out and fix it?  I followed the guide exactly and i tried reading some of the output from snmpwalk but i do not know exactly what i am looking for.

----------

## custo

Hi! I've been having problems with cpu and storage information from the mibs.

When I try this:

snmpwalk -c public 192.168.0.168 cpu

I get:

UCD-SNMP-MIB::ssCpuRawInterrupt = No Such Object available on this agent at this OID

And the same occurs for storage information. I don't know what to do...please help me!

----------

## his_royal_evilness

 *custo wrote:*   

> Hi! I've been having problems with cpu and storage information from the mibs.
> 
> When I try this:
> 
> snmpwalk -c public 192.168.0.168 cpu
> ...

 

is the following line present in your .cfg's ?

LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt

----------

## custo

Thanks for your fast response

I've already put that line in the cfg but it still doesn't work..

When I do snmpwalk in the console it also should work, shouldn't it? But there's no way to put this info when I do a snmpwalk in the console

Thanks

----------

## his_royal_evilness

 *custo wrote:*   

> Thanks for your fast response
> 
> I've already put that line in the cfg but it still doesn't work..
> 
> When I do snmpwalk in the console it also should work, shouldn't it? But there's no way to put this info when I do a snmpwalk in the console
> ...

 

could you please paste the config here?  :Smile: 

----------

## custo

Hi! thanks again..I've been out for this weekend

Thanks! I've included the Loadmib and now the cpu load works! but memory usage doesn't....any values are printed on the html page. Always 0.0 

And I have another question...some of the hosts I have to monitor are Windows Stations, and I can't find the OID for cpu load and memory usage. How can I do this?

I get something like this on a snmpwalk:

UCD-SNMP-MIB::ssCpuRawUser = No more variables left in this MIB View (It is past the end of the MIB tree)

Lots of thanks

----------

## brown

Great guide, thanks so much.

Anyone have any idea how to get stats for Samba? I'd like to display network usage of samba if possible.

----------

## brown

 *khazad-dum wrote:*   

> Folks,
> 
> i've finally get memory stat with 2.6 kernel IN MY MACHINE
> 
> ```
> ...

 

Sorry, but I don't get this. How are you using these shell scripts in your cfg file? What does the Target line look like? And why do you have MemTotal and then MemFree in the first one, and the order is swapped for the Swap2.sh?

----------

## _Daan_

Great guide! It all Just Works (tm).

I'm running an Icecast 2 server, and desperately searching for a way to make mrtg display listener statistics for each stream. Are there any scripts out there or do I have to write them myself? Google returns nothing useful...

----------

## Seather

Hi, I'm trying to get some apache stats with mrtg, but got stuck.

I tried this: http://lab.xpto.org/apache.mrtg/ but it turned into a bit of a mess, I'm not *entirely* sure how to use it though.

Anyone else that have done this, or know where I can find documentation on it?

----------

## neutcomp

I did find a few problems, during the tutorial. I am just a rookie so maby I am totally wrong but here it is:

This did not worked for me

```
emerge media-libs/libgd
```

Whats the v1, v2c and usm? 

The group MyROGroup does not exist in cat /etc/group

Neither the user public in cat /etc/passwd

Found my problem!!

com2sec local     213.84.184.144/24   public

replaced with

com2sec local     213.84.184.144/32   public

I found the error with cat /var/log/net-snmpd.log

/etc/snmp/snmpd.conf

```
com2sec local     127.0.0.1/32    public 

com2sec local     213.84.184.144/24   public  #my external ipadres is this correct?

group MyROGroup v1         local 

group MyROGroup v2c        local 

group MyROGroup usm        local 

view all    included  .1                               80 

access MyROGroup ""      any       noauth    exact  all    none   none 

syslocation /wwwroot/stats.nl 

syscontact Webmaster <neutcomp@hotmail.com>
```

Hope someone can help me out?

http://neutcomp.xs4all.nl/stats.nl/

Its still not reporting anything  :Crying or Very sad: 

Thanxx

Bjorn   :Cool: 

----------

## HomerSimpson

Thanks for the howto

----------

## Tuinslak

 *his_royal_evilness wrote:*   

> smtp root # uname -rsv
> 
> Linux 2.6.4-gentoo-r1 #1 Sat Apr 3 09:05:56 CEST 2004
> 
> I managed to produce graphs for mem/swap 
> ...

 

finaly, a cfg that works :p

thx :p

now I just need to get that cpu cfg working... :/

 *brown wrote:*   

> 
> 
> Sorry, but I don't get this. How are you using these shell scripts in your cfg file? What does the Target line look like? And why do you have MemTotal and then MemFree in the first one, and the order is swapped for the Swap2.sh?

 

idem dito, didn't get it, but use the cfg from above, those work for me!

mrtg located here :p

now wait some time that it generates some stats, and then fix some other things (like me going from left to right, instead of right to left, and it's a bigger 'square' then the other ..)

and yes, my english sux :p

----------

## Tuinslak

I get this error when executing the cpu part:

```
Unknown SNMP var ssCpuRawUser.0

 at /usr/bin/mrtg line 1846

Unknown SNMP var ssCpuRawUser.0

 at /usr/bin/mrtg line 1846

WARNING: Expected a number but got '3:17:30'

WARNING: Expected a number but got 'zero.rootspirit.com'

Unknown SNMP var ssCpuRawSystem.0

 at /usr/bin/mrtg line 1846

Unknown SNMP var ssCpuRawSystem.0

 at /usr/bin/mrtg line 1846

WARNING: Expected a number but got '3:17:30'

WARNING: Expected a number but got 'zero.rootspirit.com'

Unknown SNMP var ssCpuRawNice.0

 at /usr/bin/mrtg line 1846

Unknown SNMP var ssCpuRawNice.0

 at /usr/bin/mrtg line 1846

WARNING: Expected a number but got '3:17:30'

WARNING: Expected a number but got 'zero.rootspirit.com'

ERROR: Target[cpu][_IN_] ' $target->[1]{$mode}  +  $target->[2]{$mode}  +  $target->[3]{$mode} ' (warn): Use of uninitialized value in addition (+) at (eval 8) line 1.

ERROR: Target[cpu][_OUT_] ' $target->[1]{$mode}  +  $target->[2]{$mode}  +  $target->[3]{$mode} ' (warn): Use of uninitialized value in addition (+) at (eval 9) line 1.

```

Any idea what's wrong?

----------

## skeezer

I get this error when running cpu.sh:

```
ERROR: Target[localhost.cpu][_IN_] ' $target->[0]{$mode} +ssCpuRawSystem.0&ssCpuRawSystem.' (warn): Ambiguous use of & resolved as operator & at (eval 7) line 1.

ERROR: Target[localhost.cpu][_OUT_] ' $target->[0]{$mode} +ssCpuRawSystem.0&ssCpuRawSystem.' (warn): Ambiguous use of & resolved as operator & at (eval 8) line 1.
```

What's reason for this and how it could be solved?

My cpu.cfg looks like this:

```
WorkDir: /var/www/localhost/htdocs/mrtg/cpu

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost+ssCpuRawSystem.0&ssCpuRawSystem.

0:public@localhost + ssCpuRawNice.0&ssCpuRawNice.0:public@localhost

RouterUptime[localhost.cpu]: public@localhost

MaxBytes[localhost.cpu]: 100

Title[localhost.cpu]: CPU Load

PageTop[localhost.cpu]: <H1>Active CPU Load %</H1>

Unscaled[localhost.cpu]: ymwd

ShortLegend[localhost.cpu]: %

YLegend[localhost.cpu]: CPU Utilization

Legend1[localhost.cpu]: Active CPU in % (Load)

Legend2[localhost.cpu]:

Legend3[localhost.cpu]:

Legend4[localhost.cpu]:

LegendI[localhost.cpu]:  Active

LegendO[localhost.cpu]:

Options[localhost.cpu]: growright,nopercent
```

Thanks for the answers

----------

## banderos

I had the exact same problem but managed to figure it out.

Basically it is a cut & paste problem....you will find there's carraige returns in the target line that shouldn't be there.

That's all!

----------

## cron0

Strange, media-libs/libgd do not exist anymore...

I've searched gentoo-portage.com and it's not there!

Could it have been replaced by app-sci/libgdgeda ?

```
*  app-sci/libgdgeda [ Masked ]

      Latest version available: 2.0.15

      Latest version installed: [ Not Installed ]

      Size of downloaded files: 510 kB

      Homepage:    http://www.geda.seul.org

      Description: libgdgeda - a PNG creation library for gEDA

      License:     GPL-2
```

Or else, where it is?

EDIT: Nevermind, it's media-libs/gd

----------

## HomerSimpson

Thanks for the howto. 

I have been running this for a few weeks now. Within the last week, and I don't remember what I did, I now get emails from cron that say:

```
ERROR: It looks as if you are running two copies of mrtg in parallel on

       the same config file. There is a lockfile (/etc/mrtg/ping.cfg_l) and it is

       is only 0 seconds old ... Check your crontab.

       (/etc/crontab and /var/spool/cron/root) 

run-parts: /etc/cron.mrtg/ping.sh exited with return code 17

```

what is wrong?

Thx

----------

## banderos

Just stop mrtg and delete all the *_l files in your working directory and the message should go away.

----------

## HomerSimpson

Thanks for your response.

I am not running mrtg as a daemon. I am running it from cron, as per the instructions. I did a 

```
ps aux | grep mrtg
```

to make sure nothing was running. There are no _l files in /etc/mrtg directory. I checked for hidden file also.

I will have to look deeper. I was hoping this was something easy.

Thanks for the idea.

----------

## HomerSimpson

OK. After thinking about it for 30 seconds I realized it is trying to run in parallel. For some reason the cronjob had been changed to have it run every 1 minute. I have change it back to every 5 minutes.

Thanks again for the help. It just didn't occur to me at first but now that I know, it is obvious.

Thx

----------

## Seather

Can anyone test the following, and see if the values are correct:

```

### Memmory Usage ###

Target[memory]:memTotalReal.0&memTotalReal.0:public@localhost - memAvailReal.0&memAvailReal.0:public@localhost - memCached.0&memCached.0:public@localhost

MaxBytes[memory]: 600000

Title[memory]: Physical memory usage

PageTop[memory]: <H1>Physical memory usage</H1>

Unscaled[memory]: ymwd

YLegend[memory]: Memory Usage

Legend1[memory]: Real memory in use

Legend2[memory]:

Legend3[memory]:

Legend4[memory]:

LegendI[memory]: real mem in use :

LegendO[memory]:

ShortLegend[memory]: B

kMG[memory]: K,M,G,T,P

Options[memory]: gauge,nopercent,transparent,noborder,growright
```

I do think that this works perfect with the 2.6 kernel and an updated snmp version, but I might be wrong. This also subtracts the reserved/cached/buffered ram (whatever you want to call it).

----------

## Tuinslak

Yes, it seems to work.

(http://tiete.ath.cx:1337/mrtg/memory.html edit: link is offline.)

edit: nop, doesn't work well, after some mrtg updated it starts telling my I got 1500mb ram (I got 512)

----------

## Seather

You can look at mine:

http://scygro.ath.cx/mrtg/memory.html

Anyone else tried it yet?

Mine seems to work, although, it hasn't gone past 331.9 mb on a 512mb machine. What can I use to really fill up all the ram and keep it filled? So we can test this?

----------

## Tuinslak

(re)emerge system or something :p

----------

## Seather

heh?

----------

## Tuinslak

 *Tuinslak wrote:*   

> (re)emerge system or something :p

 

-->  *Quote:*   

> What can I use to really fill up all the ram and keep it filled? So we can test this?

 

----------

## Seather

emerge system does definately not fill up 512mb?

----------

## heutger

I believe the easiest way to bring mem and swap into MRTG would be to use also therefore the already existing hrStorage-values, working fine for me as 4 is / (hd) the 2 is my mem and 3 is my swap. Verifying this values with the results of proc/meminfo they work correctly.

And to another recent question, to grow all values from right use growright  :Wink: 

----------

## SavageMindz

Ok I have two small questions...

1) Why does this not work. Trying to get the disk io in and out for a given partition.

```
cat io-disk.cfg

LoadMIBs: /usr/share/snmp/mibs/UCD-DISKIO-MIB.txt 

Target[localhost.diskio]: diskIOReads.3&diskIOWrites.3:public@localhost

RouterUptime[localhost.diskio]: public@localhost

MaxBytes[localhost.diskio]: 1000000000000000

WorkDir: /var/www/localhost/mrtg

Title[localhost.diskio]: DISK IO

PageTop[localhost.diskio]: <H1>DISK IO /home & /storage</H1>

ShortLegend[localhost.diskio]: bytes

YLegend[localhost.diskio]: DISK Utilization

Legend1[localhost.diskio]: /home disk

Legend2[localhost.diskio]: /storage disk

Legend3[localhost.diskio]: 

Legend4[localhost.diskio]:

LegendI[localhost.diskio]: No. of reads

LegendO[localhost.diskio]: No. of writes

Options[localhost.diskio]: growright,gauge,nopercent

```

On the scale iit flatlines at 1.0. That is both tha bar for reads and the line for writes. Suffice to say its a fairly busy drive so I don't believe the graph.

Btw on running this from the command line I get;

```
Use of uninitialized value in concatenation (.) or string at /usr/bin/../lib/mrtg2/SNMP_util.pm line 1266, <MIB> line 42.

Use of uninitialized value in concatenation (.) or string at /usr/bin/../lib/mrtg2/SNMP_util.pm line 1266, <MIB> line 158.

cannot encode Object ID .15.1.1.5.3: first subid too big in Object ID 15.1.1.5.3 at /usr/bin/mrtg line 1846

ERROR: Target[localhost.diskio][_IN_] ' $target->[0]{$mode} ' did not eval into defined data

ERROR: Target[localhost.diskio][_OUT_] ' $target->[0]{$mode} ' did not eval into defined data
```

Anyone know what I'm doing wrong.

Anyway on to muy other question. Given that the above example was working is there anyway for me to change the green filled line to just a line without fill (like the blue one) but keep the blue line as is. I want a graph with two lines drawn and no fill area. Been through the docs but I can't find any mention to this.

Everything else seems to work great. Thanks for the How-to.

Savage

EDIT: I should probably point out that I put the following in snmp.conf to specify the disks I want

```
disk   /   100000

disk   /home   100000

disk   /storage   100000

```

----------

## ranmakun

I've made an uptime graph, if anyone is interested:

uptime.cfg

```

WorkDir: /PATH/TO/MRTG

Title[localhost.uptime]: System Uptime

PageTop[localhost.uptime]: <H1>System Uptime</H1>

RouterUptime[localhost.uptime]: public@localhost

Target[localhost.uptime]: `/etc/mrtg/uptime.pl`

MaxBytes[localhost.uptime]: 50000

ShortLegend[localhost.uptime]: hours

Options[localhost.uptime]: growright,unknaszero,nopercent,gauge

LegendI[localhost.uptime]: Uptime

LegendO[localhost.uptime]:

Legend1[localhost.uptime]: Maximum uptime in hours

YLegend[localhost.uptime]: Time (hours)

```

uptime.pl

```

#!/usr/bin/perl

use warnings;

use strict;

my $uptime = `/usr/bin/snmpwalk -v 2c -c public localhost hrSystemUptime`;

$uptime =~ /\((\d+)\)/;

my $hours = $1 / 360000;

printf "%.0f\n",$hours;

printf "%.0f\n",$hours;

```

----------

## ranmakun

 *SavageMindz wrote:*   

> Ok I have two small questions...
> 
> 1) Why does this not work. Trying to get the disk io in and out for a given partition.
> 
> ```
> ...

 

Maybe, I don't know much about how to configure snmp, I've followed the guide in this thread, but in my machine snmpwalk doesn't show that MIB. Maybe you don't have it either and that's the error you get from MRTG "did not eval into defined data". I would really like a graph like this too.

To see all the MIBs in your machine run:

```
snmpwalk -v 2c -c public localhost
```

 *Quote:*   

> 
> 
> Anyway on to muy other question. Given that the above example was working is there anyway for me to change the green filled line to just a line without fill (like the blue one) but keep the blue line as is. I want a graph with two lines drawn and no fill area. Been through the docs but I can't find any mention to this.
> 
> 

 

I think that if you want to do that you should store MRTG data in rrd databases and make the graphs with rrdtool. I've never used MRTG with rrd's but I know it can be done. I use rrdtool frequently to make graphs from rrd databases and it's an excelent tool, you'll have the graphs exactly as you want them. I think there is a tutorial in this forum to use MTRG with rrdtool.

----------

## SavageMindz

ranmakun thanks for the info. I might give rrdtool a try when I have soem spare time.

Cheers

Savage

----------

## WillRivendell

hey ive never set up webserver in gentoo....

i instaleld mini_httpd and apache but its nothing like debian.

what file do i edit to show server where root doc is.... and where is the root doc i want?/

/var/www/localhost/www  ?? that where it is....

??

i want to be able to get to this remtoely..... 

thanks

----------

## ranmakun

 *WillRivendell wrote:*   

> hey ive never set up webserver in gentoo....
> 
> i instaleld mini_httpd and apache but its nothing like debian.
> 
> what file do i edit to show server where root doc is.... and where is the root doc i want?/
> ...

 

Not sure the default location, but the configuration of apache is in /etc/apache/conf/apache.conf for apache 1 and /etc/apache/conf/apache2.conf and /etc/apache2/conf/commonapache2.conf for apache 2

----------

## WillRivendell

Ok I got everythin working.... (memory displays at 2000Gb instead of 2000Mb.. but thats minor)

one issue I cant resolve is the DISKSPACE

I made the cfg but when I run the sh i get

```
ERROR: CFG Error Unknown Option "shortlegendlocalhost.partition-name[]" on line 8 or above.

           Check doc/reference.txt for Help

```

this did work without error once tho....problem is that how do I make it display a graph for it... what do i add to index page?

thanks

----------

## bgrade

my swap stopped working, it was working fine for ages and now it just reports 1k !?

http://28smith.com/mrtg/localhost.swap.html

i did do a lot of updates but dont know what might have broken it. 

the swap still seems to be runnign fine on the machine..

fry mrtg # cat /proc/meminfo

        total:    used:    free:  shared: buffers:  cached:

Mem:  1057538048 395091968 662446080        0 16900096 236806144

Swap: 1028149248        0 1028149248

MemTotal:      1032752 kB

MemFree:        646920 kB

MemShared:           0 kB

Buffers:         16504 kB

Cached:         231256 kB

SwapCached:          0 kB

Active:         146832 kB

Inactive:       189508 kB

HighTotal:           0 kB

HighFree:            0 kB

LowTotal:      1032752 kB

LowFree:        646920 kB

SwapTotal:     1004052 kB

SwapFree:      1004052 kB

any ideas?

fry mrtg # more /etc/mrtg/swap.cfg

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt

Target[localhost.swap]: memAvailSwap.0&memAvailSwap.0:public@localhost

PageTop[localhost.swap]: <H1>Swap Memory</H1>

WorkDir: /var/www/localhost/mrtg

Options[localhost.swap]: nopercent,growright,gauge,noinfo

Title[localhost.swap]: Free Memory

MaxBytes[localhost.swap]: 1000000

kMG[localhost.swap]: k,M,G,T,P,X

YLegend[localhost.swap]: bytes

ShortLegend[localhost.swap]: bytes

LegendI[localhost.swap]:  Free Memory:

LegendO[localhost.swap]:

Legend1[localhost.swap]: Swap memory avail, in bytes

EDIT: hmmm, and also fry 

mrtg # snmpwalk -v 2c -c public localhost memAvailSwap.0

UCD-SNMP-MIB::memAvailSwap.0 = INTEGER: 1004052

seems to return the correct figure..

----------

## defkewl

I can't view it via my webserver since the document root is located in /var/www/localhost/htdocs

----------

## GodMoney

Does anyone know how to get mrtg working with snmpv3 ?

----------

## anidabi

First I have to say that this is very good and easy HOWTO. Thanks for that.  :Smile: 

But I have a broblem. That being that mrtg doesn't generate the images for the web page. Actually it doesnt generate or have any images on the page, only the slots where they should be. Not even the mrtg advertisement at the bottom of the web page.  :Shocked: 

I did everything as told and I didn't get any errors what so ever, except "/usr/bin/mrtg: bad interpreter: No such file or directory" when running the scripts. In HOWTO there was said that ignore any errors concerning running the scripts, so I guess that it's perfectly normal? Or am I deeply lost on this one? Are those scripts the ones tha generate the images? Then I thought that maeby my snmp doesn't work, but when running this command "snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex", it showed all my ethernet ip's correctly for every ethernet devices. A bit stange is that I didn't change the snmpd.conf at all, still it did show my ip addresses correctly. Is that what it suppose to do?

Does anyone gnow what might be the broblem, have I missed something?

----------

## anidabi

I'm going to answer myself to my own question.  :Smile: 

n00b mode *ON*

That bad interpreter wans't what supposet to happen, and thank god for google. I found out that the /etc/cron.mrtg/*.sh files did have everything in same line. Of course it supposed to be that the #!/bin/sh has to be on it's own line and the rest on it's own. So here is a little pointer for those who have this same broblen and is running n00b mode *ON*.  :Cool: 

n00b mode *OFF*

----------

## Tuinslak

Some people pm'ed me for my mrtg cfg's and so on, so from now on I've set them online right here

With those configs you should be able to make these stats.

All credits go to whoever made parts of the config and the .sh or .pl script(s). most of it came from Google or Gentoo forums.

----------

## SilverOne

looking good!

I've got similar stats, just without the lm_sensor stuff.

Question:  I don't see you using uptime.cfg or the mrtg-countapps.sh,  any particular reason?

EDIT: looking back through this thread, I notice I haven't even thanked the author!

So I'd like to thank khazad-dum and the others in this thread for the excellent how-to!

I've been using the stats as a quick rundown of system status for a year now, and it works great!Last edited by SilverOne on Sat Apr 16, 2005 12:08 pm; edited 1 time in total

----------

## Tuinslak

I use mrtg-numprocs.sh instead of countapps (worked better I think)

And I dont use uptime.cfg because I couldn't set it to display monthly or yearly instead of daily (on mrtg.rootspirit.com).

When I changed the index (using indexmaker) it sets all scripts to yearly instead of only the uptime script.

----------

## SilverOne

That explains why I couldn't quickly determine what new functionality countapps would give  :Wink: 

thanks.

----------

## qriff

Should be (4 typo-errors):

```

LoadMIBs: /usr/share/snmp/mibs/HOST-RESOURCES-MIB.txt

WorkDir: /var/www/localhost/htdocs/mrtg

Target[localhost.partition-name]:hrStorageSize.1&hrStorageUsed.1:public@localhost

MaxBytes[localhost.partition-name]: 3000000

Title[localhost.partition-name]: Disk / Usage

PageTop[localhost.partition-name]: <H1>Disk / Usage</H1>

ShortLegend[localhost.partition-name]: B

kMG[localhost.partition-name]: k,M,G,T,P

kilo[localhost.partition-name]: 1024

YLegend[localhost.partition-name]: DISK / Utilization

Legend1[localhost.partition-name]: Root disk size

Legend2[localhost.partition-name]: Root disk usage

Legend3[localhost.partition-name]:

Legend4[localhost.partition-name]:

LegendI[localhost.partition-name]:  Root disk size

LegendO[localhost.partition-name]:  Root disk usage

Options[localhost.partition-name]: gauge,nopercent

```

corrected

 *khazad-dum wrote:*   

> Disk usage:
> 
> ```
> 
> /usr/bin/snmpwalk -v 1 -c public localhost | grep hrStorageDescr
> ...

 

----------

## qriff

I also recommend increasing the timeout for snmpwalking to 3 or more (retry times default to 5)...

```

snmpwalk -v 2c -t 3 -c public localhost > snmp-list.txt

```

----------

## [sinz]

used bits and pieces of this and it was extremely helpful, thanks.

----------

## hellraiser

I would want that they give all info of the net interfaces are  in kb and not in  bits

How to??

Sorry for my english...

----------

## zaphyr

Great HOW-TO!

Is there any way I can get to see the actual traffic...like which IP's I am connecting to and vice versa?

Thanks!

----------

## debak

wHEN I run this, i have an error, and i don't know why

******************************

```
cfgmaker --global "WorkDir: /var/www/localhost/htdocs/mrtg/" \

> --global "Options[_]: growright,bits" \

> --ifref=ip \

> public@localhost > /etc/mrtg/mrtg.cfg
```

I recieved:

```
SNMP Error:

no response received

SNMPv1_Session (remote host: "localhost" [127.0.0.1].161)

                  community: "public"

                 request ID: 332966126

                PDU bufsize: 8000 bytes

                    timeout: 2s

                    retries: 5

                    backoff: 1)

 at /usr/bin/../lib/mrtg2/SNMP_util.pm line 627

SNMPWALK Problem for 1.3.6.1.2.1.1 on public@localhost::::::v4only

 at /usr/bin/cfgmaker line 918

WARNING: Skipping public@localhost: as no info could be retrieved
```

***************************************************

Alghout /etc/mrtg/mrtg.cfg was created

What is wrong?  :Sad: 

I have NET-SNMP version: 5.2.1.2

THX for help

----------

## suprnaut

Hi guys. I have trouble running MRTG on my gentoo installation. 

I am running apache webserver and it works fine (the docs are located at /var/www/localhost/htdocs/).

I ran through the howto described first in this post, and I got no errors at all. *EDIT* When i run /etc/cron.mrtg/traffic.sh I get this error, saying: "bash: /etc/cron.mrtg/traffic.sh: Permission denied" - but it said in the howto to ignore warnings. .."

EDIT AGAIN (sorry, ftw) - my traffic.sh was not executable.. So i CHMOD it (700), ran it three times (got warnings), and it is working just fine.

I only followed the "traffic guide" though, as this is my main interest, thus only mrtg and net-snmp have been installed. When I come to think of it, maybe this is why I have the problem I have.. I'll post this reply anyways..

When I try to use http://colonel/mrtg (as colonel is the machine name) I have the option to press "localhost_eth0 Traffic Graph" as a link. When I do that, I am being redirected to http://colonel/mrtg/localhost_eth0.html, but that file is not present at all (404 Not Found) in the mrtg folder.

I saw in the source code of the mrtg/index.html that it was supposed to be an *.png file there, as an image, but it won't be displayed (it's not present in mrtg folder either).

What have I done wrong, and what can be done to show them stats?  :Wink:  I have read through this MRTG guide and the other one.. Couldn't find any answers.

----------

## lorano

I've tried 

 *Quote:*   

> 
> 
> /bin/cat -s > /etc/mrtg/traffic.cfg
> 
> WorkDir: /var/www/localhost/htdocs/mrtg
> ...

 

And I still don't get quite what I'm looking for. I'd like to monitor eth0 and eth1 just to watch the traffic between the two if possible. Eth0 is connected to my cable modem, and eth1 is connected up to my switch internal. Any way to do that?

----------

