contrib/collection3: Add a vertical label to the “java_memory” type.
[collectd.git] / contrib / collection3 / lib / Collectd / Graph / Type / JavaMemory.pm
1 package Collectd::Graph::Type::JavaMemory;
2
3 # Copyright (C) 2008,2009  Florian octo Forster <octo at verplant.org>
4 #
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation; only version 2 of the License is applicable.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
18 use strict;
19 use warnings;
20 use base ('Collectd::Graph::Type');
21
22 use Collectd::Graph::Common (qw($ColorCanvas $ColorFullBlue $ColorHalfBlue
23   group_files_by_plugin_instance ident_to_filename sanitize_type_instance
24   get_faded_color sort_idents_by_type_instance));
25
26 return (1);
27
28 sub getGraphsNum
29 {
30   my $obj = shift;
31   my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
32
33   return (scalar (keys %$group));
34 }
35
36 sub getRRDArgs
37 {
38   my $obj = shift;
39   my $index = shift;
40
41   my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
42   my @group = sort (keys %$group);
43
44   my $rrd_opts = $obj->{'rrd_opts'} || [];
45   my $format = $obj->{'rrd_format'} || '%5.1lf';
46
47   my $idents = $group->{$group[$index]};
48   my %type_instance = ();
49
50   my $ds = $obj->getDataSources ();
51   if (!$ds)
52   {
53     confess ("obj->getDataSources failed.");
54   }
55   if (@$ds != 1)
56   {
57     confess ("I can only work with RRD files that have "
58       . "exactly one data source!");
59   }
60   my $data_source = $ds->[0];
61
62   my $rrd_title = $idents->[0]{'plugin_instance'};
63   $rrd_title =~ s/^memory_pool-//;
64   $rrd_title = "Memory pool \"$rrd_title\"";
65
66   my $ds_names =
67   {
68     max       => 'Max      ',
69     committed => 'Committed',
70     used      => 'Used     ',
71     init      => 'Init     '
72   };
73
74   my $colors =
75   {
76     max       => '00ff00',
77     committed => 'ff8000',
78     used      => 'ff0000',
79     init      => '0000f0',
80     'head-committed'    => '000000',
81     'head-init'         => '000000',
82     'head-max'          => '000000',
83     'head-used'         => '000000',
84     'nonhead-committed' => '000000',
85     'nonhead-init'      => '000000',
86     'nonhead-max'       => '000000',
87     'nonhead-used'      => '000000'
88   };
89   my @ret = ('-t', $rrd_title, @$rrd_opts);
90
91   if (defined $obj->{'rrd_vertical'})
92   {
93     push (@ret, '-v', $obj->{'rrd_vertical'});
94   }
95   else
96   {
97     push (@ret, '-v', "Bytes");
98   }
99
100   for (@$idents)
101   {
102     my $ident = $_;
103     if ($ident->{'type_instance'})
104     {
105       $type_instance{$ident->{'type_instance'}} = $ident;
106     }
107   }
108
109   if (exists ($type_instance{'committed'})
110     && exists ($type_instance{'init'})
111     && exists ($type_instance{'max'})
112     && exists ($type_instance{'used'}))
113   {
114     for (qw(max committed init used))
115     {
116       my $inst = $_;
117       my $file = ident_to_filename ($type_instance{$inst});
118       my $color = $colors->{$inst};
119       my $name = $ds_names->{$inst};
120       push (@ret,
121         "DEF:${inst}_min=${file}:value:MIN",
122         "DEF:${inst}_avg=${file}:value:AVERAGE",
123         "DEF:${inst}_max=${file}:value:MAX",
124         "AREA:${inst}_avg#${color}10",
125         "LINE1:${inst}_avg#${color}:${name}",
126         "GPRINT:${inst}_min:MIN:%5.1lf\%sB Min,",
127         "GPRINT:${inst}_avg:AVERAGE:%5.1lf\%sB Avg,",
128         "GPRINT:${inst}_max:MAX:%5.1lf\%sB Max,",
129         "GPRINT:${inst}_avg:LAST:%5.1lf\%sB Last\\l");
130     }
131     return (\@ret);
132   }
133   else
134   {
135     require Collectd::Graph::Type::GenericStacked;
136     return (Collectd::Graph::Type::GenericStacked::getRRDArgs ($obj, $index));
137   }
138 } # getRRDArgs
139
140 sub getGraphArgs
141 {
142   my $obj = shift;
143   my $index = shift;
144
145   my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
146   my @group = sort (keys %$group);
147
148   my $idents = $group->{$group[$index]};
149
150   my @args = ();
151   for (qw(hostname plugin plugin_instance type))
152   {
153     if (defined ($idents->[0]{$_}))
154     {
155       push (@args, $_ . '=' . $idents->[0]{$_});
156     }
157   }
158
159   return (join (';', @args));
160 } # getGraphArgs
161
162 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :