Smokeping: smokeinfo – saving loading time

Smokeping: smokeinfo – saving loading time

Whenever you run: smokeinfo /etc/smokeping/config , smokeping will load a lot of all configurations into memory, this takes a lot of time. Since we don’t change our configuration often, so why don’t we cache the configuration to a file and smokeping will just load it from a file. The script below is a modified version, it save about 3s loading time – i have about 7000 hosts to monitor , 3s is not a bad number. There are other things we can save time.

package Smokeping::Info;
use warnings;
use strict;
use RRDs;
use Smokeping;
use Carp;
use Data::Dumper;

sub new {

    my $this   = shift;
    my $class   = ref($this) || $this;
    my $self = { cfg_file => shift };
    bless $self, $class;

    my $smokeping_cfg_cache_file = "/var/lib/smokeping/smokeping_config_cache3354";
    if(  -e $smokeping_cfg_cache_file)
    {
       open FILE,  "<$smokeping_cfg_cache_file";
       my $data = join "", <FILE>;
       close FILE;
       no strict 'vars';
       $old_data = eval $data;
      $self->{cfg_hash}  = $old_data;
    }else
     {
          my $parser = Smokeping::get_parser();
         $self->{cfg_hash} = $parser->parse( $self->{cfg_file} )
          or croak "ERROR reading config file $parser->{err}";
         open  my $fh, '>', $smokeping_cfg_cache_file;
         print $fh Dumper($self->{cfg_hash});
        close $fh;

    }
    $self->{probe_hash} = Smokeping::load_probes $self->{cfg_hash};



    return $self;
}

Leave a Reply

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