| 87 | | |
|---|
| 88 | | # Ask for config & search update_rate for each plugins |
|---|
| 89 | | foreach my $plugin (@plugins) { |
|---|
| 90 | | print STDERR "Asking config for $plugin\n" if $verbose; |
|---|
| 91 | | $plugins_rate{$plugin} = 300; # default : 5 min |
|---|
| 92 | | print $sock "config $plugin\n"; |
|---|
| 93 | | open (OUTFILE, "> $SPOOLDIR/munin-daemon.$plugin.config"); |
|---|
| 94 | | while(my $line = <$sock>) { |
|---|
| 95 | | print OUTFILE $line; |
|---|
| 96 | | if ($line =~ m/^update_rate (\d+)/) { |
|---|
| 97 | | # The plugin has a special update_rate: overriding it |
|---|
| 98 | | # XXX - Doesn't take into account a per field update_rate |
|---|
| 99 | | $plugins_rate{$plugin} = $1; |
|---|
| 100 | | } |
|---|
| 101 | | if ($line =~ m/^\./) { |
|---|
| 102 | | # Starting with . => end |
|---|
| 103 | | last; |
|---|
| 104 | | } |
|---|
| 105 | | } |
|---|
| 106 | | close (OUTFILE); |
|---|
| 107 | | } |
|---|
| 171 | | if ($line =~ m/^(\w+)\.value (\d+):(-?\d+\.?\d*)/) { |
|---|
| 172 | | # the plugin already outputed a time |
|---|
| 173 | | # keeping it |
|---|
| 174 | | print $fh_data "$1.value $2:$3\n"; |
|---|
| 175 | | print STDERR "[$plugin] $1.value $2:$3\n" if $debug; |
|---|
| 176 | | } elsif ($line =~ m/^(\w+)\.value (-?\d+\.?\d*)/) { |
|---|
| 177 | | # the plugin doesn't ouput a time, |
|---|
| 178 | | # using now() |
|---|
| 179 | | print $fh_data "$1.value $when:$2\n"; |
|---|
| 180 | | print STDERR "[$plugin] $1.value $when:$2\n" if $debug; |
|---|
| | 154 | push @$output_rows, $line; |
|---|
| | 155 | if ($line =~ m/^update_rate (\d+)/) { |
|---|
| | 156 | # The plugin has a special update_rate: overriding it |
|---|
| | 157 | # XXX - Doesn't take into account a per field update_rate |
|---|
| | 158 | |
|---|
| | 159 | # This has to be sent back to the master |
|---|
| | 160 | set_hash($plugin, $1, $plugin_rate_filename); |
|---|
| 183 | | } |
|---|
| | 163 | |
|---|
| | 164 | print STDERR "[$$][$process_name] asking for data\n" if $verbose; |
|---|
| | 165 | print $sock "fetch $plugin\n"; |
|---|
| | 166 | |
|---|
| | 167 | while(my $line = <$sock>) { |
|---|
| | 168 | print STDERR "[sock] $line" if $debug; |
|---|
| | 169 | chomp($line); |
|---|
| | 170 | |
|---|
| | 171 | if ($line =~ m/^\./) { |
|---|
| | 172 | # Starting with . => end |
|---|
| | 173 | last; |
|---|
| | 174 | } |
|---|
| | 175 | |
|---|
| | 176 | # Save the line |
|---|
| | 177 | push @$output_rows, $line; |
|---|
| | 178 | } |
|---|
| | 179 | |
|---|
| | 180 | # Write the whole load into the spool |
|---|
| | 181 | $spoolwriter->write($when, $plugin, $output_rows); |
|---|
| | 182 | } |
|---|
| | 183 | |
|---|
| | 184 | sub get_hash |
|---|
| | 185 | { |
|---|
| | 186 | my ($key, $filename) = @_; |
|---|
| | 187 | my %hash; |
|---|
| | 188 | |
|---|
| | 189 | use Fcntl; # For O_RDWR, O_CREAT, etc. |
|---|
| | 190 | use DB_File; |
|---|
| | 191 | tie (%hash, 'DB_File', $filename, O_RDWR|O_CREAT, 0666) |
|---|
| | 192 | or die "$!"; |
|---|
| | 193 | my $value = $hash{$key}; |
|---|
| | 194 | untie(%hash); |
|---|
| | 195 | |
|---|
| | 196 | return $value; |
|---|
| | 197 | } |
|---|
| | 198 | |
|---|
| | 199 | sub set_hash |
|---|
| | 200 | { |
|---|
| | 201 | my ($key, $value, $filename) = @_; |
|---|
| | 202 | my %hash; |
|---|
| | 203 | |
|---|
| | 204 | use Fcntl; # For O_RDWR, O_CREAT, etc. |
|---|
| | 205 | use DB_File; |
|---|
| | 206 | tie (%hash, 'DB_File', $filename, O_RDWR|O_CREAT, 0666) |
|---|
| | 207 | or die "$!"; |
|---|
| | 208 | $hash{$key} = $value; |
|---|
| | 209 | untie(%hash); |
|---|
| | 210 | } |
|---|
| | 211 | |
|---|
| | 212 | |
|---|