832b136002f370a6cb22b3d252643f489e757002
[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
96   for (@$idents)
97   {
98     my $ident = $_;
99     if ($ident->{'type_instance'})
100     {
101       $type_instance{$ident->{'type_instance'}} = $ident;
102     }
103   }
104
105   if (exists ($type_instance{'committed'})
106     && exists ($type_instance{'init'})
107     && exists ($type_instance{'max'})
108     && exists ($type_instance{'used'}))
109   {
110     for (qw(max committed init used))
111     {
112       my $inst = $_;
113       my $file = ident_to_filename ($type_instance{$inst});
114       my $color = $colors->{$inst};
115       my $name = $ds_names->{$inst};
116       push (@ret,
117         "DEF:${inst}_min=${file}:value:MIN",
118         "DEF:${inst}_avg=${file}:value:AVERAGE",
119         "DEF:${inst}_max=${file}:value:MAX",
120         "AREA:${inst}_avg#${color}10",
121         "LINE1:${inst}_avg#${color}:${name}",
122         "GPRINT:${inst}_min:MIN:%5.1lf\%sB Min,",
123         "GPRINT:${inst}_avg:AVERAGE:%5.1lf\%sB Avg,",
124         "GPRINT:${inst}_max:MAX:%5.1lf\%sB Max,",
125         "GPRINT:${inst}_avg:LAST:%5.1lf\%sB Last\\l");
126     }
127     return (\@ret);
128   }
129   else
130   {
131     require Collectd::Graph::Type::GenericStacked;
132     return (Collectd::Graph::Type::GenericStacked::getRRDArgs ($obj, $index));
133   }
134 } # getRRDArgs
135
136 sub getGraphArgs
137 {
138   my $obj = shift;
139   my $index = shift;
140
141   my $group = group_files_by_plugin_instance (@{$obj->{'files'}});
142   my @group = sort (keys %$group);
143
144   my $idents = $group->{$group[$index]};
145
146   my @args = ();
147   for (qw(hostname plugin plugin_instance type))
148   {
149     if (defined ($idents->[0]{$_}))
150     {
151       push (@args, $_ . '=' . $idents->[0]{$_});
152     }
153   }
154
155   return (join (';', @args));
156 } # getGraphArgs
157
158 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :