Categories
Linux Software www

Bind mrtg stats

Because I couldn’t find any that worked.

(Dark blue: incoming queries, light blue: outgoing/recursive lookups)

mrtg.cfg sample:

# Bind
Title[bind]: Bind Queries
Target[bind]: `/etc/mrtg/bind-stats.sh`
PageTop[bind]: <H1> Bind queries per minute on vm1 </H1>
Options[bind]: growright,pngdate,nobanner,gauge,nopercent,noinfo
MaxBytes[bind]: 50000
Ylegend[bind]: Queries/min
ShortLegend[bind]:  queries/min
LegendO[bind]: Incoming Bind queries per minute
LegendI[bind]: Outcoing Bind queries per minute
Legend2[bind]: Incoming Bind queries per minute
Legend1[bind]: Outcoing Bind queries per minute

bind-stats.sh:

#!/bin/bash
# Bind MRTG stats
# by Yeri Tiete (Tuinslak) - 10/02/2011
# https://yeri.be
#
# mrtg.cfg sample:
################################################################################
#	#
#	# Bind
#	#
#	Title[bind]: Bind Queries
#	Target[bind]: `/etc/mrtg/bind-stats.sh`
#	PageTop[bind]: <H1> Bind queries per minute on vm1 </H1>
#	Options[bind]: growright,pngdate,nobanner,gauge,nopercent,noinfo
#	MaxBytes[bind]: 50000
#	Ylegend[bind]: Queries/min
#	ShortLegend[bind]:  queries/min
#	LegendO[bind]: Incoming Bind queries per minute
#	LegendI[bind]: Outcoing Bind queries per minute
#	Legend2[bind]: Incoming Bind queries per minute
#	Legend1[bind]: Outcoing Bind queries per minute
################################################################################

# file path of named.stats
FILE=/var/log/named.stats
TMPFILE=/tmp/__dnsstats.txt

# how often does mrtg run? for me it's every 10 mins
TIME=10

# make file empty
echo /dev/null > /var/log/named.stats

# generate file
/usr/sbin/rndc stats

# save number of queries
INNOW=`egrep "[^I]QUERY" $FILE | awk '{print $1 }'`
OUTNOW=`grep Outgoing $FILE -A 9 | sed '1,2d' | awk '{ SUM += $1} END { print SUM }'`

# check if tmp file exists and insert data in it if it doesnt
# this prevents a peak
[ ! -e $TMPFILE ] && echo $INNOW > $TMPFILE && echo $OUTNOW >> $TMPFILE

# get old data
INOLD=`cat $TMPFILE | sed -n 1p`
OUTOLD=`cat $TMPFILE | sed -n 2p`

# overwrite old
echo $INNOW > $TMPFILE
echo $OUTNOW >> $TMPFILE

# calculate (to get difference)
INDIFF=$[ $INNOW-$INOLD ]
OUTDIFF=$[ $OUTNOW-$OUTOLD ]

# as mrtg runs */10 > divide by 10 to get per minute
INPERMIN=$[ $INDIFF/$TIME ]
OUTPERMIN=$[ $OUTDIFF/$TIME ]

# print !
echo $OUTPERMIN
echo $INPERMIN
echo
echo

Or download the file riiiiiight here.

Be sure the named.stats file gives this kind of output:

# grep Outgoing /var/log/named.stats -A 9
++ Outgoing Queries ++
[View: default]
               64316 A
                   2 NS
                  22 SOA
                6945 PTR
                 892 MX
                1104 TXT
                3117 AAAA
                  22 SRV

… for the outgoing queries, and …

# grep QUERY /var/log/named.stats | awk '{print $1 }'
163143

for the incoming queries.

Don’t forget to

chmod +x bind-stats.sh

Live sample: vm1.rootspirit.com/mrtg/bind.html

Categories
Hardware Linux Misc Networking Software www

Squid MRTG stats

I talked about MRTG stats for Squid in the past but apparently forgot to include the .mib file.

