Speedy-CGI for Smokeping

Posted on Posted in Nagios

Smokeping una gran herramienta para monitorizar las latencias de los diferentes equipos de nuestra infraestructura, ofrece:

  • Best of breed latency visualisation.
  • Interactive graph explorer.
  • Wide range of latency measurment plugins.
  • Master/Slave System for distributed measurement.
  • Highly configurable alerting system.
  • Live Latency Charts with the most ‘interesting’ graphs.
  • Free and OpenSource Software written in Perl written by Tobi Oetiker, the creator of MRTG and RRDtool

Pero por defecto esta herramienta es muy lenta, para acelerarla podemos echar mano de Speedy, un módulo que nos permitirá ejecutar smokeping y su cgi correspondiente de forma más fluida.

Descarga desde CPAN

Este módulo esta disponible desde las bibliotecas de CPAN

Instalación

Para instalarlo lo único que tenemos que hacer es extraerlo y compilarlo:

tar xvfz CGI-SpeedyCGI-2.22.tar.gz
 
[root@snaider CGI-SpeedyCGI-2.22]# perl Makefile.PL

Optional mod_speedycgi support.

Mod_speedycgi increases performance under Apache by avoiding the fork/exec
overhead associated with each request under normal SpeedyCGI. However, it
requires a working copy of "apxs" in your path, Apache with mod_so
support, and additional Apache configuration.

Compile mod_speedycgi (default no)?
Checking if your kit is complete...
Looks good
Writing Makefile for src
Writing Makefile for speedy_backend
Writing MYMETA.yml and MYMETA.json
Writing Makefile for speedy
Writing MYMETA.yml and MYMETA.json
Writing Makefile for CGI::SpeedyCGI
Writing MYMETA.yml and MYMETA.json
[root@snaider CGI-SpeedyCGI-2.22]#

Compilamos…..

 
[root@snaider CGI-SpeedyCGI-2.22]# make
cd src && make
make[1]: se ingresa al directorio `/usr/local/etc/CGI-SpeedyCGI-2.22/src'
/usr/bin/perl -w optdefs.pl /usr/bin
Writing speedy_optdefs.c
Writing speedy_optdefs.h
......
....
..

Instalamos….

 
[root@snaider CGI-SpeedyCGI-2.22]# make install
make[1]: se ingresa al directorio `/usr/local/etc/CGI-SpeedyCGI-2.22/src'
make[1]: No se hace nada para `all'.
make[1]: se sale del directorio `/usr/local/etc/CGI-SpeedyCGI-2.22/src'
make[1]: se ingresa al directorio `/usr/local/etc/CGI-SpeedyCGI-2.22/speedy_backend'
make[1]: se sale del directorio `/usr/local/etc/CGI-SpeedyCGI-2.22/speedy_backend'
make[1]: se ingresa al directorio `/usr/local/etc/CGI-SpeedyCGI-2.22/speedy'
make[1]: se sale del directorio `/usr/local/etc/CGI-SpeedyCGI-2.22/speedy'
Installing /usr/bin/speedy_backend
Installing /usr/bin/speedy
Appending installation info to /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/perllocal.pod
[root@snaider CGI-SpeedyCGI-2.22]#
Configuración de Smokeping

Para que Smokeping use este módulo tenemos que configurar tanto el CGI como el binario que se lanza como demonio:

CGI

Editamos /usr/local/etc2/httpd/cgi-bin/smokeping.cgi, sustituyendo #!/usr/bin/perl por #!/usr/bin/speedy -w

 
#!/usr/bin/speedy -w
# -*-perl-*-

use strict;
use warnings;

use lib qw(/usr/local/etc2/rrdtool/lib/perl);
use lib qw(/usr/local/etc2/smokeping/lib);

use CGI::Carp qw(fatalsToBrowser);

use Smokeping 2.004002;

Smokeping::cgi("/usr/local/etc2/smokeping/etc/config");

=head1 ADMINISTRADOR

Administrado por Alberto larripa
BINARIO

Editamos /usr/local/etc2/smokeping/bin/smokeping,  sustituyendo #!/usr/bin/perl por #!/usr/bin/speedy -w 

 
#!/usr/bin/speedy -w
# -*-perl-*-

use lib qw(/usr/local/etc2/rrdtool/lib/perl);
use lib qw(/usr/local/etc2/smokeping/lib);
#use strict;
use warnings;
use Smokeping 2.004002;

Smokeping::main("/usr/local/etc2/smokeping/etc/config");

=head1 NAME

smokeping - Commandline tool for SmokePing
.....
....
..

INIT.D

Al haber cambiado de perl a speedy_backend tenemos que modificar el fichero de arranque y parada del programa.

 

#!/bin/sh
#
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

PATH=$PATH:/usr/bin:/usr/local/bin

# See how we were called.
case "$1" in
start)
        # Start daemon.
        echo -n "Starting SMOKEPING: "
        cd /usr/local/etc2/smokeping/ && ./bin/smokeping --logfile=/var/log/smoke.log
        RETVAL=$?
        touch /var/lock/subsys/smokeping
        echo
      ;;
stop)
        # Stop daemons.
        echo -n "Shutting down SMOKEPÌNG: "
        #killproc smokeping -9
        killproc speedy_backend -9
        #RETVAL=$?
        rm -f /var/lock/subsys/smokeping
        echo
      ;;

reload)
        # Recargamos la configuración
        /usr/local/etc2/smokeping/bin/smokeping --reload
        echo
        ;;
restart)
        $0 stop
        $0 start
      ;;
status)
        status mrtg
      ;;
*)
echo "Usage: $0 {start|stop|reload|restart|status}"
esac
exit 0
Comprobaciones

Podemos comprobar como es ahora el speedy_backend el que ejecuta smokeping, tres procesos corresponden al demonio de smokeping y otros dos al cgi.

  
[root@snaider CGI-SpeedyCGI-2.22]# ps aux | grep smoke
root     25189  0.1  0.2 167020 18868 ?        Ss   19:04   0:00 /usr/bin/speedy_backend -w ./bin/smokeping --logfile=/var/log/smoke.log
root     25190  3.9  0.5 194164 42984 ?        S    19:04   0:05 /usr/bin/speedy_backend -w ./bin/smokeping --logfile=/var/log/smoke.log
root     26104  0.0  0.5 194164 41920 ?        Ss   19:04   0:00 /usr/bin/speedy_backend -w ./bin/smokeping --logfile=/var/log/smoke.log
www-data 27122  0.2  0.2 109912 18868 ?        Ss   19:05   0:00 /usr/bin/speedy_backend -w /usr/local/etc2/httpd/cgi-bin/smokeping.cgi
www-data 27129  9.3  0.5 140912 46900 ?        S    19:05   0:07 /usr/bin/speedy_backend -w /usr/local/etc2/httpd/cgi-bin/smokeping.cgi

 

Leave a Reply

Your email address will not be published. Required fields are marked *