SERVER : Install MRTG for TorrentFlux

, , , , , , , , ,

Now that I've installed torrent flux, i wanted to see some graphs with the upload/download speeds, so i could see just how fast I'm downloading.

For that i need to install MRTG (for more info look at this site).

So, run this commands in the shell
apt-get install mrtg mrtgutils mrtg-contrib
It will ask you if you really want to install it since it will need to download about 8Mb of files, just answer with Y.
After the installation is done, it will ask you if you want to let only the MRTG user read the config file, you should answer with Yes
After a few seconds you end up back at the prompt with
Setting up mrtg (2.14.3-1) ...

Setting up mrtg-contrib (2.14.3-1) ...
lines above the prompt.
This means that we've installed MRTG.

Now lets configure TorrentFlux to use the MRTG.

Go to the folder where you downloaded and extracted the torrentflux archive and there's an addons/mrtg folder, get into it. If you've extracted the file in your home folder, simply execute this :
cd ~/torrentflux-b4rt_1.0-alpha5/addons/mrtg
.

Now, if you look inside (for example with ls command, you'll see a few files :
flux-mrtg.conf       
fluxpoller.pl  
mrtg.flux.examples.cfg
flux-mrtg-update.sh  
mrtg.flux.cfg


Now we need to customize this files to suit our needs.
First, we need to modify the flux-mrtg.conf file.
editor flux-mrtg.conf

now modify the FLUXPATH to be the folder where you set TorrentFlux to download the files to (in my case it's /mnt/d/Torrents) you should leave the rest of the settings as they are.
You should end up with something similar to this :
# $Id: flux-mrtg.conf 672 2006-09-10 12:29:05Z b4rt $

# set all lines after "CHANGEME" (get a list with: "grep -A 1 CHANGEME this")

# flux-path (aka "Path" in flux-settings)
# CHANGEME
FLUXPATH="/mnt/d/Torrents/"

# path to mrtg-conf-file.
# wherever this is, ensure directory is writable for the user running this
# script (-> user running mrtg) (mrtg creates a lockfile at its conf-file(s))
# CHANGEME
CONFFILE="/etc/mrtg/mrtg.flux.cfg"

# where is mrtg
# CHANGEME
BIN_MRTG="/usr/bin/mrtg"


Now we need to modify the mrtg.flux.cfg file too so execute
sudo editor mrtg.flux.cfg
and search for
Target[traffic]: `/usr/local/bin/fluxpoller.pl traffic /usr/local/torrentflux mrtg`
you must modify the /usr/local/torrentflux to be the folder you've set for the downloads, in my case it will be
Target[traffic]: `/usr/local/bin/fluxpoller.pl traffic /mnt/d/Torrents mrtg`


Now we need to create the folder where MRTG will save its data, for that execute this commands :
sudo mkdir /usr/local/torrentflux
sudo mkdir /usr/local/torrentflux/.mrtg
sudo chown -R www-data:www-data /usr/local/torrentflux
sudo chmod -R 777 /usr/local/torrentflux

This will create the folder, make it writable and owned by the Apache user (www-data).


Now we need to copy the files to their right place.
For that, execute this commands :
sudo mkdir /etc/mrtg
sudo cp flux-mrtg.conf /etc/mrtg
sudo cp mrtg.flux.cfg /etc/mrtg
sudo cp flux-mrtg-update.sh /usr/local/bin/
sudo cp fluxpoller.pl /usr/local/bin/



Now the MRTG should be configured, we should try it out, so execute this :
/usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf

If you get the following error :
-----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
       variable LANG is set to UTF-8. Please run mrtg in an environment
       where this is not the case. Try the following command to start:

       env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.flux.cfg
-----------------------------------------------------------------------
then we need to modify flux-mrtg-update.sh, so execute this
sudo editor /usr/local/bin/flux-mrtg-update.sh

Now go to the last line and edit it to look like this :
# invoke mrtg for flux
env LANG=C $BIN_MRTG $CONFFILE | tee -a $FLUXPATH/.mrtg/mrtg.log
save the file, exit and try it again
/usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf


You should get some errors that it can't remove or rename some files, that's ok
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup could not read the primary log file for traffic
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup The backup log file for traffic was invalid as well
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't remove traffic.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't rename traffic.log to traffic.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup could not read the primary log file for connections
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup The backup log file for connections was invalid as well
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't remove connections.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't rename connections.log to connections.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup could not read the primary log file for loadavg
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup The backup log file for loadavg was invalid as well
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't remove loadavg.old updating log file
09-01-2007 18:29:52, Rateup WARNING: /usr/bin/rateup Can't rename loadavg.log to loadavg.old updating log file
just run the aboce command 3 times and after that it should execute without giving any warning at all.

Now look in the mrtg folder (/var/www/mrtg) and there should be 2 INC files and some PNG files.
ls /var/www/mrtg
should return something like this :
connections-day.png    connections-year.png  loadavg-week.png  mrtg-r.png       traffic-month.png
connections.inc        loadavg-day.png       loadavg-year.png  mrtg-ti.png      traffic-week.png
connections-month.png  loadavg.inc           mrtg-l.png        traffic-day.png  traffic-year.png
connections-week.png   loadavg-month.png     mrtg-m.png        traffic.inc

Now we also need to tell torrentflux where to look for those images, for that you should do
sudo rm -r /var/www/torrentflux/mrtg/
cd /var/www/torrentflux
ln -s /var/www/mrtg
this will create a simbolyc link so that /var/www/torrentflux/mrtg will actually be /var/www/mrtg

Now we need to make shore the poller will be called periodically to update the data, so we need to add a new cron entry. (Cron is a program that executes commnds on a timed bases).
So, for that you need to edit the Cron settings for the Apache Web user (www-data in Ubuntu), so execute this :
sudo crontab -e -u www-data
in the editor paste this information
# invoke mrtg-update every 5 mins
*/5 * * * * /usr/local/bin/flux-mrtg-update.sh /etc/mrtg/flux-mrtg.conf> /var/log/mrtg/mrtg_cron.log

In some cases the script doesn't have access to some folders, so we should give it access.
For that you'll need to do the following
sudo chown www-data:www-data /var/lock/mrtg/
sudo chown www-data:www-data /var/www/mrtg
mkdir /var/log/mrtg
sudo chown www-data:www-data /var/log/mrtg
sudo chown -R www-data:www-data /mnt/d/Torrents/.mrtg

Now, if everything went well you'll have a working MRTG, so when you press the Graph button on FluxTorrent's main page you'll end up with some nice graphics, something like :

Of course, the image shows a very small amount of traffic accounting, after all i just started MRTG, in time it will be completely filled. You just have to wait for some time to pass before the graphic will be really visible, after all, the first graphic is updated every 5 minutes, the second every 30 minutes, the next one every 2 hours and the last one once a day.

idea If you have images showing up, but do not get any data in the image, and you did wait at least 20-30 minutes, then there could be 2 reasons.
  1. You don't have any traffic. You should make shore you're downloding or uploading something, or you won't get any traffic, after all, your traffic is 0
  2. You didn't set the correct folder for where you're downloding to.


To check if the path has been correctly set, open up the mrtg.flux.cfg file and search for
Target[traffic]: `/usr/local/bin/fluxpoller.pl traffic /mnt/d/Torrents mrtg`
, copy the text between the ' signs and execute it in a console. You should get a response like :
17408
28672
14:26,  1 user
server_name

If the first 2 rows are 0 then either you've got no connection, or the path is wrong. The path must be the path that's set in TorrentFlux, to see what's the path, go to the torrentflux page on your server, press the admin button (upper right corner - red rectangle in the picture), press the Server button (green rectangle in the piture) and look at what's set in Path (pink rectangle in the picture).
If the path set here is different than what you had in the mrtg.flux.cfg file, please copy this path and replace the path from the file.

SERVER : Install TorrentFluxSERVER : Install CACTI (or at least try to :-))

Comments

plastilincheg Tuesday, October 20, 2009 3:03:38 PM

Hm. Doesn`t work... Torrentflux-b4rt 1.0-beta2. System Debian Lenny.

Write a comment

You must be logged in to write a comment. If you're not a registered member, please sign up.