Web Development

Monitor connectivity with SmokePing, part 2


Following on from my post earlier this week, I’m going to show you how to install and configure SmokePing. I've already covered some of the reasons you may want to have a monitoring system such as SmokePing and laid the groundwork for it by installing RRDtool, SpeedyCGI, and FPing.

Digging straight in, the first thing to do is download the SmokePing source package. The current release is version 2.2.2; as SmokePing is actually scripted in Perl, we don’t need to compile anything. Unpack the archive in your chosen location; I opted for /opt/smokeping but you can do it anywhere you like. Remember that SmokePing will be running from this location, so don’t put it in a place where it may be accidentally deleted later on.

Before we go any further, it’s probably a good idea to make sure that your Perl installation is up to date. I would recommend checking that the HTTP::Request module is installed; I didn’t have this installed by default and it took me a little while to work out what the problem was:

# cpan
cpan[1]> install HTTP::Request
HTTP::Request is up to date (1.40).

If HTTP::Request wasn’t previously installed or is out of date then it will now be installed, if it’s already up to date you’ll see the message above.

Unpacking the SmokePing archive will leave you with a few directories:

bin - Contains the main Smokeping Perl script

doc - Documentation

etc - Sample configuration files

htdocs - Contains the Smokeping CGI script

lib - Libraries

util - Contains the fix-pod2html script

I would suggest creating three more directories: data to hold the RRDtool databases, htdocs/cache to hold the cached graph images, and var to hold the pid file. Make sure permissions allow Apache to read the htdocs directory and to read/write in htdocs/cache.

Now that everything is unpacked, start by editing the file bin/smokeping. Create a copy of smokeping.dist and keep the original as a backup (just in-case). At the top of this file, you will see a line that needs to match up with your Perl binary location and a couple of lines that point to various libraries required by SmokePing. Make sure that one of these points to the Smokeping libs directory and another to the RRDtool libs. Mine looks like:

use lib qw(/usr/share/rrdtool/lib/perl);
use lib qw(/opt/smokeping/lib);
use lib qw(lib);

You also need to make sure that the correct config location is set. I installed SmokePing in /opt/smokeping so my configuration directory looks like:

Smokeping::main("/opt/smokeping/etc/config");

Note that this file doesn’t exist yet, but we’ll create it in a moment. Navigate to the etc directory (with cd ../etc). There are some sample configuration files in here that all end with the .dist suffix. The sample configuration I’m going to use will be watching two gateways; each gateway has both an external and internal IP address. You can monitor the status of the Internet connection by referencing the external IP address and that of the VPN site/site status by referencing the internal address. GW1 has addresses of 82.2.2.1 and 192.168.0.1, GW2 uses 82.3.2.1 and 192.168.1.1; you can change these to reachable addresses in your config file.

Create a new file called config (use vi config) and paste in the following configuration:

Link to config

This is a pretty standard configuration. You will obviously need to adjust these settings to fit your server configuration. Don’t forget to check the locations of the sendmail and fping binaries. Although the barrage of numbers can make the configuration file look quite complex, after a quick skim through the documentation, it will all make sense. Most of the numbers are defining the graph dimensions; the others set the time periods to be displayed. These can be changed as needed -- the data is stored in the RRD database so the new charts will retain all of the old data.

I don’t want to configure any alerts here, which simplifies things a little. I created copies of the default basepage.html.dist, smokemail.dist, and tmail.dist, removing the .dist from each.

Moving in to the htdocs directory, make a copy of smokeping.cgi.dist, removing the .dist suffix. As with the main SmokePing Perl script, check that the first line corresponds to your Perl installation; the library and config locations also need to be set:

use lib qw(/usr/share/rrdtool/lib/perl);
use lib qw(/opt/smokeping/lib);
use CGI::Carp qw(fatalsToBrowser);
Smokeping::cgi("/opt/smokeping/etc/config");

We can now test the configuration:

# cd /opt/smokeping/bin
# ./smokeping --check
Configuration file '/opt/smokeping/etc/config' syntax OK.

Everything looks good. Smokeping can be started in daemon mode and will begin logging data:

# ./smokeping
Note: logging to syslog as local0/info.
Daemonizing ./smokeping ...

All that remains is to configure Apache. First edit /etc/apache2/apache2.conf; you need to enable Apache to see smokeping.cgi as an index page and also allow CGI execution:

AddHandler cgi-script .cgi
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml smokeping.cgi

During the SpeedyCGI installation, the LoadModule directive should have been set in /etc/apache2/httpd.conf so all that remains is to add an alias for SmokePing. The entire contents of my httpd.conf are:

LoadModule speedycgi_module   /usr/lib/apache2/modules/mod_speedycgi.so
Alias /smokeping "/opt/smokeping/htdocs/"
<Directory "/opt/smokeping/htdocs">
   Allow from all
   Options ExecCGI
</Directory>

That should be everything. Restart Apache (/etc/init.d/apache2 restart) and open up http://support.mydomain.com/smokeping in a browser. There has hopefully been some data collected whilst you configured Apache -- the default setting will poll hosts once every 300 seconds.

SmokePing

Figure A is a sample chart showing one of my long distance WAN links going through a little turbulence.

Overall, I’m very happy with Smokeping; it can be kept simple while having more advanced features, such as alerting or master/slave multi-source data collection. Other options can be explored when your needs dictate.

4 comments
Saba A.
Saba A.

Also on checking the directories, I found that there is no /usr/share/rrdtool/lib directory present even after installing the tools and packages required.

Saba A.
Saba A.

As I am new to linux, after a lot of struggle finally I installed all the tools and smokeping too but in the end I got the following error when I open the pages for the graphs, " Software error: ERROR: creating /opt/smokeping/htdocs/cache/World: No such file or directory For help, please send mail to the webmaster (webmaster@localhost), giving this error message and the time and date of the error. " plz help me.

x_terminat_or_3
x_terminat_or_3

I installed smokeping by following this guide. User friendly is not what I would call it... but I guess that's the price you have to pay. I had a problem where Smokeping web frontend was looking for the cache files as a subfolder of itself, whereas I had told smokeping to put the cache files in /tmp/smokeping/ms/cache So I made a symlink inside the htdocs folder pointing to /tmp/smokeping/ms/cache and added the +FollowSymLinks option in httpd.conf Now it works :)

quality4none
quality4none

I was hoping you had a geek solution for tracking the time people expect to be paid to inhale carcinogens I occasionally log this time manually, tally, average, and leave that much earlier on a Friday.... using all my "Smoking" breaks at once