Changeset 2726

Show
Ignore:
Timestamp:
10/27/09 13:17:17 (2 years ago)
Author:
janl
Message:

* Munin-update: Multigraph has come! (but we need it in munin-graph, munin-html and munin-limits too)
* Node/UpdateWorker/Update: Multiple log/error message enhancements

Multigraph adapt munin_master_plugin_fetch test

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/master/lib/Munin/Master/Node.pm

    r2703 r2726  
    1313use Munin::Common::Timeout; 
    1414use Munin::Common::TLSClient; 
    15 use Munin::Master::Logger; 
    1615use Data::Dumper; 
    1716use Log::Log4perl qw( :easy ); 
     
    6968sub _extract_name_from_greeting { 
    7069    my ($self, $greeting) = @_; 
    71     croak "Got no reply from node" unless $greeting; 
    72     $greeting =~ /\#.*(?:lrrd|munin) (?:client|node) at (\S+)/ 
    73         or croak "Got unknown reply from node"; 
     70    if (!$greeting) { 
     71        die "[ERROR] Got no reply from node ".$self->{host}."\n"; 
     72    } 
     73    if (! $greeting =~ /\#.*(?:lrrd|munin) (?:client|node) at (\S+)/) { 
     74        die "[ERROR] Got unknown reply from node ".$self->{host}."\n"; 
     75    } 
    7476    return $1; 
    7577} 
     
    102104        $self->{tls} = undef; 
    103105        if ($tls_requirement eq "paranoid" or $tls_requirement eq "enabled") { 
    104             croak("[ERROR] Could not establish TLS connection to '$self->{address}'. Skipping.")
     106           die "[ERROR] Could not establish TLS connection to '$self->{address}'. Skipping.\n"
    105107        } 
    106108    } 
     
    141143 
    142144 
    143 sub list_services { 
     145sub list_plugins { 
    144146    my ($self) = @_; 
    145147 
     
    148150        : $self->{host}; 
    149151 
    150     croak "Couldn't find out which host to list" unless $host; 
     152    if (not $host) { 
     153        die "[ERROR] Couldn't find out which host to list on $host.\n"; 
     154    } 
    151155 
    152156    $self->_node_write_single("list $host\n"); 
     
    154158 
    155159    if (not $list) { 
    156         logger("[WARNING] Config node $self->{host} listed no services for $host")
     160        WARN "[WARNING] Config node $self->{host} listed no services for $host"
    157161    } 
    158162 
     
    164168    my ($self, $service, @lines) = @_; 
    165169 
    166     my @global_config = (); 
    167     my %data_source_config = (); 
    168  
    169     my @graph_order = (); 
     170    my $plugin = $service; 
     171 
     172    my $nodedesignation = $self->{host}."/".$self->{address}."/".$self->{port}; 
     173 
     174    my $global_config = { 
     175        multigraph => [], 
     176    }; 
     177    my $data_source_config = {}; 
     178    my @graph_order = ( ); 
     179 
     180    # Pascal style nested subroutine 
     181    local *new_service = sub { 
     182        push @{$global_config->{multigraph}}, $service; 
     183        $global_config->{$service} = []; 
     184        $data_source_config->{$service} = {}; 
     185    }; 
     186 
     187    local *push_graphorder = sub { 
     188        my ($oldservice) = @_; 
     189 
     190        push( @{$global_config->{$oldservice}},  
     191              ['graph_order', join(' ', @graph_order)] ) 
     192            unless !@graph_order ||  
     193                   grep { $_->[0] eq 'graph_order' } @{$global_config->{$oldservice}}; 
     194        @graph_order = ( ); 
     195    }; 
     196 
     197    DEBUG "[DEBUG] Now parsing config output from plugin $plugin on ".$self->{host}; 
     198 
     199    new_service($service); 
    170200 
    171201    for my $line (@lines) { 
    172         croak "Client reported timeout in configuration of '$service'" 
    173             if $line =~ /\# timeout/; 
     202 
     203        DEBUG "[CONFIG from $plugin] $line"; 
     204 
     205        if ($line =~ /\# timeout/) { 
     206            die "[ERROR] Timeout error ($nodedesignation). Please consult the log.\n"; 
     207        } 
     208 
    174209        next unless $line; 
    175210        next if $line =~ /^\#/; 
    176211 
    177         if ($line =~ m{\A (\w+)\.(\w+) \s+ (.+) }xms) { 
     212        if ($line =~ m{\A multigraph \s+ (.+) }xms) { 
     213            push_graphorder($service); 
     214 
     215            $service = $1; 
     216 
     217            if ($service eq 'multigraph') { 
     218                ERROR "[ERROR] SERVICE can't be named \"$service\" in plugin $plugin on ".$self->{host}."/".$self->{address}."/".$self->{port}; 
     219                croak("Illegal service name.  Please consult the log"); 
     220            } 
     221            new_service($service); 
     222            DEBUG "[CONFIG multigraph $plugin] Service is now $service"; 
     223        } 
     224        elsif ($line =~ m{\A (\w+)\.(\w+) \s+ (.+) }xms) { 
    178225            my ($ds_name, $ds_var, $ds_val) = ($1, $2, $3); 
    179226            $ds_name = $self->_sanitise_fieldname($ds_name); 
    180             $data_source_config{$ds_name} ||= {}; 
    181             $data_source_config{$ds_name}{$ds_var} = $ds_val; 
    182             DEBUG "[CONFIG dataseries] $service->$ds_name.$ds_var = $ds_val"; 
    183             push @graph_order, $ds_name if ($ds_var eq 'label'); 
    184         } 
    185         elsif ($line =~ m{\A (\w+) \s+ (.+) }xms) { 
    186             push @global_config, [$1, $2]; 
    187             DEBUG "[CONFIG graph global] $service->$1 = $2"; 
    188         } 
    189         else { 
    190             croak "Protocol exception: while configuring '$service': unrecognised line '$line'"; 
    191         } 
    192     } 
    193  
    194     $self->_validate_data_sources(\%data_source_config); 
    195  
    196     push @global_config, ['graph_order', join(' ', @graph_order)] 
    197         unless !@graph_order || grep { $_->[0] eq 'graph_order' } @global_config; 
    198  
    199     return (global => \@global_config, data_source => \%data_source_config); 
     227            $data_source_config->{$service}{$ds_name} ||= {}; 
     228            $data_source_config->{$service}{$ds_name}{$ds_var} = $ds_val; 
     229            DEBUG "[CONFIG dataseries $plugin] $service->$ds_name.$ds_var = $ds_val"; 
     230            push ( @graph_order, $ds_name ) if $ds_var eq 'label'; 
     231        } 
     232        elsif ($line =~ m{\A (\w+) \s+ (.+) }xms) { 
     233            push @{$global_config->{$service}}, [$1, $2]; 
     234            DEBUG "[CONFIG graph global $plugin] $service->$1 = $2"; 
     235        } 
     236        else { 
     237            die "[ERROR] Protocol exception: unrecognized line '$line' from $plugin on $nodedesignation.\n"; 
     238        } 
     239    } 
     240 
     241    $self->_validate_data_sources($data_source_config); 
     242 
     243    push_graphorder($service); 
     244 
     245    return (global => $global_config, data_source => $data_source_config); 
    200246} 
    201247 
     
    215261 
    216262sub _validate_data_sources { 
    217     my ($self, $data_source_config) = @_; 
    218  
    219     for my $ds (keys %$data_source_config) { 
    220         croak "Missing required attribute 'label' for data source '$ds'" 
    221             unless defined $data_source_config->{$ds}{label}; 
    222     } 
    223 
    224  
    225  
    226 sub fetch_service_data { 
    227     my ($self, $service) = @_; 
    228  
    229     $self->_node_write_single("fetch $service\n"); 
    230     my @lines = $self->_node_read(); 
    231  
    232     my %values = (); 
     263    my ($self, $all_data_source_config) = @_; 
     264 
     265    for my $service (keys %$all_data_source_config) { 
     266        my $data_source_config = $all_data_source_config->{$service}; 
     267 
     268        for my $ds (keys %$data_source_config) { 
     269            croak "Missing required attribute 'label' for data source '$ds'" 
     270                unless defined $data_source_config->{$ds}{label}; 
     271        } 
     272    } 
     273
     274 
     275 
     276sub parse_service_data { 
     277    my ($self, $service, @lines) = @_; 
     278 
     279    my $plugin = $service; 
     280 
     281    my $nodedesignation = $self->{host}."/".$self->{address}.":".$self->{port}; 
     282 
     283    my %values = ( 
     284        $service => {}, 
     285    ); 
     286 
     287    DEBUG "[DEBUG] Now parsing fetch output from plugin $plugin on ". 
     288        $nodedesignation; 
    233289 
    234290    for my $line (@lines) { 
    235         croak "Client reported timeout in configuration of '$service'" 
    236             if $line =~ /\# timeout/; 
     291 
     292        DEBUG "[FETCH from $plugin] $line"; 
     293 
     294        if ($line =~ /\# timeout/) { 
     295            WARN "[WARNING] Timeout in fetch from '$plugin' on ". 
     296                $nodedesignation; 
     297            croak("Timeout error.  Please consult the log."); 
     298        } 
     299 
    237300        next unless $line; 
    238301        next if $line =~ /^\#/; 
    239302 
    240         if ($line =~ m{ (\w+)\.value \s+ ([\S:]+) }xms) { 
     303        if ($line =~ m{\A multigraph \s+ (.+) }xms) { 
     304            $service = $1; 
     305            $values{$service} = {}; 
     306 
     307            if ($service eq 'multigraph') { 
     308                ERROR "[ERROR] SERVICE can't be named \"$service\" in plugin $plugin on ". 
     309                    $nodedesignation; 
     310                croak("Plugin error.  Please consult the log."); 
     311            } 
     312        } 
     313        elsif ($line =~ m{ (\w+)\.value \s+ ([\S:]+) }xms) { 
    241314            my ($data_source, $value, $when) = ($1, $2, 'N'); 
    242315 
     
    248321            } 
    249322 
    250             $values{$data_source} = { value => $value, when => $when }; 
     323            $values{$service}{$data_source} =  
     324                { value => $value, when => $when }; 
    251325        } 
    252326        else { 
    253             croak "Protocol exception: while fetching '$service': unrecogniced line '$line'"; 
     327            die "[ERROR] Protocol exception while fetching '$service' from $nodedesignation: unrecogniced line '$line'" 
    254328        } 
    255329    } 
    256330 
    257331    return %values; 
     332} 
     333 
     334 
     335sub fetch_service_data { 
     336    my ($self, $plugin) = @_; 
     337 
     338    $self->_node_write_single("fetch $plugin\n"); 
     339    my @lines = $self->_node_read(); 
     340 
     341    return $self->parse_service_data($plugin,@lines); 
    258342} 
    259343 
     
    276360    my ($self, $text) = @_; 
    277361 
    278     logger("[DEBUG] Writing to socket: \"$text\".") if $config->{debug}
     362    DEBUG "[DEBUG] Writing to socket: \"$text\"."
    279363    my $timed_out = !do_with_timeout($self->{io_timeout}, sub { 
    280364        if ($self->{tls} && $self->{tls}->session_started()) { 
     
    287371    }); 
    288372    if ($timed_out) { 
    289         logger("[WARNING] Socket write timed out\n")
     373        WARN "[WARNING] Socket write timed out to ".$self->{host}."\n"
    290374        return; 
    291375    } 
     
    308392    }); 
    309393    if ($timed_out) { 
    310         logger("[WARNING] Socket read timed out\n")
     394        WARN "[WARNING] Socket read timed out to ".$self->{host}."\n"
    311395        return; 
    312396    } 
    313     logger("[DEBUG] Reading from socket: \"$res\".") if $config->{debug}
     397    DEBUG "[DEBUG] Reading from socket to ".$self->{host}.": \"$res\"."
    314398    return $res; 
    315399} 
     
    332416    }); 
    333417    if ($timed_out) { 
    334         logger ("[WARNING] Socket read timed out: $@\n")
     418        WARN "[WARNING] Socket read timed out to ".$self->{host}.": $@\n"
    335419        return; 
    336420    } 
    337     logger ("[DEBUG] Reading from socket: \"".(join ("\\n",@array))."\".") if $config->{debug}
     421    DEBUG "[DEBUG] Reading from socket: \"".(join ("\\n",@array))."\"."
    338422    return @array; 
    339423} 
  • trunk/master/lib/Munin/Master/Update.pm

    r2704 r2726  
    259259    print $io "version $Munin::Common::Defaults::MUNIN_VERSION\n"; 
    260260    for my $host (keys %{$self->{service_configs}}) { 
    261         for my $service (keys %{$self->{service_configs}{$host}}) { 
    262             for my $attr (@{$self->{service_configs}{$host}{$service}{global}}) { 
     261        for my $service (keys %{$self->{service_configs}{$host}{data_source}}) { 
     262            for my $attr (@{$self->{service_configs}{$host}{global}{$service}}) { 
    263263                print $io "$host:$service.$attr->[0] $attr->[1]\n"; 
    264264            } 
    265             for my $data_source (keys %{$self->{service_configs}{$host}{$service}{data_source}}) { 
    266                 for my $attr (keys %{$self->{service_configs}{$host}{$service}{data_source}{$data_source}}) { 
    267                     print $io "$host:$service.$data_source.$attr $self->{service_configs}{$host}{$service}{data_source}{$data_source}{$attr}\n"; 
     265            for my $data_source (keys %{$self->{service_configs}{$host}{data_source}{$service}}) { 
     266                for my $attr (keys %{$self->{service_configs}{$host}{data_source}{$service}{$data_source}}) { 
     267                    print $io "$host:$service.$data_source.$attr $self->{service_configs}{$host}{data_source}{$service}{$data_source}{$attr}\n"; 
    268268                } 
    269269            } 
  • trunk/master/lib/Munin/Master/UpdateWorker.pm

    r2704 r2726  
    22use base qw(Munin::Master::Worker); 
    33 
    4 # $Id$ 
     4=comment 
     5 
     6This file is part of Munin. 
     7 
     8  Copyright (C) 2002-2009  Jimmy Olsen, et al. 
     9 
     10  This program is free software; you can redistribute it and/or modify 
     11  it under the terms of the GNU General Public License as published by 
     12  the Free Software Foundation; version 2 dated June, 1991. 
     13 
     14  This program is distributed in the hope that it will be useful, 
     15  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     17  GNU General Public License for more details. 
     18 
     19  You should have received a copy of the GNU General Public License 
     20  along with this program; if not, write to the Free Software 
     21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     22 
     23 
     24$Id$ 
     25 
     26=cut 
    527 
    628use warnings; 
     
    931use Carp; 
    1032use English qw(-no_match_vars); 
     33use Log::Log4perl qw( :easy ); 
     34 
    1135use File::Basename; 
    1236use File::Path; 
    1337use File::Spec; 
    1438use Munin::Master::Config; 
    15 use Munin::Master::Logger; 
    1639use Munin::Master::Node; 
    1740use Munin::Master::Utils; 
     
    4063    my $update_time = Time::HiRes::time; 
    4164 
    42     my $lock_file = sprintf '%s/munin-%s-%s.lock', 
    43         $config->{rundir}, 
    44             $self->{host}{group}{group_name}, 
    45                 $self->{host}{host_name}; 
    46  
    47     munin_getlock($lock_file) 
    48         or croak "Could not get lock for '$self->{host}{host_name}'. Skipping node."; 
    49  
    50     my %all_service_configs = (); 
     65    my $host = $self->{host}{host_name}; 
     66 
     67    my $nodedesignation = $host."/". 
     68        $self->{host}{address}.":".$self->{host}{port}; 
     69 
     70    my $lock_file = sprintf ('%s/munin-%s-%s.lock', 
     71                             $config->{rundir}, 
     72                             $self->{host}{group}{group_name}, 
     73                             $host); 
     74 
     75    if (!munin_getlock($lock_file)) { 
     76        WARN "Could not get lock $lock_file for $nodedesignation. Skipping node."; 
     77        die "Could not get lock $lock_file for $nodedesignation. Skipping node.\n"; 
     78    } 
     79 
     80    my %all_service_configs = ( 
     81        data_source => {}, 
     82        global => {}, 
     83        ); 
    5184 
    5285    $self->{node}->do_in_session(sub { 
    5386        $self->{node}->negotiate_capabilities(); 
    5487        # Note: A multigraph plugin can present multiple services. 
    55         my @plugins =  $self->{node}->list_services(); 
    56         # my @services = 
     88        my @plugins =  $self->{node}->list_plugins(); 
    5789 
    5890        for my $plugin (@plugins) { 
     
    6395            my %service_config = $self->uw_fetch_service_config($plugin); 
    6496            unless (%service_config) { 
    65                 logger("[WARNING] Service $plugin returned no config")
     97                WARN "[WARNING] Service $plugin on $nodedesignation returned no config"
    6698                next; 
    6799            } 
    68  
    69             $self->_compare_and_act_on_config_changes($plugin, 
    70                                                       \%service_config); 
    71100 
    72101            my %service_data = eval { 
     
    74103            }; 
    75104            if ($EVAL_ERROR) { 
    76                 logger($EVAL_ERROR); 
     105                ERROR $EVAL_ERROR; 
     106                warn "$EVAL_ERROR\n"; 
    77107                next; 
    78108            } 
    79109 
    80             $self->_update_rrd_files($plugin, \%service_config, \%service_data); 
    81             $all_service_configs{$plugin} = \%service_config; 
     110            # Since different plugins can populate multiple positions in the 
     111            # service namespace we'll check for collisions and warn of them. 
     112 
     113            for my $service (keys %{$service_config{data_source}}) { 
     114                if (defined($all_service_configs{data_source}{$service})) { 
     115                    WARN "[WARNING] Service colision: plugin $plugin on $nodedesignation reports $service which already exists on that host.  Deleting new data."; 
     116                    delete($service_config{data_source}{$service}); 
     117                    delete($service_data{$service}) 
     118                        if defined $service_data{$service}; 
     119                } 
     120            } 
     121 
     122            $self->_compare_and_act_on_config_changes(\%service_config); 
     123 
     124            %{$all_service_configs{data_source}} = ( 
     125                %{$all_service_configs{data_source}}, 
     126                %{$service_config{data_source}}); 
     127 
     128            %{$all_service_configs{global}} = ( 
     129                %{$all_service_configs{global}}, 
     130                %{$service_config{global}}); 
     131 
     132            $self->_update_rrd_files(\%service_config, \%service_data); 
    82133        } 
    83134 
     
    96147sub uw_fetch_service_config { 
    97148    # not sure why fetch_service_config needs eval and fetch_service_data 
    98     # does not. - janl 2009.10.22 
     149    # does not. - janl 2009-10-22 
    99150    my ($self, $plugin) = @_; 
    100151 
     
    105156        # FIX Report failed service so that we can use the old service 
    106157        # config. 
    107         logger($EVAL_ERROR); 
     158        ERROR $EVAL_ERROR; 
     159        warn "$EVAL_ERROR\n"; 
    108160        return; 
    109161    } 
    110162 
     163    # FIX for nested services 
    111164    if ($self->{host}{service_config} && $self->{host}{service_config}{$plugin}) { 
    112165        %service_config 
     
    119172 
    120173sub _compare_and_act_on_config_changes { 
    121     my ($self, $service, $service_config) = @_; 
     174    my ($self, $nested_service_config) = @_; 
    122175 
    123176    # Kjellm: Why do we need to tune RRD files after upgrade? 
    124177    # Shouldn't we create a upgrade script or something instead? 
    125178    # 
    126     # janl: Not sure? Code duplication? Ease of use? Lazyness? 
     179    # janl: Upgrade script sucks.  This way it's inline in munin and 
     180    #  no need to remember anything or anything. 
    127181 
    128182    my $just_upgraded = 0; 
     
    136190    } 
    137191 
    138     for my $data_source (keys %{$service_config->{data_source}}) { 
    139         my $old_data_source = $data_source; 
    140         my $ds_config = $service_config->{data_source}{$data_source}; 
    141         $self->_set_rrd_data_source_defaults($ds_config); 
    142  
    143         my $group = $self->{host}{group}{group_name}; 
    144         my $host = $self->{host}{host_name}; 
    145  
    146         my $old_host_config = 
    147             $old_config->{groups}{$group}{hosts}{$host}; 
    148         my $old_ds_config = 
    149             $old_host_config->get_canned_ds_config($service, 
    150                                                    $data_source); 
    151  
    152         if (not %$old_ds_config 
    153             and defined($ds_config->{oldname}) 
    154             and $ds_config->{oldname}) { 
    155  
    156             $old_data_source = $ds_config->{oldname}; 
    157             $old_ds_config = 
    158                 $old_host_config->get_canned_ds_config($service, 
    159                                                        $old_data_source); 
    160         } 
    161  
    162         if (%$old_ds_config 
    163             and not $self->_ds_config_eq($old_ds_config, $ds_config)) { 
    164             $self->_ensure_filename($service, 
    165                                     $old_data_source, $data_source, 
    166                                     $old_ds_config, $ds_config) 
    167                 and $self->_ensure_tuning($service, $data_source, 
    168                                           $ds_config); 
    169         } elsif ($just_upgraded) { 
    170             $self->_ensure_tuning($service, $data_source, 
    171                                   $ds_config); 
    172         } 
     192    for my $service (keys %{$nested_service_config->{data_source}}) { 
     193 
     194        my $service_config = $nested_service_config->{data_source}{$service}; 
     195 
     196        for my $data_source (keys %{$service_config}) { 
     197            my $old_data_source = $data_source; 
     198            my $ds_config = $service_config->{$data_source}; 
     199            $self->_set_rrd_data_source_defaults($ds_config); 
     200 
     201            my $group = $self->{host}{group}{group_name}; 
     202            my $host = $self->{host}{host_name}; 
     203 
     204            my $old_host_config = $old_config->{groups}{$group}{hosts}{$host}; 
     205            my $old_ds_config = undef; 
     206 
     207            if ($old_host_config) { 
     208                $old_ds_config = 
     209                    $old_host_config->get_canned_ds_config($service, 
     210                                                           $data_source); 
     211            } 
     212 
     213            if (defined($old_ds_config) 
     214                and %$old_ds_config 
     215                and defined($ds_config->{oldname}) 
     216                and $ds_config->{oldname}) { 
     217 
     218                $old_data_source = $ds_config->{oldname}; 
     219                $old_ds_config = 
     220                    $old_host_config->get_canned_ds_config($service, 
     221                                                           $old_data_source); 
     222            } 
     223 
     224            if (defined($old_ds_config) 
     225                and %$old_ds_config 
     226                and not $self->_ds_config_eq($old_ds_config, $ds_config)) { 
     227                $self->_ensure_filename($service, 
     228                                        $old_data_source, $data_source, 
     229                                        $old_ds_config, $ds_config) 
     230                    and $self->_ensure_tuning($service, $data_source, 
     231                                              $ds_config); 
     232                # _ensure_filename prints helpfull warnings in the log 
     233            } elsif ($just_upgraded) { 
     234                $self->_ensure_tuning($service, $data_source, 
     235                                      $ds_config); 
     236            } 
     237        } 
    173238    } 
    174239} 
     
    215280                                                 $old_ds_config); 
    216281 
     282    my $hostspec = $self->{node}{hostname}.'/'.$self->{node}{address}.':'. 
     283        $self->{node}{port}; 
     284 
    217285    if ($rrd_file ne $old_rrd_file) { 
    218286        if (-f $old_rrd_file and -f $rrd_file) { 
    219287            my $host = $self->{host}{host_name}; 
    220             logger("[WARNING]: $host $service $data_source config change
    221                    . " suggests moving '$old_rrd_file' to '$rrd_file' but
    222                    . " both exist; manually merge the data or remove
    223                    . " whichever file you care less about.\n")
    224             return ''; 
     288            WARN "[WARNING]: $hostspec $service $data_source config change
     289               . "suggests moving '$old_rrd_file' to '$rrd_file'
     290               . "but both exist; manually merge the data
     291                . "or remove whichever file you care less about.\n"
     292           return ''; 
    225293        } elsif (-f $old_rrd_file) { 
    226             logger("[INFO]: Config update, changing name of '$old_rrd_file'" 
    227                    . " to '$rrd_file'")
     294            INFO "[INFO]: Config update, changing name of '$old_rrd_file'" 
     295                   . " to '$rrd_file' on $hostspec "
    228296            unless (rename ($old_rrd_file, $rrd_file)) { 
    229                 logger ("[ERROR]: Could not rename '$old_rrd_file' to" 
    230                         . " '$rrd_file': $!\n")
     297                ERROR "[ERROR]: Could not rename '$old_rrd_file' to" 
     298                   . " '$rrd_file' for $hostspec: $!\n"
    231299                return ''; 
    232300            } 
     
    251319 
    252320    for my $rrd_prop (qw(type max min)) { 
    253         logger("[INFO]: Config update, ensuring $rrd_prop of" 
    254                . " '$rrd_file' is '$ds_config->{$rrd_prop}'.\n")
     321        INFO "[INFO]: Config update, ensuring $rrd_prop of" 
     322           . " '$rrd_file' is '$ds_config->{$rrd_prop}'.\n"
    255323        RRDs::tune($rrd_file, $tune_flags{$rrd_prop}, 
    256324                   "42:$ds_config->{$rrd_prop}"); 
    257325        if (my $tune_error = RRDs::error()) { 
    258             logger("[ERROR] Tuning $rrd_prop of '$rrd_file' to" 
    259                    . " '$ds_config->{$rrd_prop}' failed.\n")
     326            ERROR "[ERROR] Tuning $rrd_prop of '$rrd_file' to" 
     327               . " '$ds_config->{$rrd_prop}' failed.\n"
    260328            $success = ''; 
    261329        } 
     
    267335 
    268336sub _update_rrd_files { 
    269     my ($self, $service, $service_config, $service_data) = @_; 
    270  
    271     for my $ds_name (keys %{$service_config->{data_source}}) { 
    272         $self->_set_rrd_data_source_defaults($service_config->{data_source}{$ds_name}); 
    273  
    274         unless ($service_config->{data_source}{$ds_name}{label}) { 
    275             logger("[ERROR] Unable to update $service -> $ds_name: Missing data source configuration attribute: label"); 
    276             next; 
    277         } 
    278  
    279         my $rrd_file 
    280             = $self->_create_rrd_file_if_needed($service, $ds_name,  
    281                                                 $service_config->{data_source}{$ds_name}); 
    282  
    283         if (%$service_data and defined($service_data->{$ds_name})) { 
    284             $self->_update_rrd_file($rrd_file, $ds_name, $service_data->{$ds_name}); 
    285         } 
    286         else { 
    287             logger("[WARNING] Service $service returned no data"); 
    288         } 
     337    my ($self, $nested_service_config, $nested_service_data) = @_; 
     338 
     339    my $nodedesignation = $self->{host}{host_name}."/". 
     340        $self->{host}{address}.":".$self->{host}{port}; 
     341 
     342    for my $service (keys %{$nested_service_config->{data_source}}) { 
     343 
     344        my $service_config = $nested_service_config->{data_source}{$service}; 
     345        my $service_data   = $nested_service_data->{$service}; 
     346 
     347        for my $ds_name (keys %{$service_config}) { 
     348            $self->_set_rrd_data_source_defaults($service_config->{$ds_name}); 
     349 
     350            unless ($service_config->{$ds_name}{label}) { 
     351                ERROR "[ERROR] Unable to update $service on $nodedesignation -> $ds_name: Missing data source configuration attribute: label"; 
     352                next; 
     353            } 
     354 
     355            my $rrd_file  
     356                = $self->_create_rrd_file_if_needed($service, $ds_name,  
     357                                                    $service_config->{$ds_name}); 
     358 
     359            if (%$service_data and defined($service_data->{$ds_name})) { 
     360                $self->_update_rrd_file($rrd_file, $ds_name, $service_data->{$ds_name}); 
     361            } 
     362            else { 
     363                WARN "[WARNING] Service $service on $nodedesignation returned no data"; 
     364            } 
     365        } 
    289366    } 
    290367} 
     
    334411    } ($group, $file); 
    335412         
    336     logger("[DEBUG] Made rrd filename: $group / $file\n") if $config->{debug}
     413    DEBUG "[DEBUG] Made rrd filename: $group / $file\n"
    337414 
    338415    return File::Spec->catfile($config->{dbdir},  
     
    345422    my ($self, $rrd_file, $service, $ds_name, $ds_config) = @_; 
    346423 
    347     logger("creating rrd-file for $service->$ds_name: '$rrd_file'")
     424    INFO "[INFO] creating rrd-file for $service->$ds_name: '$rrd_file'"
    348425    mkpath(dirname($rrd_file), {mode => oct(777)}); 
    349426    my @args = ( 
     
    377454    RRDs::create @args; 
    378455    if (my $ERROR = RRDs::error) { 
    379         logger("[ERROR] Unable to create '$rrd_file': $ERROR")
     456        ERROR "[ERROR] Unable to create '$rrd_file': $ERROR"
    380457    } 
    381458} 
     
    403480    } 
    404481 
    405     logger("[DEBUG] Updating $rrd_file with $value") if $config->{debug}
     482    DEBUG "[DEBUG] Updating $rrd_file with ".$ds_values->{when}.":$value"
    406483    RRDs::update($rrd_file, "$ds_values->{when}:$value"); 
    407484    if (my $ERROR = RRDs::error) { 
    408         logger ("[ERROR] In RRD: unable to update $rrd_file: $ERROR")
     485        ERROR "[ERROR] In RRD: Error updating $rrd_file: $ERROR"
    409486    } 
    410487} 
  • trunk/master/t/munin_master_plugin_fetch.t

    r2676 r2726  
    2323 
    2424# print Dumper \%answer; 
     25 
     26=comment 
     27 
     28Keep old correct answer for reference. 
    2529 
    2630my $fasit = { 
     
    5559        }; 
    5660 
     61=cut 
     62 
     63my $fasit = { 
     64          'cpu' => { 
     65                     'irq' => { 
     66                                'when' => '1256305015', 
     67                                'value' => '2770' 
     68                              }, 
     69                     'system' => { 
     70                                   'when' => 'N', 
     71                                   'value' => '66594' 
     72                                 }, 
     73                     'softirq' => { 
     74                                    'when' => '1256305015', 
     75                                    'value' => '127' 
     76                                  }, 
     77                     'user' => { 
     78                                 'when' => 'N', 
     79                                 'value' => '145923' 
     80                               }, 
     81                     'iowait' => { 
     82                                   'when' => 'N', 
     83                                   'value' => '14375' 
     84                                 }, 
     85                     'idle' => { 
     86                                 'when' => 'N', 
     87                                 'value' => '2245122' 
     88                               }, 
     89                     'nice' => { 
     90                                 'when' => 'N', 
     91                                 'value' => '268' 
     92                               } 
     93                   } 
     94        }; 
     95 
    5796is_deeply(\%answer,$fasit,"Plugin fetch output"); 
    5897