So, here it is. Download this file and put it in /usr/share/squid/mib.txt.

I don’t quite remember where I found that mib file. Probably included with Squid on Gentoo or the world wide web… But I couldn’t find it on Debian, so here it is. And be sure to add these lines to your Squid config:

acl snmppublic snmp_community public
snmp_port 3401
snmp_access allow snmppublic all

This is what it should look like (low usage Squid):

Categories
Hardware Linux Misc Networking Software www

MRTG and network interfaces

I tend to restart OpenVPN a lot due to config changes. As a result, this brings quite some issues to MRTG (or more precisely, SNMP), due to the fact tun devices change of ID.

A while back, I found a quick fix for this; rename the interface targets from their respective ID to their name:

Target[eth0]:ย 2:[email protected]

becomes

Target[eth0]:ย #eth0:[email protected]
For example:
#
# Eth0 stats
#
Options[eth0]: growright, nobanner, pngdate, nopercent, noinfo
Target[eth0]: #eth0:[email protected]:
SetEnv[eth0]: MRTG_INT_DESCR="eth0"
MaxBytes[eth0]: 1250000
Title[eth0]: Traffic Analysis for deng
PageTop[eth0]: <H1>Traffic Analysis for deng (eth0)</H1>
#
# Eth1 stats
#
Options[eth1]: growright, nobanner, pngdate, nopercent, noinfo
Target[eth1]: #eth1:[email protected]:
SetEnv[eth1]: MRTG_INT_DESCR="eth1"
MaxBytes[eth1]: 1250000
Title[eth1]: Traffic Analysis for deng
PageTop[eth1]: <H1>Traffic Analysis for deng (eth1)</H1>
#
# tun0 stats
#
Options[tun0]: growright, nobanner, pngdate, nopercent, noinfo
Target[tun0]: #tun0:[email protected]:
SetEnv[tun0]: MRTG_INT_DESCR="tun0"
MaxBytes[tun0]: 1250000
Title[tun0]: Traffic Analysis for deng
PageTop[tun0]: <H1>Traffic Analysis for deng (tun0)</H1>
Categories
iRail Linux Networking Software www

iRail slashdot effect

Only because stats are pretty awesome. The effects of my media attention a few days ago. I’ll give some more info than what can be seen here.

And pretty happy I set up my nginx caching up a few weeks ago.

MRTG traffic stats on vm1, my nginx caching server, of the first 2 days (only major traffic source is this blog):

Top referrers (though not 100% accurate):

Website hits:

Top posts last few days:

Flickr hits last few days:

Screenshots are all a few days old by the way.

This, and a bunch of other cool stats from Google Analytics. ๐Ÿ™‚

Oh, and also, visits on iRail.be from the NMBS/SNCB network starting Sept 1 2008:

Categories
Hardware Misc Networking Software www

MRTG

As I often have people asking for the files I use to make my pretty MRTG graphs; I’ll publish them here.

Here are some examples:

ZeroOneFourvm1Sauron

The config files:

Sauron (including Squid stats),

Zero (including fan stats).

List of files included:

  • indexmaker; simple script (included with MRTG) to generate a simple index file with all the graphs
  • snmp-if.sh; will show you the IDs of the interfaces on the server/pc. These IDs have to be edited in the mrtg.cfg file; e.g.:

Target[eth0]: 2:[email protected]:

Make sure 2 is indeed the ID of eth0. Be aware that virtual interfaces, like the TUN/TAP interfaces (using by openVPN for example), can change ID each time they are restarted/rebooted.

  • mrtg.cfg; check the config file as an example.
  • mrtg-<xyz>.sh; bunch of files to generate some data. Not all ofย  those still work, but I haven’t deleted them yet in case. See the config to check those I’m using.
  • mrtg._1 and mrtg.ok can be deleted/ignores. Those files are generated by MRTG and I was to lazy to remove them. ๐Ÿ™

  • Some day, I’ll write a decent howto, but for now, you’ll have to do with this.

    If there’s any question, just leave a comment.