Changeset 1297

Show
Ignore:
Timestamp:
08/28/07 16:07:44 (4 years ago)
Author:
jo
Message:

Milestone 2 finished; munin-graph should now work properly with multilevel groups.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • people/jo/multilevel-groups/server/Munin.pm.in

    r1296 r1297  
    6060           'munin_copy_node_toloc', 
    6161           'munin_get_separated_node', 
    62            'munin_mkdir_p' 
     62           'munin_mkdir_p', 
     63           'munin_get_node_partialpath' 
    6364           ); 
    6465 
     
    573574} 
    574575 
     576# munin_get_node_partialpath: gets a node froma partial path 
     577# Parameters:  
     578# - $hash: A ref to the "current" location in the hash tree 
     579# - $var: A path string with relative location (from the $hash). 
     580# Returns: 
     581# - Success: The node 
     582# - Failure: undef 
     583sub munin_get_node_partialpath 
     584{ 
     585    my $hash = shift; 
     586    my $var  = shift; 
     587    my $ret  = undef; 
     588 
     589    return undef if !defined $hash or ref ($hash) ne "HASH"; 
     590 
     591    my $root    = munin_get_root_node ($hash); 
     592    my $hashloc = munin_get_node_loc ($hash); 
     593    my $varloc  = undef; 
     594 
     595    if ($var =~ /^\s*([^:]+):(\S+)\s*$/) { 
     596        my ($leftstring, $rightstring) = ($1, $2); 
     597 
     598        my @leftarr = split (/;/, $leftstring); 
     599        my @rightarr = split (/\./, $rightstring); 
     600        push @$varloc, @leftarr, @rightarr 
     601    } elsif ($var =~ /^\s*([^;:\.]+)\s*$/) { 
     602        push @$varloc, $var; 
     603    } elsif ($var =~ /^\s*(.+)\.([^\.:;]+)$/) { 
     604        my ($leftstring, $rightstring) = ($1, $2); 
     605 
     606        my @leftarr = split (/;/, $leftstring); 
     607        my @rightarr = split (/\./, $rightstring); 
     608        push @$varloc, @leftarr, @rightarr; 
     609    } elsif ($var =~ /^\s*(\S+)\s*$/) { 
     610        my @leftarr = split (/;/, $1); 
     611        push @$varloc, @leftarr; 
     612    } else { 
     613        ::logger ("Error: munin_get_node_partialpath: Malformatted variable path \"$var\"."); 
     614    } 
     615 
     616    # We've got both parts of the loc (varloc and hashloc) -- let's figure out  
     617    # where they meet up. 
     618    do { 
     619        $ret = munin_get_node ($root, [@$hashloc, @$varloc]); 
     620    } while (!defined $ret and pop @$hashloc); 
     621 
     622    return $ret; 
     623} 
     624 
    575625# munin_set_var_path: sets a variable in a hash 
    576626# Parameters:  
     
    11871237    my $name    = munin_get_node_name ($field); 
    11881238 
     1239    # Bail out on bad input data 
     1240    return undef if !defined $field or ref ($field) ne "HASH"; 
     1241 
    11891242    # If the field has a .filename setting, use it 
    11901243    return $result if $result = munin_get ($field, "filename"); 
     
    11921245    # Handle custom paths (used in .sum, .stack, graph_order, et al) 
    11931246    if (defined $path and length $path) { 
    1194         if (!munin_get ($field, "label")) { 
    1195             print "DEBUG: Setting label: $name\n" if $DEBUG; 
    1196             munin_set_var_loc ($field, ["label"], $name); 
    1197         } 
    1198  
    1199         my $sourcenode = munin_get_node (munin_get_root_node ($field), munin_path_to_loc ($path)); 
     1247 
     1248        my $sourcenode = munin_get_node_partialpath ($field, $path); 
    12001249        $result = munin_get_filename ($sourcenode); 
    12011250 
  • people/jo/multilevel-groups/server/munin-graph.in

    r1296 r1297  
    319319    my $fieldnum = 0; 
    320320    for my $field (@$order) { # Search for 'specials'... 
    321  
    322         if ($field =~ /^-(.+)$/) { 
     321        my $tmp_field; 
     322 
     323        if ($field =~ /^-(.+)$/) { # Invisible field 
    323324            $field = $1; 
    324325            munin_set_var_loc ($service, [$field, "graph"], "no"); 
     
    326327 
    327328        $fieldnum++; 
    328         my $tmp_field; 
    329         if (defined ($tmp_field = &get_stack_command ($service->{$field}))) { 
    330             print "DEBUG: Doing special_stack...\n" if $DEBUG; 
     329        if ($field =~ /^([^=]+)=(.+)$/) { # Aliased in graph_order 
     330            my $fname = $1; 
     331            my $spath = $2; 
     332            my $src   = munin_get_node_partialpath ($service, $spath); 
     333            my $sname = munin_get_node_name ($src); 
     334 
     335            next unless defined $src; 
     336            logger ("Debug: Copying settings from $sname to $fname.") if $DEBUG; 
     337 
     338            foreach my $foption ("draw", "type", "rrdfile", "fieldname", "info") { 
     339                if (!defined $service->{$fname}->{$foption}) { 
     340                    if (defined $src->{$foption}) { 
     341                        munin_set_var_loc ($service, [$fname, $foption], $src->{$foption}); 
     342                    } 
     343                } 
     344            } 
     345 
     346            # cdef is special... 
     347            if (!defined $service->{$fname}->{"cdef"}) { 
     348                if (defined $src->{"cdef"}) { 
     349                    (my $tmpcdef = $src->{"cdef"}) =~ s/([,=])$sname([,=]|$)/$1$fname$2/g; 
     350                    munin_set_var_loc ($service, [$fname, "cdef"], $tmpcdef); 
     351                } 
     352            } 
     353             
     354            munin_set_var_loc ($service, [$fname, "label"], $fname); 
     355            munin_set_var_loc ($service, [$fname, "filename"], munin_get_rrd_filename ($src)); 
     356 
     357        } elsif (defined ($tmp_field = get_stack_command ($service->{$field}))) { 
     358            logger ("DEBUG: expand_specials ($tmp_field): Doing stack...") if $DEBUG; 
    331359            my @spc_stack = (); 
    332360            foreach my $pre (split (/\s+/, $tmp_field)) { 
    333361                (my $name = $pre) =~ s/=.+//; 
    334362                if (!@spc_stack) { 
    335                     munin_set_var_loc ($service->{$name}, ["draw"], munin_get ($service->{$field}, "draw")); 
    336                     munin_set_var_loc ($service->{$field}, ["process"], "no"); 
     363                    munin_set_var_loc ($service, [$name, "draw"], munin_get ($service->{$field}, "draw", "LINE2")); 
     364                    munin_set_var_loc ($service, [$field, "process"], "no"); 
    337365                } else { 
    338                     munin_set_var_loc ($service->{$name}, ["draw"], "STACK"); 
     366                    munin_set_var_loc ($service, [$name, "draw"], "STACK"); 
    339367                } 
    340368                push (@spc_stack, $name); 
     
    344372                push @$result, "$name.cdef"; 
    345373 
    346                 munin_set_var_loc ($service->{$name}, ["label"], $name); 
    347                 munin_set_var_loc ($service->{$name}, ["cdef"], "$name,UN,0,$name,IF"); 
     374                munin_set_var_loc ($service, [$name, "label"], $name); 
     375                munin_set_var_loc ($service, [$name, "cdef"], "$name,UN,0,$name,IF"); 
    348376                if (munin_get ($service->{$field}, "cdef") and !munin_get_bool ($service->{$name}, "onlynullcdef", 0)) { 
    349                     print "NotOnlynullcdef ($field)...\n" if $DEBUG; 
     377                    logger ("NotOnlynullcdef ($field)...") if $DEBUG; 
    350378                    $service->{$name}->{"cdef"} .= "," . $service->{$field}->{"cdef"}; 
    351379                    $service->{$name}->{"cdef"} =~ s/\b$field\b/$name/g; 
    352380                } else { 
    353                     print "Onlynullcdef ($field)...\n" if $DEBUG; 
    354                     munin_set_var_loc ($service->{$name}, ["onlynullcdef"], 1); 
     381                    logger ("Onlynullcdef ($field)...") if $DEBUG; 
     382                    munin_set_var_loc ($service, [$name, "onlynullcdef"], 1); 
    355383                    push @$result, "$name.onlynullcdef"; 
    356384                } 
    357385            } 
    358         } elsif (defined ($tmp_field = &get_sum_command ($service->{$field}))) { 
     386        } elsif (defined ($tmp_field = get_sum_command ($service->{$field}))) { 
    359387            my @spc_stack = (); 
    360388            my $last_name = ""; 
    361             print "DEBUG: Doing special_sum...\n" if $DEBUG; 
     389            logger ("DEBUG: expand_specials ($tmp_field): Doing sum...") if $DEBUG; 
    362390 
    363391            if (@$order == 1 or (@$order == 2 and munin_get {$field, "negative", 0})) { 
     
    451479 
    452480    # See if we should skip the service 
    453     next if (skip_service ($service)); 
     481    return if (skip_service ($service)); 
    454482 
    455483    my $field_count = 0; 
     
    471499 
    472500    # Get max label length 
    473     $max_field_len = &munin_get_max_label_length ($service, \@field_order); 
     501    $max_field_len = munin_get_max_label_length ($service, \@field_order); 
    474502 
    475503    # Global headers makes the value tables easier to read no matter how 
     
    505533    logger ("DEBUG: Treating fields \"" . join ("\",\"", @field_order) . "\".") if $DEBUG; 
    506534    for my $fname (@field_order) { 
    507         my $field = munin_get_node ($service, [$fname]); 
    508535        my $path     = undef; 
     536        my $field    = undef; 
    509537 
    510538        if ($fname =~ s/=(.+)//) { 
    511539            $path = $1; 
    512540        } 
     541        $field = munin_get_node ($service, [$fname]); 
    513542 
    514543        next if !process_field ($field); 
    515         logger ("DEBUG: Processing field \"$fname\".") if $DEBUG; 
     544        logger ("DEBUG: Processing field \"$fname\" [".munin_get_node_name($field)."].") if $DEBUG; 
    516545 
    517546        my $fielddraw = munin_get ($field, "draw", "LINE2"); 
     
    794823        RRDs::graph (@complete); 
    795824        if (my $ERROR = RRDs::error) { 
    796             logger ("Unable to graph $filename: $ERROR"); 
     825            logger ("Unable to graph ". munin_get_picture_filename ($service, $time) . ": $ERROR"); 
    797826        } elsif ($list_images) { 
    798827            # Command-line option to list images created 
     
    876905 
    877906            if (my $ERROR = RRDs::error) { 
    878                 logger ("Unable to graph $filename: $ERROR"); 
     907                logger ("Unable to graph ". munin_get_picture_filename ($service, $time) . ": $ERROR"); 
    879908            } elsif ($list_images) { 
    880909                # Command-line option to list images created 
     
    888917    print STATS "GS|$service_time\n" unless $skip_stats; 
    889918 
     919    print "Final look of service subtree: ", Dumper (munin_get_separated_node ($service)), "\n\n"; 
    890920    foreach (@added) { 
    891921        delete $service->{$_} if exists $service->{$_}; 
     
    914944sub skip_service { 
    915945    my $service = shift; 
     946    my $sname   = munin_get_node_name ($service); 
     947 
     948    # Skip if we've limited services with cli options 
     949    return 1 if (@limit_services and !grep /^$sname$/, @limit_services); 
    916950 
    917951    # Always graph if --force is present