Code

Merge branch 'collectd-4.6'
[collectd.git] / contrib / collection3 / lib / Collectd / Graph / Type / PsCputime.pm
1 package Collectd::Graph::Type::PsCputime;
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.
18 use strict;
19 use warnings;
20 use base ('Collectd::Graph::Type');
22 use Collectd::Graph::Common (qw(ident_to_filename get_faded_color));
24 return (1);
26 sub getDataSources
27 {
28   return ([qw(syst user)]);
29 } # getDataSources
31 sub new
32 {
33   my $pkg = shift;
34   my $obj = Collectd::Graph::Type->new (@_);
35   $obj->{'data_sources'} = [qw(syst user)];
36   $obj->{'rrd_opts'} = ['-v', 'CPU time [s]', '-l', '0'];
37   $obj->{'rrd_title'} = 'CPU time used by {plugin_instance}';
38   $obj->{'rrd_format'} = '%5.1lf';
39   $obj->{'colors'} = [qw(00b000 ff0000)];
41   return (bless ($obj, $pkg));
42 } # new
44 sub getRRDArgs
45 {
46   my $obj = shift;
47   my $index = shift;
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;
58   my $faded_blue = get_faded_color ('0000ff');
59   my $faded_red = get_faded_color ('ff0000');
61   return (['-t', $obj->getTitle (), @{$obj->{'rrd_opts'}},
62     "DEF:user_min_raw=${filename}:user:MIN",
63     "DEF:user_avg_raw=${filename}:user:AVERAGE",
64     "DEF:user_max_raw=${filename}:user:MAX",
65     "DEF:syst_min_raw=${filename}:syst:MIN",
66     "DEF:syst_avg_raw=${filename}:syst:AVERAGE",
67     "DEF:syst_max_raw=${filename}:syst:MAX",
68     "CDEF:user_min=0.000001,user_min_raw,*",
69     "CDEF:user_avg=0.000001,user_avg_raw,*",
70     "CDEF:user_max=0.000001,user_max_raw,*",
71     "CDEF:syst_min=0.000001,syst_min_raw,*",
72     "CDEF:syst_avg=0.000001,syst_avg_raw,*",
73     "CDEF:syst_max=0.000001,syst_max_raw,*",
74     "VDEF:v_user_min=user_min,MINIMUM",
75     "VDEF:v_user_avg=user_avg,AVERAGE",
76     "VDEF:v_user_max=user_max,MAXIMUM",
77     "VDEF:v_user_lst=syst_avg,LAST",
78     "VDEF:v_syst_min=syst_min,MINIMUM",
79     "VDEF:v_syst_avg=syst_avg,AVERAGE",
80     "VDEF:v_syst_max=syst_max,MAXIMUM",
81     "VDEF:v_syst_lst=syst_avg,LAST",
82     "CDEF:user_stack=syst_avg,user_avg,+",
83     "AREA:user_stack#${faded_blue}",
84     'LINE1:user_stack#0000ff:User  ',
85     'GPRINT:v_user_min:%5.1lf%ss Min,',
86     'GPRINT:v_user_avg:%5.1lf%ss Avg,',
87     'GPRINT:v_user_max:%5.1lf%ss Max,',
88     'GPRINT:v_user_lst:%5.1lf%ss Last\l',
89     "AREA:syst_avg#${faded_red}",
90     'LINE1:syst_avg#ff0000:System',
91     'GPRINT:v_syst_min:%5.1lf%ss Min,',
92     'GPRINT:v_syst_avg:%5.1lf%ss Avg,',
93     'GPRINT:v_syst_max:%5.1lf%ss Max,',
94     'GPRINT:v_syst_lst:%5.1lf%ss Last\l']);
95 } # getRRDArgs
97 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :