diff options
Diffstat (limited to 'type/Default.class.php')
-rw-r--r-- | type/Default.class.php | 80 |
1 files changed, 52 insertions, 28 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; |