function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     $raw = null;
     if ($this->scale) {
         $raw = '_raw';
     }
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $i++;
         }
     }
     if ($this->scale) {
         $i = 0;
         foreach ($this->tinstances as $tinstance) {
             foreach ($this->data_sources as $ds) {
                 $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $i++;
             }
         }
     }
     for ($i = count($sources) - 1; $i >= 0; $i--) {
         if ($i == count($sources) - 1) {
             $rrdgraph[] = sprintf('CDEF:area_%s=avg_%1$s', crc32hex($sources[$i]));
         } else {
             $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,ADDNAN', crc32hex($sources[$i]), crc32hex($sources[$i + 1]));
         }
     }
     $c = 0;
     foreach ($sources as $source) {
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         $php_color = new Color($color);
         $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $php_color->darken(20));
         $rrdgraph[] = sprintf('LINE1:area_%s#%s', crc32hex($source), $php_color->lighten());
         $rrdgraph[] = sprintf('AREA:min_%s#%s', crc32hex($source), $php_color->darken(10));
     }
     $c = 0;
     foreach ($sources as $source) {
         $legend = empty($this->legend[$source]) ? $source : $this->legend[$source];
         #			$color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors;
         #			$rrdgraph[] = sprintf('LINE1:area_%s#%s:%s', crc32hex($source), $this->validate_color($color), $this->rrd_escape($legend));
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:%s Min,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:%s Avg,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:%s Max,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:%s Last\\l', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     if ($this->scale) {
         $raw = '_raw';
     } else {
         $raw = null;
     }
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $i++;
         }
     }
     if ($this->scale) {
         $i = 0;
         foreach ($this->tinstances as $tinstance) {
             foreach ($this->data_sources as $ds) {
                 $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $i++;
             }
         }
     }
     if ($this->graph_minmax) {
         $c = 0;
         foreach ($sources as $source) {
             $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
             $rrdgraph[] = sprintf('LINE1:max_%s#%s', crc32hex($source), $this->get_faded_color($color));
             $rrdgraph[] = sprintf('LINE1:min_%s#%s', crc32hex($source), $this->get_faded_color($color));
         }
     }
     $c = 0;
     foreach ($sources as $source) {
         $legend = empty($this->legend[$source]) ? $source : $this->legend[$source];
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         $rrdgraph[] = sprintf('LINE1:avg_%s#%s:%s', crc32hex($source), $this->validate_color($color), $this->rrd_escape($legend));
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:%s Min,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:%s Avg,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:%s Max,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:%s Last\\l', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     if ($this->scale) {
         $raw = '_raw';
     }
     $i = 0;
     if (!isset($raw)) {
         $raw = "";
     }
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s%s="%s":%s:MIN', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s%s="%s":%s:MAX', crc32hex($sources[$i]), $raw, $this->rrd_escape($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('VDEF:tot_%1$s=avg_%1$s%2$s,TOTAL', crc32hex($sources[$i]), $raw);
             $i++;
         }
     }
     if ($this->scale) {
         $i = 0;
         foreach ($this->tinstances as $tinstance) {
             foreach ($this->data_sources as $ds) {
                 $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('VDEF:tot_%1$s=avg_%1$s,TOTAL', crc32hex($sources[$i]));
                 $i++;
             }
         }
     }
     $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s,LT,avg_%1$s,avg_%2$s,IF', crc32hex($sources[0]), crc32hex($sources[1]));
     foreach ($sources as $source) {
         $rrdgraph[] = sprintf('AREA:avg_%s#%s', crc32hex($source), $this->get_faded_color($this->colors[$source]));
     }
     $rrdgraph[] = sprintf('AREA:overlap#%s', $this->get_faded_color($this->get_faded_color($this->colors[$sources[0]]), $this->get_faded_color($this->colors[$sources[1]])));
     foreach ($sources as $source) {
         $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source;
         $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->colors[$source], $dsname);
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:tot_%s:\'%s Total\\l\'', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:avg_%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s=%s:%s:MAX', crc32hex($sources[$i]), $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('CDEF:c_avg_%s=avg_%1$s,86400,/', crc32hex($sources[$i]));
             $rrdgraph[] = sprintf('CDEF:c_max_%s=max_%1$s,86400,/', crc32hex($sources[$i]));
             $rrdgraph[] = sprintf('VDEF:v_avg_%s=c_avg_%1$s,AVERAGE', crc32hex($sources[$i]));
             $rrdgraph[] = sprintf('VDEF:v_max_%s=c_max_%1$s,MAXIMUM', crc32hex($sources[$i]));
             $i++;
         }
     }
     for ($i = count($sources) - 1; $i >= 0; $i--) {
         if ($i == count($sources) - 1) {
             $rrdgraph[] = sprintf('CDEF:area_%s=c_avg_%1$s', crc32hex($sources[$i]));
         } else {
             $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,c_avg_%1$s,+', crc32hex($sources[$i]), crc32hex($sources[$i + 1]));
         }
     }
     $c = 0;
     foreach ($sources as $source) {
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         $color = $this->get_faded_color($color);
         $rrdgraph[] = sprintf('AREA:area_%s#%s', crc32hex($source), $color);
     }
     $c = 0;
     foreach ($sources as $source) {
         $legend = empty($this->legend[$source]) ? $source : $this->legend[$source];
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         //current value
         $rrdgraph[] = sprintf('LINE1:area_%s#%s:%s', crc32hex($source), $this->validate_color($color), $this->rrd_escape($legend));
         $rrdgraph[] = sprintf('GPRINT:c_avg_%s:LAST:%s days\\l', crc32hex($source), $this->rrd_format);
         //max value
         $rrdgraph[] = sprintf('LINE1:v_max_%s#FF0000:Maximum:dashes', crc32hex($source));
         $rrdgraph[] = sprintf('GPRINT:v_max_%s:%s days\\l', crc32hex($source), $this->rrd_format);
         //avg value
         $rrdgraph[] = sprintf('LINE1:v_avg_%s#0000FF:Average:dashes', crc32hex($source));
         $rrdgraph[] = sprintf('GPRINT:v_avg_%s:%s days\\l', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s="%s":%s:MIN', crc32hex($sources[$i]), $this->rrd_escape($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $this->rrd_escape($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s="%s":%s:MAX', crc32hex($sources[$i]), $this->rrd_escape($this->files[$tinstance]), $ds);
             $i++;
         }
     }
     for ($i = count($sources) - 1; $i >= 0; $i--) {
         if ($i == count($sources) - 1) {
             $rrdgraph[] = sprintf('CDEF:area_%s=avg_%1$s', crc32hex($sources[$i]));
         } else {
             $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,+', crc32hex($sources[$i]), crc32hex($sources[$i + 1]));
         }
     }
     $c = 0;
     foreach ($sources as $source) {
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         $color = $this->get_faded_color($color);
         $rrdgraph[] = sprintf('AREA:area_%s#%s', crc32hex($source), $color);
     }
     $c = 0;
     foreach ($sources as $source) {
         $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source;
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname);
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }
Beispiel #6
0
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s="%s":%s:MIN', crc32hex($sources[$i]), $this->files[$tinstance], $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s="%s":%s:AVERAGE', crc32hex($sources[$i]), $this->files[$tinstance], $ds);
             $rrdgraph[] = sprintf('DEF:max_%s="%s":%s:MAX', crc32hex($sources[$i]), $this->files[$tinstance], $ds);
             $i++;
         }
     }
     if (count($this->files) <= 1) {
         $c = 0;
         foreach ($sources as $source) {
             $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
             $rrdgraph[] = sprintf('AREA:max_%s#%s', crc32hex($source), $this->get_faded_color($color));
             $rrdgraph[] = sprintf('AREA:min_%s#%s', crc32hex($source), 'ffffff');
             break;
             # only 1 area to draw
         }
     }
     $c = 0;
     foreach ($sources as $source) {
         $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source;
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname);
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     $raw = null;
     if ($this->scale) {
         $raw = '_raw';
     }
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s_raw=%s:%s:AVERAGE', crc32hex($sources[$i]), $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             if (!$this->scale) {
                 $rrdgraph[] = sprintf('VDEF:tot_%s=avg_%1$s,TOTAL', crc32hex($sources[$i]));
             }
             $i++;
         }
     }
     if ($this->scale) {
         $i = 0;
         foreach ($this->tinstances as $tinstance) {
             foreach ($this->data_sources as $ds) {
                 $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 if ($i == 1) {
                     $rrdgraph[] = sprintf('CDEF:avg_%s_neg=avg_%1$s_raw,%s%s,*', crc32hex($sources[$i]), $this->negative_io ? '-' : '', $this->scale);
                 }
                 $rrdgraph[] = sprintf('VDEF:tot_%1$s=avg_%1$s,TOTAL', crc32hex($sources[$i]));
                 if ($this->percentile) {
                     $rrdgraph[] = sprintf('VDEF:pct_%1$s=avg_%1$s,%2$s,PERCENT', crc32hex($sources[$i]), $this->percentile);
                 }
                 if ($this->percentile && $this->negative_io && $i == 1) {
                     $rrdgraph[] = sprintf('VDEF:pct_%1$s_neg=avg_%1$s_neg,%2$s,PERCENT', crc32hex($sources[$i]), 100 - $this->percentile);
                 }
                 $i++;
             }
         }
     }
     $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s_neg,LT,avg_%1$s,avg_%2$s_neg,IF', crc32hex($sources[0]), crc32hex($sources[1]));
     $i = 0;
     foreach ($sources as $source) {
         $rrdgraph[] = sprintf('AREA:avg_%s%s#%s', crc32hex($source), $i == 1 ? '_neg' : '', $this->get_faded_color($this->colors[$source]));
         $i++;
     }
     if (!$this->negative_io) {
         $rrdgraph[] = sprintf('AREA:overlap#%s', $this->get_faded_color($this->get_faded_color($this->colors[$sources[0]]), $this->get_faded_color($this->colors[$sources[1]])));
     }
     $i = 0;
     foreach ($sources as $source) {
         $legend = empty($this->legend[$source]) ? $source : $this->legend[$source];
         $rrdgraph[] = sprintf('LINE1:avg_%s%s#%s:%s', crc32hex($source), $i == 1 ? '_neg' : '', $this->colors[$source], $this->rrd_escape($legend));
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:%s Min,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:%s Avg,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:%s Max,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:%s Last', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:tot_%s:%s Total\\l', crc32hex($source), $this->rrd_format);
         $i++;
     }
     if ($this->percentile) {
         $rrdgraph[] = 'COMMENT: \\l';
         $i = 0;
         foreach ($sources as $source) {
             $legend = empty($this->legend[$source]) ? $source : $this->legend[$source];
             $rrdgraph[] = sprintf('LINE:pct_%s%s#%s:%sth Percentile %s', crc32hex($source), $i == 1 && $this->negative_io ? '_neg' : '', $this->get_faded_color($this->colors[$source], '000000', 0.6), $this->percentile, $this->rrd_escape($legend));
             $rrdgraph[] = sprintf('GPRINT:pct_%s:%s\\l', crc32hex($source), $this->rrd_format);
             $i++;
         }
     }
     return $rrdgraph;
 }
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     $raw = null;
     if ($this->scale) {
         $raw = '_raw';
     }
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $i++;
         }
     }
     if ($this->scale) {
         $i = 0;
         foreach ($this->tinstances as $tinstance) {
             foreach ($this->data_sources as $ds) {
                 $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $i++;
             }
         }
     }
     for ($i = count($sources) - 1; $i >= 0; $i--) {
         if ($i == count($sources) - 1) {
             $rrdgraph[] = sprintf('CDEF:area_%s=avg_%1$s', crc32hex($sources[$i]));
         } else {
             $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,ADDNAN', crc32hex($sources[$i]), crc32hex($sources[$i + 1]));
         }
     }
     $c = 0;
     foreach ($sources as $source) {
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         #$color = $this->get_faded_color($color);
         $tmp = crc32hex($source);
         $rrdgraph[] = sprintf('CDEF:shading10_%s=area_%s,0.90,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading10_%s#E50C00', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading15_%s=area_%s,0.85,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading15_%s#d90c0a', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading20_%s=area_%s,0.80,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading20_%s#CE0C15', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading25_%s=area_%s,0.75,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading25_%s#c30d20', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading30_%s=area_%s,0.70,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading30_%s#B80D2B', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading35_%s=area_%s,0.65,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading35_%s#ad0e36', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading40_%s=area_%s,0.60,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading40_%s#a20e41', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading45_%s=area_%s,0.55,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading45_%s#970f4b', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading50_%s=area_%s,0.50,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading50_%s#8c0f56', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading55_%s=area_%s,0.45,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading55_%s#811061', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading60_%s=area_%s,0.40,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading60_%s#75106c', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading65_%s=area_%s,0.35,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading65_%s#6a1177', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading70_%s=area_%s,0.30,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading70_%s#5f1182', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading75_%s=area_%s,0.25,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading75_%s#54128c', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading80_%s=area_%s,0.20,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading80_%s#491297', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading85_%s=area_%s,0.15,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading85_%s#3e13a2', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading90_%s=area_%s,0.10,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading90_%s#3313ad', $tmp);
         $rrdgraph[] = sprintf('CDEF:shading95_%s=area_%s,0.05,*', $tmp, $tmp);
         $rrdgraph[] = sprintf('AREA:shading95_%s#2814b8', $tmp);
     }
     $c = 0;
     foreach ($sources as $source) {
         $legend = empty($this->legend[$source]) ? $source : $this->legend[$source];
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         #$rrdgraph[] = sprintf('LINE1:area_%s#%s:%s', crc32hex($source), $this->validate_color($color), $this->rrd_escape($legend));
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:%s Min,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:%s Avg,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:%s Max,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:%s Last\\l', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }
 function rrd_gen_graph()
 {
     $rrdgraph = $this->rrd_options();
     $sources = $this->rrd_get_sources();
     $raw = null;
     if ($this->scale) {
         $raw = '_raw';
     }
     $i = 0;
     foreach ($this->tinstances as $tinstance) {
         foreach ($this->data_sources as $ds) {
             $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', crc32hex($sources[$i]), $raw, $this->parse_filename($this->files[$tinstance]), $ds);
             $i++;
         }
     }
     if ($this->scale) {
         $i = 0;
         foreach ($this->tinstances as $tinstance) {
             foreach ($this->data_sources as $ds) {
                 $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', crc32hex($sources[$i]), $this->scale);
                 $i++;
             }
         }
     }
     for ($i = count($sources) - 1; $i >= 0; $i--) {
         if ($i == count($sources) - 1) {
             $rrdgraph[] = sprintf('CDEF:area_%s=avg_%1$s', crc32hex($sources[$i]));
         } else {
             $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,ADDNAN', crc32hex($sources[$i]), crc32hex($sources[$i + 1]));
         }
     }
     $c = 0;
     foreach ($sources as $source) {
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         #$color = $this->get_faded_color($color);
         $tmp = crc32hex($source);
         $rrdgraph[] = sprintf('AREA:60#ce0c15');
         $rrdgraph[] = sprintf('AREA:55#ce0c15');
         $rrdgraph[] = sprintf('AREA:50#ce0c15');
         $rrdgraph[] = sprintf('AREA:45#ce0c15');
         $rrdgraph[] = sprintf('AREA:40#c20c1f');
         $rrdgraph[] = sprintf('AREA:35#b70d2a');
         $rrdgraph[] = sprintf('AREA:30#ac0d35');
         $rrdgraph[] = sprintf('AREA:25#a10e40');
         $rrdgraph[] = sprintf('AREA:20#960e4b');
         $rrdgraph[] = sprintf('AREA:15#8b0f56');
         $rrdgraph[] = sprintf('AREA:10#800f61');
         $rrdgraph[] = sprintf('AREA:05#75106b');
         $rrdgraph[] = sprintf('AREA:00#6a1076');
         $rrdgraph[] = sprintf('AREA:00#54118c');
         $rrdgraph[] = sprintf('AREA:-20#2814b8');
         $rrdgraph[] = sprintf('AREA:-15#3313ad');
         $rrdgraph[] = sprintf('AREA:-10#3e12a2');
         $rrdgraph[] = sprintf('AREA:-5#491197');
         $rrdgraph[] = sprintf('LINE2:area_%s#000000', $tmp);
     }
     $c = 0;
     foreach ($sources as $source) {
         $legend = empty($this->legend[$source]) ? $source : $this->legend[$source];
         $color = is_array($this->colors) ? isset($this->colors[$source]) ? $this->colors[$source] : $this->colors[$c++] : $this->colors;
         #$rrdgraph[] = sprintf('LINE1:area_%s#%s:%s', crc32hex($source), $this->validate_color($color), $this->rrd_escape($legend));
         $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:%s Min,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:%s Avg,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:%s Max,', crc32hex($source), $this->rrd_format);
         $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:%s Last\\l', crc32hex($source), $this->rrd_format);
     }
     return $rrdgraph;
 }