validate_color($fgc); if (!is_numeric($percent)) $percent=0.25; $rgb = array('r', 'g', 'b'); $fg[r] = hexdec(substr($fgc,0,2)); $fg[g] = hexdec(substr($fgc,2,2)); $fg[b] = hexdec(substr($fgc,4,2)); $bg[r] = hexdec(substr($bgc,0,2)); $bg[g] = hexdec(substr($bgc,2,2)); $bg[b] = hexdec(substr($bgc,4,2)); foreach ($rgb as $pri) { $c[$pri] = dechex(round($percent * $fg[$pri]) + ((1.0 - $percent) * $bg[$pri])); if ($c[$pri] == '0') $c[$pri] = '00'; } return $c[r].$c[g].$c[b]; } function get_filename($tinstance=NULL) { if (!is_array($this->args['tinstance']) && $tinstance == NULL) $tinstance = $this->args['tinstance']; $search = array('{host}', '{plugin}', '{pinstance}', '{type}', '{tinstance}'); $replace = array($this->args['host'], $this->args['plugin'], $this->args['pinstance'], $this->args['type'], $tinstance); $f = $this->datadir . '/' . str_replace($search, $replace, $this->path_format); return $f; } function rrd_graph($debug=false) { $graphdata = $this->rrd_gen_graph(); if(!$debug) { # caching header("Expires: " . date(DATE_RFC822,strtotime("90 seconds"))); header("content-type: image/png"); $graphdata = implode(' ', $graphdata); echo `$graphdata`; } else { print '
';
			print_r($graphdata);
			print '
'; } } function rrd_gen_graph() { $filename = $this->get_filename(); $rrdgraph[] = '/usr/bin/rrdtool graph - -a PNG'; $rrdgraph[] = sprintf('-w %d', is_numeric($this->width) ? $this->width : 400); $rrdgraph[] = sprintf('-h %d', is_numeric($this->heigth) ? $this->heigth : 175); $rrdgraph[] = '-l 0'; $rrdgraph[] = sprintf('-t "%s"', $this->rrd_title); $rrdgraph[] = sprintf('-v "%s"', $this->rrd_vertical); $rrdgraph[] = sprintf('-s -%d', is_numeric($this->seconds) ? $this->seconds : 86400); if (is_array($this->args['tinstance'])) $array = is_array($this->order) ? $this->order : $this->args['tinstance']; else $array = $this->data_sources; $i=0; foreach ($array as $value) { if (is_array($this->args['tinstance'])) { $filename = $this->get_filename($value); $ds = $this->data_sources[0]; } else { $filename = $this->get_filename(); $ds = $value; } $rrdgraph[] = sprintf('DEF:min%s=%s:%s:MIN', $i, $filename, $ds); $rrdgraph[] = sprintf('DEF:avg%s=%s:%s:AVERAGE', $i, $filename, $ds); $rrdgraph[] = sprintf('DEF:max%s=%s:%s:MAX', $i, $filename, $ds); $i++; } if (!is_array($this->args['tinstance'])) { $rrdgraph[] = sprintf('AREA:max0#%s', $this->get_faded_color($this->colors[$this->data_sources[0]])); $rrdgraph[] = sprintf('AREA:min0#%s', 'ffffff'); } $i=0; foreach ($array as $value) { $dsname = $this->ds_names[$value] != '' ? $this->ds_names[$value] : $value; $color = is_array($this->colors) ? $this->colors[$value]: $this->colors; $rrdgraph[] = sprintf('LINE1:avg%d#%s:\'%s\'', $i, $this->validate_color($color), $dsname); $rrdgraph[] = sprintf('GPRINT:min%d:MIN:\'%s Min,\'', $i, $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg%d:AVERAGE:\'%s Avg,\'', $i, $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:max%d:MAX:\'%s Max,\'', $i, $this->rrd_format); $rrdgraph[] = sprintf('GPRINT:avg%d:LAST:\'%s Last\\l\'', $i, $this->rrd_format); $i++; } return $rrdgraph; } } ?>