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 my $ignore_unknown = $obj->{'ignore_unknown'} || 0;
55 if ($ignore_unknown =~ m/^(yes|true|on)$/i)
65 if (defined $obj->{'rrd_vertical'})
67 push (@ret, '-v', $obj->{'rrd_vertical'});
70 if ($obj->{'custom_order'})
72 sort_idents_by_type_instance ($idents, $obj->{'custom_order'});
80 if (exists ($obj->{'ds_names'}{$_->{'type_instance'}}))
82 push (@$new_idents, $_);
88 $idents = $new_idents;
92 $obj->{'ds_names'} ||= {};
93 my @names = map { $obj->{'ds_names'}{$_->{'type_instance'}} || $_->{'type_instance'} } (@$idents);
95 for (my $i = 0; $i < @$idents; $i++)
97 my $ident = $idents->[$i];
98 my $filename = ident_to_filename ($ident);
100 if ($ds_name_len < length ($names[$i]))
102 $ds_name_len = length ($names[$i]);
105 # Escape colons _after_ the length has been checked.
106 $names[$i] =~ s/:/\\:/g;
109 "DEF:min${i}=${filename}:${data_source}:MIN",
110 "DEF:avg${i}=${filename}:${data_source}:AVERAGE",
111 "DEF:max${i}=${filename}:${data_source}:MAX");
114 for (my $i = @$idents - 1; $i >= 0; $i--)
116 if ($i == (@$idents - 1))
119 "CDEF:cdef${i}=avg${i}");
125 "CDEF:cdef${i}=cdef${j},avg${i},+");
129 for (my $i = 0; $i < @$idents; $i++)
131 my $type_instance = $idents->[$i]{'type_instance'};
132 my $color = '000000';
133 if (exists $colors->{$type_instance})
135 $color = $colors->{$type_instance};
138 $color = get_faded_color ($color);
141 "AREA:cdef${i}#${color}");
144 for (my $i = 0; $i < @$idents; $i++)
146 my $type_instance = $idents->[$i]{'type_instance'};
147 my $ds_name = sprintf ("%-*s", $ds_name_len, $names[$i]);
148 my $color = '000000';
149 if (exists $colors->{$type_instance})
151 $color = $colors->{$type_instance};
154 "LINE1:cdef${i}#${color}:${ds_name}",
155 "GPRINT:min${i}:MIN:${format} Min,",
156 "GPRINT:avg${i}:AVERAGE:${format} Avg,",
157 "GPRINT:max${i}:MAX:${format} Max,",
158 "GPRINT:avg${i}:LAST:${format} Last\\l");
169 my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
170 my @group = sort (keys %$group);
172 my $idents = $group->{$group[$index]};
175 for (qw(hostname plugin plugin_instance type))
177 if (defined ($idents->[0]{$_}))
179 push (@args, $_ . '=' . $idents->[0]{$_});
183 return (join (';', @args));
187 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :