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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
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