aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/type/GenericIO.class.php
diff options
context:
space:
mode:
authorPim van den Berg2009-12-31 11:42:56 +0100
committerPim van den Berg2009-12-31 13:07:13 +0100
commit95c70c919837f588389f525fe2cf4aba479e9f91 (patch)
treeef242a0273458ffcadf8357fd8dd4d64b2fb7105 /type/GenericIO.class.php
parentalways show 'on $host' in the rrd title (diff)
downloadapt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.zip
apt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.tar.gz
apt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.tar.bz2
apt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.tar.xz
rewrite of type classes
A constructor is added to the Type_Default class. The constructor will parse GET values (such as host, plugin, pinstance, type, tinstance, seconds), create an array of all needed rrd files to generate a graph and substract identifiers from these rrd files. Because of the constructor (and related functions) it is not needed to define an array of tinstances to be grouped and shown in one graph. Also $obj->args don't have to be defined per plugin. This will result in smaller plugin files. The type classes are based on the fact that a plugin has multiple type instances OR multiple rrd data sources. This is called the source and is retrieved by rrd_get_sources in each rrd_gen_graph function. Also variables in function rrd_gen_graph have been renamed to better ones.
Diffstat (limited to 'type/GenericIO.class.php')
-rw-r--r--type/GenericIO.class.php51
1 files changed, 30 insertions, 21 deletions
diff --git a/type/GenericIO.class.php b/type/GenericIO.class.php
index e91cb16..ee04316 100644
--- a/type/GenericIO.class.php
+++ b/type/GenericIO.class.php
@@ -5,45 +5,54 @@ require_once 'Default.class.php';
5class Type_GenericIO extends Type_Default { 5class Type_GenericIO extends Type_Default {
6 6
7 function rrd_gen_graph() { 7 function rrd_gen_graph() {
8 $filename = $this->get_filename();
9
10 $rrdgraph = $this->rrd_options(); 8 $rrdgraph = $this->rrd_options();
11 9
10 $sources = $this->rrd_get_sources();
11
12 if ($this->scale) 12 if ($this->scale)
13 $raw = '_raw'; 13 $raw = '_raw';
14 foreach($this->data_sources as $ds) { 14 $i=0;
15 $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', $ds, $raw, $filename, $ds); 15 foreach ($this->tinstances as $tinstance) {
16 $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', $ds, $raw, $filename, $ds); 16 foreach ($this->data_sources as $ds) {
17 $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', $ds, $raw, $filename, $ds); 17 $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', $sources[$i], $raw, $this->files[$tinstance], $ds);
18 $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', $sources[$i], $raw, $this->files[$tinstance], $ds);
19 $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', $sources[$i], $raw, $this->files[$tinstance], $ds);
20 $i++;
21 }
18 } 22 }
19 if ($this->scale) { 23 if ($this->scale) {
20 foreach($this->data_sources as $ds) { 24 $i=0;
21 $rrdgraph[] = sprintf('CDEF:min_%s=min_%s_raw,%s,*', $ds, $ds, $this->scale); 25 foreach ($this->tinstances as $tinstance) {
22 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%s_raw,%s,*', $ds, $ds, $this->scale); 26 foreach ($this->data_sources as $ds) {
23 $rrdgraph[] = sprintf('CDEF:max_%s=max_%s_raw,%s,*', $ds, $ds, $this->scale); 27 $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', $sources[$i], $this->scale);
28 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', $sources[$i], $this->scale);
29 $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', $sources[$i], $this->scale);
30 $i++;
31 }
24 } 32 }
25 } 33 }
26 34
27 $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s,LT,avg_%1$s,avg_%2$s,IF', 35 $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s,LT,avg_%1$s,avg_%2$s,IF',
28 $this->data_sources[0], $this->data_sources[1]); 36 $sources[0], $sources[1]);
29 37
30 foreach($this->data_sources as $ds) { 38 foreach($sources as $source) {
31 $rrdgraph[] = sprintf('AREA:avg_%s#%s', $ds, $this->get_faded_color($this->colors[$ds])); 39 $rrdgraph[] = sprintf('AREA:avg_%s#%s', $source, $this->get_faded_color($this->colors[$source]));
32 } 40 }
33 41
34 $rrdgraph[] = sprintf('AREA:overlap#%s', 42 $rrdgraph[] = sprintf('AREA:overlap#%s',
35 $this->get_faded_color( 43 $this->get_faded_color(
36 $this->get_faded_color($this->colors[$this->data_sources[0]]), 44 $this->get_faded_color($this->colors[$sources[0]]),
37 $this->get_faded_color($this->colors[$this->data_sources[1]]) 45 $this->get_faded_color($this->colors[$sources[1]])
38 ) 46 )
39 ); 47 );
40 48
41 foreach($this->data_sources as $ds) { 49 foreach($sources as $source) {
42 $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', $ds, $this->colors[$ds], $this->ds_names[$ds]); 50 $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source;
43 $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $ds, $this->rrd_format); 51 $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', $source, $this->colors[$source], $dsname);
44 $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $ds, $this->rrd_format); 52 $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $source, $this->rrd_format);
45 $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $ds, $this->rrd_format); 53 $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $source, $this->rrd_format);
46 $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\l\'', $ds, $this->rrd_format); 54 $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $source, $this->rrd_format);
55 $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\l\'', $source, $this->rrd_format);
47 } 56 }
48 57
49 return $rrdgraph; 58 return $rrdgraph;