logo banniere

S'il n'y a pas de solution c'est qu'il n'y a pas de problème!


MRTG



Introduction

This page gives some basic information about installation and configuration of MRTG under Linux. The reference page is MRTG.

Necessary tools and libraries

You need:

  • a C compiler (gcc or ecgs...)
  • a not too old perl version (at least 5.004_4)
  • snmp running as a daemon (Simple Network Management Protocol)

All these tools are usually available in most distributions. For snmp, I use ucd-snmp whichi is available in some distributions as a package. You can have a look at: http://net-snmp.sourceforge.net/.

Jean-Louis Noel proposed a script netstat for measuring interfaces input/output which does not require snmp. I think this is safer and easier to use this script if you do not need advanced function required by snmp. See further how to use it.

You also need gd from Thomas Boutell (www.boutell.com). I have here gd 1.8.4 .

To install gd, you need libpng, zlib and jpeg 6b at least. These libraries are generally available in most distributions. You can have a look at: Sinon, voir ftp://ftp.freesoftware.com/pub/infozip/zlib/ for zlib, ftp://ftp.freesoftware.com/pub/png/src/ for libpng, and http://www.ijg.org/ for jpeg.

Finally you need MRTG sources. I have here MRTG 2.9.17.

Be careful!

Check that you have an empty (if you trust you LAN end snmp port is closed from outside) config file snmp.conf in /etc or /usr/share/snmp (or elsewhere...), or containing:
com2sec readonly localhost public
Some distribution provides a default config file which does not allow MRTG to work as:
com2sec paranoid default public

gd installation

So, you already installed zlib, libpng and jpeg (sorry, I do not give explanations for these libraries, their installation is standart).

Uncompress (tar -zxf gd-1.8.4.tar.gz) gd source in (for example) /usr/local/src/. Go to gd directory and edit the Makefile. This is the part to edit:

COMPILER=gcc
AR=ar
CFLAGS=-O -DHAVE_LIBPNG -DHAVE_LIBJPEG -DHAVE_LIBXPM -DHAVE_LIBTTF
LIBS=-lgd -lpng -lz -ljpeg -lm -lttf
INCLUDEDIRS=-I. -I/usr/include/freetype -I/usr/include/X11 \
            -I/usr/X11R6/include/X11 -I/usr/local/include
LIBDIRS=-L. -L/usr/local/lib -L/usr/lib/X11 -L/usr/X11R6/lib
INSTALL_LIB=/usr/local/lib
INSTALL_INCLUDE=/usr/local/include
INSTALL_BIN=/usr/local/bin

Modify the lines COMPILER, CFLAGS, LIBS and INCLUDEDIR according to your configuration (read the comments in the Makefile and the readme.txt of gd, for freetype for instance). Setup INSTALL_LIB, INSTALL_INCLUDE et INSTALL_BIN if you want an install in other directories.

Run make and if there are no errors, run make install.

MRTG Installation

Uncompress (tar -zxf mrtg-2.9.17.tar.gz). From the MRTG directory run ./configure. If all is OK, you get a Makefile...after ordering MRTG CD (:-D). Now run make. Si le./configure a produit des messages d'erreur, lisez les, c'est qu'il vous manque des librairies ou outils de développement.
make install will install mrtg in /usr/local/mrtg-2

All the necessary pogrammes are in /usr/local/mrtg-2/bin.

MRTG configuration

In the directory /usr/local/mrtg-2/bin, there is a tool cfgmaker which builds a "beginning" of the configuration file. Go to a temp directory and run:

/usr/local/mrtg-2/bin/cfgmaker public@machine_name >test

where machine_name is the hostname of your machine. You get the list of your interfaces in the file test and the "beginning of a configuration file". You can see here the file test on my machine.

As you can see, there are 5 interfaces: loopback, dummy0, 2 ethernet and PPP0. For each interface, a name is proposed. In your final configuration file, you can (or should) change these names, you can also decide to not mention all these interfaces.

cfgmaker can also configure interfaces by their ip (option -ifref=ip). Run ./cfgmaker --help from the mrtg bin directory for a list of all options and have a look at all available documentation on MRTG website.

Chose a working directory (in your website root directory if you want ro give access to yout mrtg pages). Make a mrtg.cfg in this directory. Start with a line like WorkDir: /web/mrtg (or use a different directory fo logs, images and html with Logdir, Imagedir and Htmldir options, have a look at my config file) . Then copy the "pieces" of test which correspond to the interfaces you want to measure. Though in my file foo ppp0 was marked "unrealistic", it is the one I use!!

For each interface, you have to chose a name for each "target" order. Mrtg will generate a "name.html" file. Do not forget to copy the *.png Mrtg images from the Mrtg directory to to you Workdir or you Imagedir.

To know all the available option, have a look at the doc directrory in Mrtg install directory.

Run "mrtg mrtg.cfg" and look what happens... if all is OK, Mrtg created html files in Workdir or Htmldir. The two first run of Mrtg generate warning messages, they disappear at the third run. Now, you can run mrtg from a cron job in /etc/crontab. The default time intervall is 5 minutes. If you want to change this, you have to use Intervall keyword and change you cron job accordingly.

indexmaker (available in /usr/local/mrtg-2/bin) allows to make a page with access to your Mrtg pages.

You should read the doc about [_] which defines default options and [^] which defines "prefix" for targets and [$] whiche defines "suffix" for targets.
An example is better than long explanations, have a look at my config file on linux-sottises.

MRTG for pings and other tricks

