Multi Router Traffic Grapher

From ArchWiki
Revision as of 12:36, 14 January 2012 by Two oes (Talk | contribs) (resource monitoring)

Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Multi Router Traffic Grapher#)

Server Setup

this document assumes that you already have a Apache and net-snmp working and configured properly

The following should all be performed as root.

  • Install the necessary programs
# pacman -S mrtg perl-net-snmp
  • create an mrtg user
# useradd -d /srv/http/mrtg mrtg
  • create the user home directory and change the owner ship to the user
# mkdir /srv/http/mrtg/
# chown mrtg:mrtg /srv/http/mrtg

MRTG Setup

there are meny ways to configure the mrtg for your local server. this document will describe the must easest way to expend the application for other server and network appliances when and if needed.

The following should all be performed as the mrtg user we created.

  • create an HTML directory to hold the png files and the index.html file
# mkdir /srv/http/mrtg/html

now we will begin dealing with the application scripts first we will create a basic mrtg.cfg file

  • the next script will scan our localhost for it's interfaces and create for us the relevent configuration for each interface
# cfgmaker --output=/srv/http/mrtg/mrtg.cfg --ifref=name --ifref=descr --global "WorkDir: /srv/http/mrtg" public@localhost
  • the mrtg.cfg files contains all the server interfaces. we do not need the "lo" interface so we are going to delete it and edit the global configuration

mrtg.cfg Global configuration

remove the lines that are irrelevant to the interface and add the fallowing lines at the top:

### Global configuration  ###

LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
EnableIPv6: no
HtmlDir: /srv/http/mrtg/html
ImageDir: /srv/http/mrtg/html
LogDir: /srv/http/mrtg
ThreshDir: /srv/http/mrtg
RunAsDaemon: Yes
Interval: 5
Refresh: 600

the global configuration lines are :

1) to load the Linux MIB to the mrtg Applicaiton
2) to enable/disable IPv6
3) HTML home directory
4) the png files home directory
5) the log dir files locations
6) the Thres Directory
7) wether or not we want to run the application as a daemon , in this case : yes
8) the daemon interval (minimum 5 min)
9) the interval to refresh the html files

resource monitoring

now that we have the global configuration set we need to add the resources and devices we want to monitor.

in this tutorial we are going to monitor:

2)memory Usage
4)number of processes
5)Total TCP Established Connections
6)users count
7)the server mount points
8)the server interfaces

CPU Monitoring

for monitoring the CPU we need to add the next lines :

Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@ + ssCpuRawSystem.0&ssCpuRawSystem.0:public@ +\ 
RouterUptime[localhost.cpu]: public@
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: Active CPU Load %
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
LegendI[localhost.cpu]:  Active
Options[localhost.cpu]: growright,nopercent

Memory usage

to monitor the memory usage we need to add the next lines :

# get memory Usage
Target[localhost.memtotal]: ( . ) - \
( . )
PageTop[localhost.memtotal]: Memory Usage
Options[localhost.memtotal]: nopercent,growright,gauge
Title[localhost.memtotal]: Memory Usage
MaxBytes[localhost.memtotal]: 100000000
kMG[localhost.memtotal]: k,M,G,T,P,X
YLegend[localhost.memtotal]: bytes
ShortLegend[localhost.memtotal]: bytes
LegendI[localhost.memtotal]: Memory Usage: 
Legend1[localhost.memtotal]: Memory Usage, not including swap, in bytes
Colours[localhost.memtotal]: Blue#1000ff, Black#000000, Gray#CCCCCC, Yellow#FFFF00

Swap Usage

for swap usage add the fallowing lines :

