1 package Collectd::Graph::Type::GenericIO;
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 Carp ('confess');
24 use Collectd::Graph::Common (qw($ColorCanvas ident_to_filename get_faded_color));
26 return (1);
28 sub getRRDArgs
29 {
30 my $obj = shift;
31 my $index = shift;
33 my $ident = $obj->{'files'}[$index] || confess ("Unknown index $index");
34 my $filename = ident_to_filename ($ident);
36 my $rrd_opts = $obj->{'rrd_opts'} || [];
37 my $rrd_title = $obj->getTitle ($ident);
38 my $format = $obj->{'rrd_format'} || '%5.1lf%s';
40 my $ds_list = $obj->getDataSources ();
41 my $ds_names = $obj->{'ds_names'};
42 if (!$ds_names)
43 {
44 $ds_names = {};
45 }
47 my $colors = $obj->{'rrd_colors'} || {};
48 my @ret = ('-t', $rrd_title, @$rrd_opts);
50 if (defined $obj->{'rrd_vertical'})
51 {
52 push (@ret, '-v', $obj->{'rrd_vertical'});
53 }
55 if (@$ds_list != 2)
56 {
57 my $num = 0 + @$ds_list;
58 confess ("Expected two data sources, but there is/are $num");
59 }
61 my $rx_ds = $ds_list->[0];
62 my $tx_ds = $ds_list->[1];
64 my $rx_ds_name = $ds_names->{$rx_ds} || $rx_ds;
65 my $tx_ds_name = $ds_names->{$tx_ds} || $tx_ds;
67 my $rx_color_fg = $colors->{$rx_ds} || '0000ff';
68 my $tx_color_fg = $colors->{$tx_ds} || '00b000';
70 my $rx_color_bg = get_faded_color ($rx_color_fg);
71 my $tx_color_bg = get_faded_color ($tx_color_fg);
72 my $overlap_color = get_faded_color ($rx_color_bg, background => $tx_color_bg);
74 $filename =~ s#:#\\:#g;
75 $rx_ds =~ s#:#\\:#g;
76 $tx_ds =~ s#:#\\:#g;
77 $rx_ds_name =~ s#:#\\:#g;
78 $tx_ds_name =~ s#:#\\:#g;
80 if ($obj->{'scale'})
81 {
82 my $factor = $obj->{'scale'};
84 push (@ret,
85 "DEF:min_rx_raw=${filename}:${rx_ds}:MIN",
86 "DEF:avg_rx_raw=${filename}:${rx_ds}:AVERAGE",
87 "DEF:max_rx_raw=${filename}:${rx_ds}:MAX",
88 "DEF:min_tx_raw=${filename}:${tx_ds}:MIN",
89 "DEF:avg_tx_raw=${filename}:${tx_ds}:AVERAGE",
90 "DEF:max_tx_raw=${filename}:${tx_ds}:MAX",
91 "CDEF:min_rx=min_rx_raw,${factor},*",
92 "CDEF:avg_rx=avg_rx_raw,${factor},*",
93 "CDEF:max_rx=max_rx_raw,${factor},*",
94 "CDEF:min_tx=min_tx_raw,${factor},*",
95 "CDEF:avg_tx=avg_tx_raw,${factor},*",
96 "CDEF:max_tx=max_tx_raw,${factor},*");
97 }
98 else # (!$obj->{'scale'})
99 {
100 push (@ret,
101 "DEF:min_rx=${filename}:${rx_ds}:MIN",
102 "DEF:avg_rx=${filename}:${rx_ds}:AVERAGE",
103 "DEF:max_rx=${filename}:${rx_ds}:MAX",
104 "DEF:min_tx=${filename}:${tx_ds}:MIN",
105 "DEF:avg_tx=${filename}:${tx_ds}:AVERAGE",
106 "DEF:max_tx=${filename}:${tx_ds}:MAX");
107 }
109 push (@ret,
110 "CDEF:avg_rx_bytes=avg_rx,8,/",
111 "VDEF:global_min_rx=min_rx,MINIMUM",
112 "VDEF:global_avg_rx=avg_rx,AVERAGE",
113 "VDEF:global_max_rx=max_rx,MAXIMUM",
114 "VDEF:global_tot_rx=avg_rx_bytes,TOTAL",
115 "CDEF:avg_tx_bytes=avg_tx,8,/",
116 "VDEF:global_min_tx=min_tx,MINIMUM",
117 "VDEF:global_avg_tx=avg_tx,AVERAGE",
118 "VDEF:global_max_tx=max_tx,MAXIMUM",
119 "VDEF:global_tot_tx=avg_tx_bytes,TOTAL");
121 push (@ret,
122 "CDEF:overlap=avg_rx,avg_tx,LT,avg_rx,avg_tx,IF",
123 "AREA:avg_rx#${rx_color_bg}",
124 "AREA:avg_tx#${tx_color_bg}",
125 "AREA:overlap#${overlap_color}",
126 "LINE1:avg_rx#${rx_color_fg}:${rx_ds_name}",
127 "GPRINT:global_min_rx:${format} Min,",
128 "GPRINT:global_avg_rx:${format} Avg,",
129 "GPRINT:global_max_rx:${format} Max,",
130 "GPRINT:global_tot_rx:ca. ${format} Total\\l",
131 "LINE1:avg_tx#${tx_color_fg}:${tx_ds_name}",
132 "GPRINT:global_min_tx:${format} Min,",
133 "GPRINT:global_avg_tx:${format} Avg,",
134 "GPRINT:global_max_tx:${format} Max,",
135 "GPRINT:global_tot_tx:ca. ${format} Total\\l");
137 return (\@ret);
138 } # getRRDArgs
140 # vim: set shiftwidth=2 softtabstop=2 tabstop=8 :