Mrtg permits to make charts for "anything"! using some scripts. Do not forget to make those script "x" by chmod u+x.
You can see all the results of these script on the page stats_mrtg.
Remark: mrtg stats has been stopped on April 17 2002 as linux-sottises uses MRTNK which is based on RRDTOOL, you can have a look at the graphics generated by MRTNK.
The current stable version of MRTNK is available on the software page.
The development version (which is always the one used at linux-sottises) is available here.
For the moment, only the french documentation is avaliable for the development version in the doc directory.

PING.
It is target [ping_nerim] of my config file.
You can download ping-nerim script which gives min et max over 3 pings.

APACHE
Mrtg can also count the hits number on you Apache server (server-status and ExtendStatus must be enabled in your apache config file)
It is target [apache] in my config file.
The perl script is webstat.pl. This script can also measure apache traffic, look at the section [apache_byte of my config file.

To measure separatly hits and and traffic/documents of virtual hosts, I use mod_watch www.snert.com/Software/mod_watch/
You must hace compiled apache yourself.
There are 2 options of compilation of mod_watch, as a dynamic module if apache has been compiled with dynamic modules support, or statically. I only use mod_watch as a dynamic module and only have explanations for this compilation.
After downloading and compiling it, edit the Makefile. Modify to path to you apache sources in APACHEDIR, the path to the scripts used by mod_watch in SCRIPTDIR, the path of virtual servers logs in SPOOLDIR.
If apache apxs is not in your path, you have to modify APXS a little further in the Makefile. For example, for me it is:

APXS=/usr/local/apache/bin/apxs

Then run make install-dynamic
Check that mod_watch has been added up in your apache config file and that the module is effectly in libexec directory of you apache install directory.
Then add in you apache config file:

<IfModule mod_watch.c>
        <Location /watch-info>
        SetHandler watch-info
        </Location>
</IfModule>

Stop and start apache.
goto /watch-info on you server from your browser to check that mod_watch is active. Go to www.snert.com/Software/mod_watch/ for more details.
Have a look at my MRTG config file to have a look at the 4 mod_watch sections and stats_mrtg to see all the results.

UPTIME
For uptime I use perl script uptime.pl and the corresponding target is [uptime] in my config file.

PROCESS
To count the number of processes, I use the perl script stat.pl, target [procs] in my config file.

MEMORY
For memory, I use mem, target [mem] in my config file.

DNS
For DNS queries (bind V8), it is the same script as process number stat.pl, target [dns] in my config file.

CPU
For CPU, it is a bit more complex. The script is cpustat, target [cpu] in my config file. But, you need to install sysstat-4.0.3. Have a look at http://perso.wanadoo.fr/sebastien.godard/ systat author page. systat must be installed and regularly launched by cron.

NETWORK INTERFACES WITHOUT SNMP To measure interfaces without snmp, you can use netstat. Check cut, grep and uptime location. Usage is:
Target[target_ppp0]: `path_to_netstat target_ppp0 ppp0`
first parameter is the name of the target, the second one is the interface name.

David Du Serre-Telmon proposed another script netstat-ip which permits to call an interface by its IP.
Usage is straightforward: netstat target_name interface or netstat target_name ip ip_value.

OPEN FILES
A script proposed by 0_be_one counts the number of open files (you need lsof). The perl script is files.pl. Look at the section [files] of my config file.

DISK SPACE
A script from AIREY Romuald give disk space.
It is based on df command, example:

Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/sda3              8625436   3168832   5018432  39% /
/dev/sda1                23300      5193     16904  24% /boot
/dev/hda1             59084932  44493936  14590996  76% /mnt/idea
/dev/hdb1             38448276   9756360  26738816  27% /mnt/ideb
192.168.0.6:/          3984704    934288   2848000  25% /pluto
192.168.0.7:/          1921188    507476   1316120  28% /vador

option -m for Mo is used (for better readness and respect the max integer of MRTG, it is also advised to eliminate nfs file systems by -x nfs (if nfs servers are down, you will get problems with the script!).
df -m -x nfs :

Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/sda3                 8423      3089      4907  39% /
/dev/sda1                   23         6        16  24% /boot
/dev/hda1                57700     43452     14249  76% /mnt/idea
/dev/hdb1                37547      9528     26112  27% /mnt/ideb

The script checkdisk returns free and used disk space. Check df, cut and grep location.
checkdisk is used followod by the partition name, have a look at sections hda1, hdb1 and sda3 of my config file.
Have a look at the use of kMG which is required to avoid kMo in place of Go!!

DATA EXCHANGE AMOUNT ON AN INTERFACE
volume gives the amount of data exchanged on an interface.
As this tiny script is based on ifconfig, an interface down-up reset the statistics to 0,..., what I do not feel disturbing. The data appearing through ifconfig is also reset when some maximum is reached (I did no try to evaluate this maximum).
it is very easy to use: volume interface_name (have a look at volume_ppp0 of my config file and the results on stats_mrtg.

ACTIVE TCP CONNECTIONS WITH NETFILTER
This was contributed by David Du Serre-Telmon. The script is tcpcount.
use is:
tcpcount => total tcp connections through the gateway
tcpcount 21 => FTP connections
tcpcount 80 dst www.linux-sottises.net => web connections to www.linux-sottises.net
tcpcount 1214 src 192.168.0.2 => Kazaa connections fo user 192.168.0.2

If you have difficulties or questions, all email are welcome to tnka at linux-sottises.net.



Warning: strftime() [function.strftime]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2,0/DST' instead in /Library/WebServer/Documents/gabarit.php on line 107
Dernière modification le Jeudi 01 mai 2003 à 00:00:00 Paris
Webmaster: TNK