| | 81 | # Check if this plugin has to be updated |
|---|
| | 82 | my $update_rate_in_seconds = get_global_service_value(\%service_config, $plugin, "update_rate", 0); # default is 0 sec : always update when asked |
|---|
| | 83 | |
|---|
| | 84 | DEBUG "[DEBUG] update_rate $update_rate_in_seconds for $plugin on $nodedesignation"; |
|---|
| | 85 | if ($update_rate_in_seconds && is_fresh_enough($nodedesignation, $plugin, $update_rate_in_seconds)) { |
|---|
| | 86 | # It's fresh enough, skip this $service |
|---|
| | 87 | DEBUG "[DEBUG] $plugin is fresh enough, not updating it"; |
|---|
| | 88 | next; |
|---|
| | 89 | } |
|---|
| | 90 | |
|---|
| | 159 | return $default; |
|---|
| | 160 | } |
|---|
| | 161 | |
|---|
| | 162 | sub is_fresh_enough { |
|---|
| | 163 | my ($nodedesignation, $service, $update_rate_in_seconds) = @_; |
|---|
| | 164 | |
|---|
| | 165 | my $key = "$nodedesignation/$service"; |
|---|
| | 166 | DEBUG "is_fresh_enough asked for $key with a rate of $update_rate_in_seconds"; |
|---|
| | 167 | |
|---|
| | 168 | my %last_updated; |
|---|
| | 169 | # XXX - ugly hack. Should be refactored to use a a common state provider |
|---|
| | 170 | |
|---|
| | 171 | use Fcntl; # For O_RDWR, O_CREAT, etc. |
|---|
| | 172 | use NDBM_File; |
|---|
| | 173 | tie(%last_updated, 'NDBM_File', '/tmp/munin_plugins_last_updated', O_RDWR|O_CREAT, 0666) or ERROR "$!"; |
|---|
| | 174 | DEBUG "last_updated{$key}: " . $last_updated{$key}; |
|---|
| | 175 | my @last = split(/ /, $last_updated{$key}); |
|---|
| | 176 | |
|---|
| | 177 | use Time::HiRes qw(gettimeofday tv_interval); |
|---|
| | 178 | my $now = [ gettimeofday ]; |
|---|
| | 179 | |
|---|
| | 180 | my $age = tv_interval(\@last, $now); |
|---|
| | 181 | DEBUG "last: " . Dumper(\@last) . ", now: " . Dumper($now) . ", age: $age"; |
|---|
| | 182 | my $is_fresh_enough = ($age < $update_rate_in_seconds); |
|---|
| | 183 | DEBUG "is_fresh_enough $is_fresh_enough"; |
|---|
| | 184 | |
|---|
| | 185 | if (! $is_fresh_enough) { |
|---|
| | 186 | DEBUG "new value: " . join(" ", @$now); |
|---|
| | 187 | $last_updated{$key} = join(" ", @$now); |
|---|
| | 188 | } |
|---|
| | 189 | |
|---|
| | 190 | untie(%last_updated); |
|---|
| | 191 | |
|---|
| | 192 | return $is_fresh_enough; |
|---|
| | 193 | } |
|---|
| | 194 | |
|---|
| | 195 | |
|---|