some stuff glued together to integrate mrtg into torrentflux. i tried to stay as simple as possible to make integration easy. (and it is complete non-destructive to tf-code in its current form). the default-config/setup uses mrtgs rateup (no rrd). (my fluxpoller.pl-data-gatherer also supports cacti output-format for ppl with running rrd+cacti systems)
the implementations are smart enough that it is possible to add/delete mrtg-targets without changing a line of code only by configuring the targets in the mrtg-target-config-file (mrtg.flux.cfg).
requires:included:- fluxpoller.pl : data-gatherer (see this thread)
- flux-mrtg-update.sh : shell-script that is invoked from cron
- flux-mrtg.conf : config-file for mrtg *changes needed*
- mrtg.flux.cfg : file with mrtg-target-definitions *changes needed*
- mrtg.php : "frontend" for the graphs
- mrtg.sql : sql-file to enable the mrtg-frontend
defined graphs:- traffic : graph of incoming + outgoing flux-traffic
- connections : graph of flux-tcp-connections (sum)
setup:1. pre-requisites1.1 install mrtg http://oss.oetiker.ch/mrtg/2. set up mrtg2.1 create required dirscreate a directory with the name
mrtg in your flux-docroot-dir.
(on a default 2.1 that would be
/var/www/mrtg)
ensure the user running your webserver is able to write to this dir (create files in it).
2.2 setup my scriptscopy my scripts to a place you like. in the default-config the locations are:
fluxpoller.pl : /usr/local/bin/fluxpoller.plflux-mrtg-update.sh : /usr/local/bin/flux-mrtg-update.shensure these scripts are executable by the user running your webserver.
2.3 setup config(-files)copy the config files to a place you like.
in the default-config the locations are:
mrtg.flux.cfg : /etc/mrtg/mrtg.flux.cfg
flux-mrtg.conf : /etc/mrtg/flux-mrtg.confensure these files are readable by the user running your webserver.
ensure the user running your webserver can create a file in that dir. (mrtg creates a lock-file besides its config-files)
edit the two files and adjust it to your installation.
all places that (maybe) have to be adjusted are flagged with the string "CHANGEME".
exactly : every line after a CHANGEME may need adjustments.
tip: for "lists" do "grep -A 1 CHANGEME flux-mrtg.conf" and "grep -A 1 CHANGEME mrtg.flux.cfg"
2.4 init+test mrtgat this stage your mrtg is (should be~) ready to go. to test it and because mrtg will complain about its logs the first 3 invocations my advice is to get things started by hand.
call as the user running your webserver (adjust paths if needed):
/usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf
if the only errors/warnings are about logfiles then it looks good.
do the call until you dont get any output anymore.
to control that things are right at this point check these dirs (referencing default-config):
/var/www/mrtg : should contain 2 .inc files and some pngs
/usr/local/torrent/.mrtg : should contain mrtg-logs and rateups "flat-file-db"
2.5 setup cron-jobwhereever you define your custom-cronjobs.. add this one (paths = default-config, webserver-user/user doin mrtg-stuff is
www-data) adjust if needed):
# invoke mrtg-update every 5 mins
*/5 * * * * www-data /usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf &> /dev/null
3. integrate into torrentflux3.1 sqluse the included
mrtg.sql3.2 setup "frontend"copy the file
mrtg.php to flux-document-root (default :
/var/www)
3.3 changes in file config.phpadd this line:
define('_ID_MRTG','Graph');
3.4 changes in file index.phpits up to you where you link to
mrtg.php. what i use is :
look for this:
<a href="who.php">
and add
above:
<?php
if ($cfg['enable_mrtg'] == 1) {
echo '<a href="mrtg.php">';
echo '<img src="images/all.gif" width="16" height="16" title="" border="0" align="absmiddle">';
echo _ID_MRTG;
echo '</a>|';
}
?>
4. doneyou made it, time to lean back and enjoy your graphs

