Merge branch 'master' into sr/pf
[collectd.git] / contrib / collection3 / lib / Collectd / Graph / Type / Wirkleistung.pm
1 package Collectd::Graph::Type::Wirkleistung;
2
3 # Copyright (C) 2009  Stefan Pfab <spfab at noris.net>
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(wirkleistung)]);
29 } # getDataSources
30
31 sub new
32 {
33   my $pkg = shift;
34   my $obj = Collectd::Graph::Type->new (@_);
35   $obj->{'data_sources'} = [qw(wirkleistung)];
36   $obj->{'rrd_opts'} = ['-v', 'Watt'];
37   $obj->{'rrd_title'} = 'Wirkleistung ({type_instance})';
38   $obj->{'rrd_format'} = '%5.1lf%s W';
39   $obj->{'colors'} = [qw(000000 f00000)];
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', 'Wirkleistung (' . $ident->{'type_instance'} . ')', '-v', 'Watt', '-l', '0',
62     "DEF:min0=${filename}:kWh:MIN",
63     "DEF:avg0=${filename}:kWh:AVERAGE",
64     "DEF:max0=${filename}:kWh:MAX",
65     'AREA:max0#bfbfbf',
66     'AREA:min0#FFFFFF',
67     'CDEF:watt_avg0=avg0,36000,*,',
68     'CDEF:watt_min0=min0,36000,*,',
69     'CDEF:watt_max0=max0,36000,*,',
70     'CDEF:watt_total=avg0,10,*,',
71     'VDEF:total=watt_total,TOTAL',
72     'VDEF:first=watt_total,FIRST',
73     'VDEF:last=watt_total,LAST',
74     #'CDEF:first_value=first,POP',
75     #'CDEF:first_time=first,POP',
76     'LINE1:watt_avg0#000000:W',
77     'HRULE:190#ff0000',
78     'GPRINT:watt_min0:MIN:%4.1lfW Min,',
79     'GPRINT:watt_avg0:AVERAGE:%4.1lfW Avg,',
80     'GPRINT:watt_max0:MAX:%4.1lfW Max,',
81     'GPRINT:watt_avg0:LAST:%4.1lfW Last\l',
82     'GPRINT:total:%4.1lf%sWh Gesamtverbrauch im angezeigten Zeitraum\l',
83     'GPRINT:first:erster Wert %c:strftime',
84     'GPRINT:last:letzter Wert %c:strftime']);
85
86     # HRULE:190\ ff0000    
87
88 } # getRRDArgs
89
90 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :