MRTG - fun with 20th century monitoring solution

I’m totaly aware there are more modern monitoring solutions (prometheus, icinga2, prtg and other hipster stuff) out there. Despite this, I still like MRTG’s minimalist approach.

(my) setup

In my configuration MRTG is solely used for collecting metrics from various sources. MRTG is very flexible where these metrics come from (snmp, curl, scripts …). My current configuration can be found at https://git.br0tkasten.de/br0tkasten/mrtg

backend

installation

In Alpine, mrtg can be installed with apk add mrtg.

configuration

Details on mrtg’s config can be found in the projects online documentation. You will find my configs in my git project.

Example:

1
2
3
4
5
6
7
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
WorkDir: /var/www/mrtg/rrd
LogFormat: rrdtool

Target[br0tkasten.eth0]: #eth0:oom6faayaTosh0nizoepoonahCohhahy@10.3.0.1:
Title[br0tkasten.eth0]: [br0tkasten] eth0 
MaxBytes[br0tkasten.eth0]: 4294967295

frontend

cgi-bin/graph.pl

A perl script is generating graphs from rrd using templates for each metric.

1
<img alt="br0tkasten.eth0 Traffic Graph" src="/cgi-bin/graph.pl?width=680&height=200&graph=br0tkasten.eth0">
Parameter
  • graph: name of the metric, the script will look for a template with the same name in tmpl/*.tmpl
  • width & height: dimensions of the returned image in pixel

Templates

For each metric to be displayed you will have to create a template in tmpl/metric.tmpl. Templates use rrdgraph syntax. More details can be found at the projects online documentation

Example: tmpl/br0tkasten.eth0.tmpl

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
-v in/up bps 
-t [br0tkasten] eth0
--full-size-mode
--color=BACK#343637
--color=CANVAS#F0F0F0
--color=FONT#F0F0F0
--font=TITLE:12:DejaVu Bold
DEF:d=/var/www/mrtg/rrd/br0tkasten.eth0.rrd:ds0:AVERAGE
DEF:u=/var/www/mrtg/rrd/br0tkasten.eth0.rrd:ds1:AVERAGE
CDEF:down=d,8,*
CDEF:up=u,-8,*
AREA:down#CC9A5780:Down
AREA:up#2EA34960:Up
LINE1:down#CC9A57
LINE1:up#2EA349
LINE1:0#000000

cgi-bin/details.pl

Renders tmpl/details.tmpl to display a html page with a bigger version of the graph. Using rrdGraphJs you can interactively zoom and scroll in your graph.

html

Graphs are embedded in static (and some dynamically generated) html pages. I like to keep things simple - so most content is static. Examples can be found in htdocs.

1
2
3
4
5
6
<div>
	<b>[br0tkasten.de] eth0</b><br/>
	<a href="/cgi-bin/details.pl?graph=br0tkasten.eth0">
        <img alt="br0tkasten.eth0 Traffic Graph" src="/cgi-bin/graph.pl?width=680&height=200&graph=br0tkasten.eth0">
    </a>
</div>
0%