# get swap memory
Target[localhost.swap]:( . ) - \
( .
PageTop[localhost.swap]: Swap Usage
Options[localhost.swap]: nopercent,growright,gauge,noinfo
Title[localhost.swap]: Swap Usage
MaxBytes[localhost.swap]: 100000000 
kMG[localhost.swap]: k,M,G,T,P,X
YLegend[localhost.swap]: bytes
ShortLegend[localhost.swap]: bytes
LegendI[localhost.swap]: Swap Usage:
Legend1[localhost.swap]: Swap memory avail, in bytes
Colours[localhost.swap]: Blue#1000ff,Violet#ff00ff,Black#000000, Gray#CCCCCC

in the title section some calculation are made. MRTG knows to calculate the values given from the OID

number of processes

for getting the number of processes running we are doing some unique here

# get number of processes running
Target[localhost.procs]: `/usr/local/mrtg/`
Title[localhost.procs]: Process Statistics
PageTop[localhost.procs]: Process Statistics
MaxBytes[localhost.procs]: 10000
YLegend[localhost.procs]: Processes  
LegendI[localhost.procs]:   Blocked Processes:
LegendO[localhost.procs]:   Run Queue:
Legend1[localhost.procs]: Number of Blocked Processes 
Legend2[localhost.procs]: Number of Processes in Run Queue
Legend3[localhost.procs]: Maximal Blocked Processes
Legend4[localhost.procs]: Maximal Processes in Run Queue
Options[localhost.procs]: growright, integer, nopercent, gauge

as we can see here we are calling the command that was written in Perl and returns an Integer which presence the number of processes.

the content of the command is :

open(COMD,"ps -ef | wc -l|");
$num = <COMD>;
print int($num);

established connections

in order to get a graph about established connections we are doing the way as the privies section :

# get number of established connections
Target[localhost.estconn]: `/usr/local/mrtg/`
Title[localhost.estconn]: Established connections
PageTop[localhost.estconn]: Established connections
MaxBytes[localhost.estconn]: 100000
YLegend[localhost.estconn]: Established connections
LegendI[localhost.estconn]:   Established connections: 
Legend0[localhost.estconn]: Number of Established connections: 
Options[localhost.estconn]: growright, integer, nopercent, gauge
Colours[localhost.estconn]: Red#FF0000,Blue#0066CC,Black#000000, White#FFFFFF

the content of the file is :

open(COMD,"netstat -an | grep ESTABLISHED | wc -l|");
$num = <COMD>;
print int($num);

users count

for the users count once again we are using a Perl script to create an integer output

for the mrtg configuration we need to add :

# get number of current users
Target[localhost.users]: `/usr/local/mrtg/`
Title[localhost.users]: logged in users
PageTop[localhost.users]: number of users
MaxBytes[localhost.users]: 100000
YLegend[localhost.users]: users count 
Legend0[localhost.users]: logged in users count: 
Options[localhost.users]: growright, integer, nopercent, gauge
Colours[localhost.users]: Red#FF0000,White#FFFFFF,Blue#0066CC,Black#000000

the file content is :

open(COMD,"w | grep -v load | grep -v USER | wc -l|");
$num = <COMD>;
print int($num);

monitor mount points

in order to monitor mount points we first need to make sure that SNMP is sending us the relevant information to check the mount point OID we need first to see all the mount points by the command :

snmpwalk -v 2c -c public localhost mount

this will display all of the server mount points and there mount location.

to monitor the mount point we want we need to take the last octet from the result and add it to the next 2 OID's


so the mrtg.cfg section for the root FS will look like this :

# monitor root FS 
Target[localhost.rootfs]: .
PageTop[localhost.rootfs]: Root FS Usage
Options[localhost.rootfs]: nopercent,growright,gauge,noinfo
Title[localhost.rootfs]: Root FS Usage
MaxBytes[localhost.rootfs]: 100000000
YLegend[localhost.rootfs]: Giga bytes
ShortLegend[localhost.rootfs]: bytes
LegendI[localhost.rootfs]: Root FS Usage:
Colours[localhost.rootfs]: Yellow#FFFF00, White#FFFFFF, Gray#CCCCCC, Blue#1000ff

Server interface

the server interface is outomaticly generated when we run the command.