EDIT:
i attached new screenies after my setup was running for a while. still unimpressive because my torrent is kinda idle atm.
EDIT-2:
5. Examples for additional Graphs (targets) :maybe some of you want to graph more than just traffic + connections so here are some examples to start with.
i didnt test any of these !for that kind of stuff (stuff not really being flux but being system itself) i use a much more sophisticated rrd-based solution.
(if interested :
rrd:
http://oss.oetiker.ch/rrdtool/ cacti:
http://www.cacti.net/ )
- of course you need a tool to gather and output the data in a format mrtg can read. fluxpoller.pl only supports traffic+connections so thats up to you. just do a google-search, there exist tons of these tools. the ones i use in the examples actually really exist and might be a start to search for.
- of course you have to adjust these examples for your system.
- quite sure you have to adjust the graph-settings to get "nice-looking" graphs.
- you dont have to change any code when adding graphs (targets) if you use my hack as suggested. just add the new graphs (targets) in mrtg.flux.cfg (mrtg.php is smart enough to recognize new graphs and flux-mrtg-update.sh allways updates all anyway)
to add a graph (=target) add it at the end of
mrtg.flux.cfg .
Example : Graphing the Load Average# ------------------------------------------------------------------------------
# target : loadavg
# ------------------------------------------------------------------------------
# gather data for this target
# CHANGEME
Target[loadavg]: `/usr/bin/mrtg-load -m 1000`
# MaxBytes
MaxBytes[loadavg]: 50000
# 1 kilo def
kilo[loadavg]: 1000
# title
Title[loadavg]: loadavg
# title in the graph
PNGTitle[loadavg]: loadavg
# options.
Options[loadavg]: gauge,integer,growright,nobanner,nopercent,pngdate,transparent
# peaks
WithPeak[loadavg]: ym
# legend
YLegend[loadavg]: loadavg
ShortLegend[loadavg]:
# ....
Example : Graphing apache stats# ------------------------------------------------------------------------------
# target : apachestats
# ------------------------------------------------------------------------------
# gather data for this target
# CHANGEME
Target[apachestats]: `/usr/bin/mrtg-apache -m 100 localhost`
# MaxBytes
MaxBytes[apachestats]: 20000
# 1 kilo def
kilo[apachestats]: 1000
# title
Title[apachestats]: apachestats
# title in the graph
PNGTitle[apachestats]: apachestats
# options.
Options[apachestats]: gauge,integer,growright,nobanner,nopercent,pngdate,transparent
# peaks
WithPeak[apachestats]: ym
# legend
YLegend[apachestats]: loadavg
ShortLegend[apachestats]:
# ....
Example : Graphing CPU-Temperature (needs sensors !)# ------------------------------------------------------------------------------
# target : sensors_temperature
# ------------------------------------------------------------------------------
# gather data for this target
# CHANGEME
Target[sensors_temperature]: `mrtg-sensors -m 800 dummy dummy w83781d-i2c-0-2d Temp`
# MaxBytes
MaxBytes[sensors_temperature]: 10000
# 1 kilo def
kilo[sensors_temperature]: 1000
# title
Title[sensors_temperature]: sensors_temperature
# title in the graph
PNGTitle[sensors_temperature]: temperature
# options.
Options[sensors_temperature]: gauge,integer,growright,nobanner,nopercent,pngdate,transparent,bits
# peaks
WithPeak[sensors_temperature]: ym
# legend
YLegend[sensors_temperature]: temperature
ShortLegend[sensors_temperature]:
# ....
Example : Graphing CPU-Fans (needs sensors !)# ------------------------------------------------------------------------------
# target : sensors_fans
# ------------------------------------------------------------------------------
# gather data for this target
# CHANGEME
Target[sensors_fans]: `mrtg-sensors -m 400 w83781d-i2c-0-2d FanCPU1 w83781d-i2c-0-2d FanCPU2`
# MaxBytes
MaxBytes[sensors_fans]: 100000
# 1 kilo def
kilo[sensors_fans]: 1000
# title
Title[sensors_fans]: sensors_fans
# title in the graph
PNGTitle[sensors_fans]: fans
# options.
Options[sensors_fans]: gauge,integer,growright,nobanner,nopercent,pngdate,transparent,bits
# peaks
WithPeak[sensors_fans]: ym
# legend
YLegend[sensors_fans]: fans
ShortLegend[sensors_fans]:
# ....
EDIT: new example
Example : Graphing disk-usagedidnt even think of this so far because i do disk-usage-graphing with cacti. (so i dont even know a tool like "mrtg-du" but writing that if none can be googled should be no big deal.)
so if you want to graph the disk-usage of the torrent-dir a config to start with may be:
# ------------------------------------------------------------------------------
# target : disk_usage
# ------------------------------------------------------------------------------
# gather data for this target
# CHANGEME
Target[disk_usage]: `/usr/local/bin/foo.bar /usr/local/torrent`
# flux torrent dir capacity
MaxBytes[disk_usage]: 100000000000
# 1024 bytes are 1 kilo
kilo[disk_usage]: 1024
# title
Title[disk_usage]: disk_usage
# title in the graph
PNGTitle[disk_usage]: disk_usage
# options.
Options[disk_usage]: gauge,growright,nobanner,pngdate,transparent
# peaks
WithPeak[disk_usage]: ym
# legend
YLegend[disk_usage]: Disk-Usage
ShortLegend[disk_usage]:
# ....
happy graphing,
b4rt