1 package Collectd::Graph::Type::GenericStacked;
5 use base ('Collectd::Graph::Type');
7 use Collectd::Graph::Common (qw($ColorCanvas $ColorFullBlue $ColorHalfBlue
8 group_files_by_plugin_instance ident_to_filename sanitize_type_instance
9 get_faded_color sort_idents_by_type_instance));
16 my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
18 return (scalar (keys %$group));
26 my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
27 my @group = sort (keys %$group);
29 my $rrd_opts = $obj->{'rrd_opts'} || [];
30 my $format = $obj->{'rrd_format'} || '%5.1lf';
32 my $idents = $group->{$group[$index]};
35 my $ds = $obj->getDataSources ();
38 confess ("obj->getDataSources failed.");
42 confess ("I can only work with RRD files that have "
43 . "exactly one data source!");
45 my $data_source = $ds->[0];
47 my $rrd_title = $obj->getTitle ($idents->[0]);
49 my $colors = $obj->{'rrd_colors'} || {};
50 my @ret = ('-t', $rrd_title, @$rrd_opts);
52 if (defined $obj->{'rrd_vertical'})
54 push (@ret, '-v', $obj->{'rrd_vertical'});
57 if ($obj->{'custom_order'})
59 sort_idents_by_type_instance ($idents, $obj->{'custom_order'});
62 $obj->{'ds_names'} ||= {};
63 my @names = map { $obj->{'ds_names'}{$_->{'type_instance'}} || $_->{'type_instance'} } (@$idents);
65 for (my $i = 0; $i < @$idents; $i++)
67 my $ident = $idents->[$i];
68 my $filename = ident_to_filename ($ident);
70 if ($ds_name_len < length ($names[$i]))
72 $ds_name_len = length ($names[$i]);
75 # Escape colons _after_ the length has been checked.
76 $names[$i] =~ s/:/\\:/g;
79 "DEF:min${i}=${filename}:${data_source}:MIN",
80 "DEF:avg${i}=${filename}:${data_source}:AVERAGE",
81 "DEF:max${i}=${filename}:${data_source}:MAX");
84 for (my $i = @$idents - 1; $i >= 0; $i--)
86 if ($i == (@$idents - 1))
89 "CDEF:cdef${i}=avg${i}");
95 "CDEF:cdef${i}=cdef${j},avg${i},+");
99 for (my $i = 0; $i < @$idents; $i++)
101 my $type_instance = $idents->[$i]{'type_instance'};
102 my $color = '000000';
103 if (exists $colors->{$type_instance})
105 $color = $colors->{$type_instance};
108 $color = get_faded_color ($color);
111 "AREA:cdef${i}#${color}");
114 for (my $i = 0; $i < @$idents; $i++)
116 my $type_instance = $idents->[$i]{'type_instance'};
117 my $ds_name = sprintf ("%-*s", $ds_name_len, $names[$i]);
118 my $color = '000000';
119 if (exists $colors->{$type_instance})
121 $color = $colors->{$type_instance};
124 "LINE1:cdef${i}#${color}:${ds_name}",
125 "GPRINT:min${i}:MIN:${format} Min,",
126 "GPRINT:avg${i}:AVERAGE:${format} Avg,",
127 "GPRINT:max${i}:MAX:${format} Max,",
128 "GPRINT:avg${i}:LAST:${format} Last\\l");
139 my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
140 my @group = sort (keys %$group);
142 my $idents = $group->{$group[$index]};
145 for (qw(hostname plugin plugin_instance type))
147 if (defined ($idents->[0]{$_}))
149 push (@args, $_ . '=' . $idents->[0]{$_});
153 return (join (';', @args));
157 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :