diff options
author | Pim van den Berg | 2013-05-18 16:05:43 +0200 |
---|---|---|
committer | Pim van den Berg | 2013-05-18 16:08:09 +0200 |
commit | 5793a8cd003643974206e44ea752ab0966cfa8c0 (patch) | |
tree | 387a6a327af9834f2986ad3316be2183949d897a /type | |
parent | jsrrdgraph: RrdGraph.js: fix undefined 2nd argument of RrdVdef function (diff) | |
download | apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.zip apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.tar.gz apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.tar.bz2 apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.tar.xz |
integrate jsrrdgraph in CGP
Diffstat (limited to 'type')
-rw-r--r-- | type/Default.class.php | 80 | ||||
-rw-r--r-- | type/GenericIO.class.php | 18 | ||||
-rw-r--r-- | type/GenericStacked.class.php | 16 | ||||
-rw-r--r-- | type/Uptime.class.php | 16 |
4 files changed, 77 insertions, 53 deletions
diff --git a/type/Default.class.php b/type/Default.class.php index 514d1c1..c9220fa 100644 --- a/type/Default.class.php +++ b/type/Default.class.php | |||
@@ -36,6 +36,7 @@ class Type_Default { | |||
36 | if (empty($this->width)) $this->width = $config['width']; | 36 | if (empty($this->width)) $this->width = $config['width']; |
37 | $this->heigth = GET('y'); | 37 | $this->heigth = GET('y'); |
38 | if (empty($this->heigth)) $this->heigth = $config['heigth']; | 38 | if (empty($this->heigth)) $this->heigth = $config['heigth']; |
39 | $this->graph_type = $config['graph_type']; | ||
39 | } | 40 | } |
40 | 41 | ||
41 | function rainbow_colors() { | 42 | function rainbow_colors() { |
@@ -108,6 +109,13 @@ class Type_Default { | |||
108 | return str_replace(':', '\:', $value); | 109 | return str_replace(':', '\:', $value); |
109 | } | 110 | } |
110 | 111 | ||
112 | function parse_filename($file) { | ||
113 | if ($this->graph_type == 'canvas') { | ||
114 | $file = 'rrd' . str_replace($this->datadir, '', $file); | ||
115 | } | ||
116 | return $this->rrd_escape($file); | ||
117 | } | ||
118 | |||
111 | function rrd_files() { | 119 | function rrd_files() { |
112 | $files = $this->get_filenames(); | 120 | $files = $this->get_filenames(); |
113 | 121 | ||
@@ -153,35 +161,51 @@ class Type_Default { | |||
153 | return $files; | 161 | return $files; |
154 | } | 162 | } |
155 | 163 | ||
156 | function rrd_graph($debug=false) { | 164 | function rrd_graph($debug = false) { |
157 | if (!$this->colors) | 165 | if (!$this->colors) |
158 | $this->rainbow_colors(); | 166 | $this->rainbow_colors(); |
159 | 167 | ||
160 | $graphdata = $this->rrd_gen_graph(); | 168 | $graphdata = $this->rrd_gen_graph(); |
161 | 169 | ||
162 | if(!$debug) { | 170 | $style = $debug !== false ? $debug : $this->graph_type; |
163 | # caching | 171 | switch ($style) { |
164 | if (is_numeric($this->cache) && $this->cache > 0) | 172 | case 'cmd': |
165 | header("Expires: " . date(DATE_RFC822,strtotime($this->cache." seconds"))); | 173 | print '<pre>'; |
166 | header("content-type: image/png"); | 174 | foreach ($graphdata as $d) { |
167 | $graphdata = implode(' ', $graphdata); | 175 | printf("%s \\\n", $d); |
168 | echo `$graphdata`; | 176 | } |
169 | } elseif ($debug == 'cmd') { | 177 | print '</pre>'; |
170 | print '<pre>'; | 178 | break; |
171 | foreach ($graphdata as $d) { | 179 | case 'canvas': |
172 | printf("%s \\\n", $d); | 180 | printf('<canvas id="%s" class="rrd">', sha1(serialize($graphdata))); |
173 | } | 181 | foreach ($graphdata as $d) { |
174 | print '</pre>'; | 182 | printf("%s\n", $d); |
175 | } else { | 183 | } |
176 | print '<pre>'; | 184 | print '</canvas>'; |
177 | print_r($graphdata); | 185 | break; |
178 | print '</pre>'; | 186 | case 'debug': |
187 | case 1: | ||
188 | print '<pre>'; | ||
189 | print_r($graphdata); | ||
190 | print '</pre>'; | ||
191 | break; | ||
192 | case 'png': | ||
193 | default: | ||
194 | # caching | ||
195 | if (is_numeric($this->cache) && $this->cache > 0) | ||
196 | header("Expires: " . date(DATE_RFC822,strtotime($this->cache." seconds"))); | ||
197 | header("content-type: image/png"); | ||
198 | $graphdata = implode(' ', $graphdata); | ||
199 | echo `$graphdata`; | ||
200 | break; | ||
179 | } | 201 | } |
180 | } | 202 | } |
181 | 203 | ||
182 | function rrd_options() { | 204 | function rrd_options() { |
183 | $rrdgraph[] = $this->rrdtool; | 205 | if ($this->graph_type != 'canvas') { |
184 | $rrdgraph[] = 'graph - -a PNG'; | 206 | $rrdgraph[] = $this->rrdtool; |
207 | $rrdgraph[] = 'graph - -a PNG'; | ||
208 | } | ||
185 | if ($this->rrdtool_opts != '') | 209 | if ($this->rrdtool_opts != '') |
186 | $rrdgraph[] = $this->rrdtool_opts; | 210 | $rrdgraph[] = $this->rrdtool_opts; |
187 | $rrdgraph[] = sprintf('-w %d', is_numeric($this->width) ? $this->width : 400); | 211 | $rrdgraph[] = sprintf('-w %d', is_numeric($this->width) ? $this->width : 400); |
@@ -260,9 +284,9 @@ class Type_Default { | |||
260 | $i=0; | 284 | $i=0; |
261 | foreach ($this->tinstances as $tinstance) { | 285 | foreach ($this->tinstances as $tinstance) { |
262 | foreach ($this->data_sources as $ds) { | 286 | foreach ($this->data_sources as $ds) { |
263 | $rrdgraph[] = sprintf('DEF:min_%s%s="%s":%s:MIN', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 287 | $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
264 | $rrdgraph[] = sprintf('DEF:avg_%s%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 288 | $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
265 | $rrdgraph[] = sprintf('DEF:max_%s%s="%s":%s:MAX', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 289 | $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
266 | $i++; | 290 | $i++; |
267 | } | 291 | } |
268 | } | 292 | } |
@@ -292,11 +316,11 @@ class Type_Default { | |||
292 | foreach ($sources as $source) { | 316 | foreach ($sources as $source) { |
293 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; | 317 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
294 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]): $this->colors; | 318 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]): $this->colors; |
295 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $this->rrd_escape($dsname)); | 319 | $rrdgraph[] = sprintf('"LINE1:avg_%s#%s:%s"', crc32hex($source), $this->validate_color($color), $this->rrd_escape($dsname)); |
296 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); | 320 | $rrdgraph[] = sprintf('"GPRINT:min_%s:MIN:%s Min,"', crc32hex($source), $this->rrd_format); |
297 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); | 321 | $rrdgraph[] = sprintf('"GPRINT:avg_%s:AVERAGE:%s Avg,"', crc32hex($source), $this->rrd_format); |
298 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format); | 322 | $rrdgraph[] = sprintf('"GPRINT:max_%s:MAX:%s Max,"', crc32hex($source), $this->rrd_format); |
299 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', crc32hex($source), $this->rrd_format); | 323 | $rrdgraph[] = sprintf('"GPRINT:avg_%s:LAST:%s Last\\l"', crc32hex($source), $this->rrd_format); |
300 | } | 324 | } |
301 | 325 | ||
302 | return $rrdgraph; | 326 | return $rrdgraph; |
diff --git a/type/GenericIO.class.php b/type/GenericIO.class.php index 42314fd..0cf3e22 100644 --- a/type/GenericIO.class.php +++ b/type/GenericIO.class.php | |||
@@ -15,9 +15,9 @@ class Type_GenericIO extends Type_Default { | |||
15 | $i=0; | 15 | $i=0; |
16 | foreach ($this->tinstances as $tinstance) { | 16 | foreach ($this->tinstances as $tinstance) { |
17 | foreach ($this->data_sources as $ds) { | 17 | foreach ($this->data_sources as $ds) { |
18 | $rrdgraph[] = sprintf('DEF:min_%s%s="%s":%s:MIN', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 18 | $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
19 | $rrdgraph[] = sprintf('DEF:avg_%s%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 19 | $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
20 | $rrdgraph[] = sprintf('DEF:max_%s%s="%s":%s:MAX', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 20 | $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
21 | if (!$this->scale) | 21 | if (!$this->scale) |
22 | $rrdgraph[] = sprintf('VDEF:tot_%s=avg_%1$s,TOTAL', crc32hex($sources[$i])); | 22 | $rrdgraph[] = sprintf('VDEF:tot_%s=avg_%1$s,TOTAL', crc32hex($sources[$i])); |
23 | $i++; | 23 | $i++; |
@@ -52,12 +52,12 @@ class Type_GenericIO extends Type_Default { | |||
52 | 52 | ||
53 | foreach($sources as $source) { | 53 | foreach($sources as $source) { |
54 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; | 54 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
55 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->colors[$source], $this->rrd_escape($dsname)); | 55 | $rrdgraph[] = sprintf('"LINE1:avg_%s#%s:%s"', crc32hex($source), $this->colors[$source], $this->rrd_escape($dsname)); |
56 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); | 56 | $rrdgraph[] = sprintf('"GPRINT:min_%s:MIN:%s Min,"', crc32hex($source), $this->rrd_format); |
57 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); | 57 | $rrdgraph[] = sprintf('"GPRINT:avg_%s:AVERAGE:%s Avg,"', crc32hex($source), $this->rrd_format); |
58 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format); | 58 | $rrdgraph[] = sprintf('"GPRINT:max_%s:MAX:%s Max,"', crc32hex($source), $this->rrd_format); |
59 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\'', crc32hex($source), $this->rrd_format); | 59 | $rrdgraph[] = sprintf('"GPRINT:avg_%s:LAST:%s Last"', crc32hex($source), $this->rrd_format); |
60 | $rrdgraph[] = sprintf('GPRINT:tot_%s:\'%s Total\l\'',crc32hex($source), $this->rrd_format); | 60 | $rrdgraph[] = sprintf('"GPRINT:tot_%s:%s Total\l"',crc32hex($source), $this->rrd_format); |
61 | } | 61 | } |
62 | 62 | ||
63 | return $rrdgraph; | 63 | return $rrdgraph; |
diff --git a/type/GenericStacked.class.php b/type/GenericStacked.class.php index 7c65ddd..5d1a556 100644 --- a/type/GenericStacked.class.php +++ b/type/GenericStacked.class.php | |||
@@ -15,9 +15,9 @@ class Type_GenericStacked extends Type_Default { | |||
15 | $i=0; | 15 | $i=0; |
16 | foreach ($this->tinstances as $tinstance) { | 16 | foreach ($this->tinstances as $tinstance) { |
17 | foreach ($this->data_sources as $ds) { | 17 | foreach ($this->data_sources as $ds) { |
18 | $rrdgraph[] = sprintf('DEF:min_%s%s="%s":%s:MIN', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 18 | $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
19 | $rrdgraph[] = sprintf('DEF:avg_%s%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 19 | $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
20 | $rrdgraph[] = sprintf('DEF:max_%s%s="%s":%s:MAX', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds); | 20 | $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds); |
21 | $i++; | 21 | $i++; |
22 | } | 22 | } |
23 | } | 23 | } |
@@ -51,11 +51,11 @@ class Type_GenericStacked extends Type_Default { | |||
51 | foreach ($sources as $source) { | 51 | foreach ($sources as $source) { |
52 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; | 52 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
53 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; | 53 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; |
54 | $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $this->rrd_escape($dsname)); | 54 | $rrdgraph[] = sprintf('"LINE1:area_%s#%s:%s"', crc32hex($source), $this->validate_color($color), $this->rrd_escape($dsname)); |
55 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format); | 55 | $rrdgraph[] = sprintf('"GPRINT:min_%s:MIN:%s Min,"', crc32hex($source), $this->rrd_format); |
56 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format); | 56 | $rrdgraph[] = sprintf('"GPRINT:avg_%s:AVERAGE:%s Avg,"', crc32hex($source), $this->rrd_format); |
57 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format); | 57 | $rrdgraph[] = sprintf('"GPRINT:max_%s:MAX:%s Max,"', crc32hex($source), $this->rrd_format); |
58 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', crc32hex($source), $this->rrd_format); | 58 | $rrdgraph[] = sprintf('"GPRINT:avg_%s:LAST:%s Last\\l"', crc32hex($source), $this->rrd_format); |
59 | } | 59 | } |
60 | 60 | ||
61 | return $rrdgraph; | 61 | return $rrdgraph; |
diff --git a/type/Uptime.class.php b/type/Uptime.class.php index aa91a6e..17bcb9a 100644 --- a/type/Uptime.class.php +++ b/type/Uptime.class.php | |||
@@ -12,8 +12,8 @@ class Type_Uptime extends Type_Default { | |||
12 | $i=0; | 12 | $i=0; |
13 | foreach ($this->tinstances as $tinstance) { | 13 | foreach ($this->tinstances as $tinstance) { |
14 | foreach ($this->data_sources as $ds) { | 14 | foreach ($this->data_sources as $ds) { |
15 | $rrdgraph[] = sprintf('DEF:avg_%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $this->rrd_escape($this->files[$tinstance]), $ds); | 15 | $rrdgraph[] = sprintf('DEF:avg_%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $this->parse_filename($this->files[$tinstance]), $ds); |
16 | $rrdgraph[] = sprintf('DEF:max_%s="%s":%s:MAX', crc32hex($sources[$i]), $this->rrd_escape($this->files[$tinstance]), $ds); | 16 | $rrdgraph[] = sprintf('DEF:max_%s=%s:%s:MAX', crc32hex($sources[$i]), $this->parse_filename($this->files[$tinstance]), $ds); |
17 | 17 | ||
18 | $rrdgraph[] = sprintf('CDEF:c_avg_%s=avg_%1$s,86400,/', crc32hex($sources[$i])); | 18 | $rrdgraph[] = sprintf('CDEF:c_avg_%s=avg_%1$s,86400,/', crc32hex($sources[$i])); |
19 | $rrdgraph[] = sprintf('CDEF:c_max_%s=max_%1$s,86400,/', crc32hex($sources[$i])); | 19 | $rrdgraph[] = sprintf('CDEF:c_max_%s=max_%1$s,86400,/', crc32hex($sources[$i])); |
@@ -45,16 +45,16 @@ class Type_Uptime extends Type_Default { | |||
45 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; | 45 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; |
46 | 46 | ||
47 | //current value | 47 | //current value |
48 | $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $this->rrd_escape($dsname)); | 48 | $rrdgraph[] = sprintf('"LINE1:area_%s#%s:%s"', crc32hex($source), $this->validate_color($color), $this->rrd_escape($dsname)); |
49 | $rrdgraph[] = sprintf('GPRINT:c_avg_%s:LAST:\'%s days\\l\'', crc32hex($source), $this->rrd_format); | 49 | $rrdgraph[] = sprintf('"GPRINT:c_avg_%s:LAST:%s days\\l"', crc32hex($source), $this->rrd_format); |
50 | 50 | ||
51 | //max value | 51 | //max value |
52 | $rrdgraph[] = sprintf('LINE1:v_max_%s#FF0000:\'Maximum\':dashes', crc32hex($source)); | 52 | $rrdgraph[] = sprintf('"LINE1:v_max_%s#FF0000:Maximum:dashes"', crc32hex($source)); |
53 | $rrdgraph[] = sprintf('GPRINT:v_max_%s:\'%s days\\l\'', crc32hex($source), $this->rrd_format); | 53 | $rrdgraph[] = sprintf('"GPRINT:v_max_%s:%s days\\l"', crc32hex($source), $this->rrd_format); |
54 | 54 | ||
55 | //avg value | 55 | //avg value |
56 | $rrdgraph[] = sprintf('LINE1:v_avg_%s#0000FF:\'Average\':dashes', crc32hex($source)); | 56 | $rrdgraph[] = sprintf('"LINE1:v_avg_%s#0000FF:Average:dashes"', crc32hex($source)); |
57 | $rrdgraph[] = sprintf('GPRINT:v_avg_%s:\'%s days\\l\'', crc32hex($source), $this->rrd_format); | 57 | $rrdgraph[] = sprintf('"GPRINT:v_avg_%s:%s days\\l"', crc32hex($source), $this->rrd_format); |
58 | } | 58 | } |
59 | 59 | ||
60 | return $rrdgraph; | 60 | return $rrdgraph; |