Merge branch 'collectd-4.10' into collectd-5.0
[collectd.git] / contrib / collection3 / lib / Collectd / Graph / Type / Df.pm
1 package Collectd::Graph::Type::Df;
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(ident_to_filename get_faded_color));
23
24 return (1);
25
26 sub getDataSources
27 {
28   return ([qw(free used)]);
29 } # getDataSources
30
31 sub new
32 {
33   my $pkg = shift;
34   my $obj = Collectd::Graph::Type->new (@_);
35   $obj->{'data_sources'} = [qw(free used)];
36   $obj->{'rrd_opts'} = ['-v', 'Bytes'];
37   $obj->{'rrd_title'} = 'Disk space ({instance})';
38   $obj->{'rrd_format'} = '%5.1lf%sB';
39   $obj->{'colors'} = [qw(00b000 ff0000)];
40
41   return (bless ($obj, $pkg));
42 } # new
43
44 sub getRRDArgs
45 {
46   my $obj = shift;
47   my $index = shift;
48
49   my $ident = $obj->{'files'}[$index];
50   if (!$ident)
51   {
52     cluck ("Invalid index: $index");
53     return;
54   }
55   my $filename = ident_to_filename ($ident);
56   $filename =~ s#:#\\:#g;
57
58   my $faded_green = get_faded_color ('00ff00');
59   my $faded_red = get_faded_color ('ff0000');
60
61   return (['-t', $obj->getTitle ($ident), '-v', 'Bytes', '-l', '0',
62     "DEF:free_min=${filename}:free:MIN",
63     "DEF:free_avg=${filename}:free:AVERAGE",
64     "DEF:free_max=${filename}:free:MAX",
65     "DEF:used_min=${filename}:used:MIN",
66     "DEF:used_avg=${filename}:used:AVERAGE",
67     "DEF:used_max=${filename}:used:MAX",
68     "CDEF:both_avg=free_avg,used_avg,+",
69     "AREA:both_avg#${faded_green}",
70     "AREA:used_avg#${faded_red}",
71     'LINE1:both_avg#00ff00:Free',
72     'GPRINT:free_min:MIN:%5.1lf%sB Min,',
73     'GPRINT:free_avg:AVERAGE:%5.1lf%sB Avg,',
74     'GPRINT:free_max:MAX:%5.1lf%sB Max,',
75     'GPRINT:free_avg:LAST:%5.1lf%sB Last\l',
76     'LINE1:used_avg#ff0000:Used',
77     'GPRINT:used_min:MIN:%5.1lf%sB Min,',
78     'GPRINT:used_avg:AVERAGE:%5.1lf%sB Avg,',
79     'GPRINT:used_max:MAX:%5.1lf%sB Max,',
80     'GPRINT:used_avg:LAST:%5.1lf%sB Last\l']);
81 } # getRRDArgs
82
83 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :