Changeset 1764

Show
Ignore:
Timestamp:
12/03/08 18:31:31 (1 month ago)
Author:
jlmartinez
Message:

/rrdgraph

Support for selectively stacking some metrics. The rest get represented by lines

stack=1 still behaves in the same way as before

new behaviour: stack=metric1&stack=metric2&stack=metric3

will stack metric1, metric2 and metric3, if there are other metrics, they will be drawn with lines


Implementation notes:

The items that have to be stacked have to be put the first in the RRD, so they stack nicely one on top of the other in the order specified by the parameters. If not ordered, you get a LINE metric, and on top of that LINE, a stacked AREA.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/DEV-capside/opsview-web/lib/Opsview/Web/Controller/RRDgraph.pm

    r1763 r1764  
    6565        my $title = $params->{'title'}; 
    6666        my $stacked = $params->{stack} || 0; 
    67         my $type = "LINE1"; 
    68         if ($stacked) {          
    69                 $stacked = ":STACK"; 
    70                 $type = "AREA"; 
    71         } else { 
    72                 $stacked = ""; 
     67        my $all_stacked = 0; 
     68        if ($stacked eq '1') {   
     69                $all_stacked = ":STACK"; 
    7370        } 
    7471 
     
    8077        my $services = convert_to_arrayref($params->{service}); 
    8178        my $metrics = convert_to_arrayref($params->{metric}); 
     79        $stacked = convert_to_arrayref($params->{stack}); 
     80        my $order = convert_to_arrayref($params->{order}); 
     81 
    8282        my %metrics = map { ($_ => 1) } @$metrics; 
     83        my $pos = 1; 
     84        my %stacked = map { ($_ => $pos++) } @$stacked; 
    8385 
    8486        # Get list of all files in directory 
     
    149151                push @$rrdoptions, "--title", $title; 
    150152        } 
    151         foreach my $dsname (sort keys %$ds) { 
     153        foreach my $dsname (keys %$ds) { 
    152154                foreach my $hash (@{ $ds->{$dsname} }) { 
    153155                        # $vname is a unique datapoint name, stripped of invalid characters 
     
    183185        } 
    184186         
    185         foreach my $dsname (sort keys %$ds) { 
     187        foreach my $dsname (sort { if($stacked{ $a } or $stacked{ $b }){ 
     188                                        # if the column isn't stacked it has a very low priority (all 
     189                                        # stacked columns get rendered before unstacked ones)  
     190                                        return(($stacked{ $a } || 1000) <=> ($stacked{ $b } || 1000)) 
     191                                    } else {  
     192                                        return($a cmp $b);  
     193                                    }  
     194                                 } keys %$ds) { 
    186195                foreach my $hash (@{ $ds->{$dsname} }) { 
    187196                        my $f = $hash->{file}; 
     
    190199                        my $nextcolour = shift @colours; 
    191200                        my $fixedw_legend = $hash->{'legend'} . (' ' x ($max_legend_length - length($hash->{'legend'}))); 
     201                        my $stacked = (($all_stacked) or ($stacked{ $dsname }))?':STACK':'';  
     202                        my $type    = ($stacked eq '')?'LINE1':'AREA'; 
    192203                        push @$rrdoptions,  
    193204                                "DEF:$vname=$f:$dsname:AVERAGE",