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 $rrd_title = $obj->getTitle ($idents->[0]);
37 my $colors = $obj->{'rrd_colors'} || {};
38 my @ret = ('-t', $rrd_title, @$rrd_opts);
40 if (defined $obj->{'rrd_vertical'})
42 push (@ret, '-v', $obj->{'rrd_vertical'});
45 if ($obj->{'custom_order'})
47 sort_idents_by_type_instance ($idents, $obj->{'custom_order'});
50 $obj->{'ds_names'} ||= {};
51 my @names = map { $obj->{'ds_names'}{$_->{'type_instance'}} || $_->{'type_instance'} } (@$idents);
53 for (my $i = 0; $i < @$idents; $i++)
55 my $ident = $idents->[$i];
56 my $filename = ident_to_filename ($ident);
58 if ($ds_name_len < length ($names[$i]))
60 $ds_name_len = length ($names[$i]);
63 # Escape colons _after_ the length has been checked.
64 $names[$i] =~ s/:/\\:/g;
67 "DEF:min${i}=${filename}:value:MIN",
68 "DEF:avg${i}=${filename}:value:AVERAGE",
69 "DEF:max${i}=${filename}:value:MAX");
72 for (my $i = @$idents - 1; $i >= 0; $i--)
74 if ($i == (@$idents - 1))
77 "CDEF:cdef${i}=avg${i}");
83 "CDEF:cdef${i}=cdef${j},avg${i},+");
87 for (my $i = 0; $i < @$idents; $i++)
89 my $type_instance = $idents->[$i]{'type_instance'};
91 if (exists $colors->{$type_instance})
93 $color = $colors->{$type_instance};
96 $color = get_faded_color ($color);
99 "AREA:cdef${i}#${color}");
102 for (my $i = 0; $i < @$idents; $i++)
104 my $type_instance = $idents->[$i]{'type_instance'};
105 my $ds_name = sprintf ("%-*s", $ds_name_len, $names[$i]);
106 my $color = '000000';
107 if (exists $colors->{$type_instance})
109 $color = $colors->{$type_instance};
112 "LINE1:cdef${i}#${color}:${ds_name}",
113 "GPRINT:min${i}:MIN:${format} Min,",
114 "GPRINT:avg${i}:AVERAGE:${format} Avg,",
115 "GPRINT:max${i}:MAX:${format} Max,",
116 "GPRINT:avg${i}:LAST:${format} Last\\l");
127 my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
128 my @group = sort (keys %$group);
130 my $idents = $group->{$group[$index]};
133 for (qw(hostname plugin plugin_instance type))
135 if (defined ($idents->[0]{$_}))
137 push (@args, $_ . '=' . $idents->[0]{$_});
141 return (join (';', @args));
145 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :