Example #1
0
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $dt = date("M j, Y H:i:s");
     $rrdGraph = new RRDGraph($image_path);
     $options = array("--step" => $r["step"], "--pango-markup", "--vertical-label" => 'Load averages', "--title" => "Load averages ({$dt})", "--lower-limit" => '0', "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--alt-y-grid", "--units-exponent" => '0', "--x-grid" => $r["x_grid"], "--end" => $r["end"], "--start" => $r["start"], "--border" => 0, "--color" => "BACK#FFFFFF", "--width" => 440, "--height" => 140, "--font-render-mode" => "normal", "DEF:la1={$rrddbpath}:la1:AVERAGE", "DEF:la5={$rrddbpath}:la5:AVERAGE", "DEF:la15={$rrddbpath}:la15:AVERAGE", "VDEF:la1_min=la1,MINIMUM", "VDEF:la1_last=la1,LAST", "VDEF:la1_avg=la1,AVERAGE", "VDEF:la1_max=la1,MAXIMUM", "VDEF:la5_min=la5,MINIMUM", "VDEF:la5_last=la5,LAST", "VDEF:la5_avg=la5,AVERAGE", "VDEF:la5_max=la5,MAXIMUM", "VDEF:la15_min=la15,MINIMUM", "VDEF:la15_last=la15,LAST", "VDEF:la15_avg=la15,AVERAGE", "VDEF:la15_max=la15,MAXIMUM", 'COMMENT:<b><tt>                                Minimum   Current     Average     Maximum</tt></b>\\j', 'AREA:la15' . self::COLOR_LA15 . ':<tt>15 Minutes system load </tt>', 'GPRINT:la15_min:<tt>%3.2lf</tt>', 'GPRINT:la15_last:<tt>%3.2lf</tt>', 'GPRINT:la15_avg:<tt>%3.2lf</tt>', 'GPRINT:la15_max:<tt>%3.2lf</tt>\\j', 'LINE1:la5' . self::COLOR_LA5 . ':<tt> 5 Minutes system load </tt>', 'GPRINT:la5_min:<tt>%3.2lf</tt>', 'GPRINT:la5_last:<tt>%3.2lf</tt>', 'GPRINT:la5_avg:<tt>%3.2lf</tt>', 'GPRINT:la5_max:<tt>%3.2lf</tt>\\j', 'LINE1:la1' . self::COLOR_LA1 . ':<tt> 1 Minute system load  </tt>', 'GPRINT:la1_min:<tt>%3.2lf</tt>', 'GPRINT:la1_last:<tt>%3.2lf</tt>', 'GPRINT:la1_avg:<tt>%3.2lf</tt>', 'GPRINT:la1_max:<tt>%3.2lf</tt>\\j');
     $rrdGraph->setOptions($options);
     try {
         return $rrdGraph->save();
     } catch (Exception $e) {
         var_dump($e);
     }
 }
Example #2
0
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $dt = date("M j, Y H:i:s");
     $rrdGraph = new RRDGraph($image_path);
     $options = array("--step" => $r["step"], "--pango-markup", "--vertical-label" => 'Bits per second', "--title" => "Network usage ({$dt})", "--lower-limit" => '0', "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--x-grid" => $r["x_grid"], "--end" => $r["end"], "--start" => $r["start"], "--width" => 440, "--border" => 0, "--color" => "BACK#FFFFFF", "--height" => 100, "--font-render-mode" => "normal", "DEF:in={$rrddbpath}:in:AVERAGE", "DEF:out={$rrddbpath}:out:AVERAGE", "CDEF:in_bits=in,8,*", "CDEF:out_bits=out,8,*", "VDEF:in_last=in_bits,LAST", "VDEF:in_avg=in_bits,AVERAGE", "VDEF:in_max=in_bits,MAXIMUM", "VDEF:out_last=out_bits,LAST", "VDEF:out_avg=out_bits,AVERAGE", "VDEF:out_max=out_bits,MAXIMUM", 'COMMENT:<b><tt>           Current   Average   Maximum</tt></b>\\j', 'AREA:in_bits' . self::COLOR_INBOUND . ':<tt>In    </tt>', 'GPRINT:in_last:<tt>  %4.1lf%s</tt>', 'GPRINT:in_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:in_max:<tt>  %4.1lf%s</tt>\\n', 'LINE1:out_bits' . self::COLOR_OUBOUND . ':<tt>Out   </tt>', 'GPRINT:out_last:<tt>  %4.1lf%s</tt>', 'GPRINT:out_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:out_max:<tt>  %4.1lf%s</tt>\\n');
     $rrdGraph->setOptions($options);
     try {
         return $rrdGraph->save();
     } catch (Exception $e) {
         var_dump($e);
     }
 }
Example #3
0
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $dt = date("M j, Y H:i:s");
     $rrdGraph = new RRDGraph($image_path);
     $options = array("--step" => $r["step"], "--pango-markup", "--vertical-label" => 'Servers', "--title" => "Servers count ({$dt})", "--alt-autoscale-max", "--alt-autoscale-min", "--lower-limit" => 0, "--y-grid" => "1:1", "--units-exponent" => '0', "--rigid", "--no-gridfit", "--slope-mode", "--border" => 0, "--color" => "BACK#FFFFFF", "--x-grid" => $r["x_grid"], "--end" => $r["end"], "--start" => $r["start"], "--width" => 440, "--height" => 100, "--font-render-mode" => "normal", "DEF:s_running={$rrddbpath}:s_running:AVERAGE", "VDEF:s_running_last=s_running,LAST", "VDEF:s_running_avg=s_running,AVERAGE", "VDEF:s_running_max=s_running,MAXIMUM", "VDEF:s_running_min=s_running,MINIMUM", 'COMMENT:<b><tt>                     Current    Average    Maximum    Minimum</tt></b>\\j', 'LINE1:s_running' . self::COLOR_RUNNING_SERVERS . ':<tt>Running servers </tt>', 'GPRINT:s_running_last:<tt>    %3.0lf</tt>', 'GPRINT:s_running_avg:<tt>     %3.0lf</tt>', 'GPRINT:s_running_max:<tt>     %3.0lf</tt>', 'GPRINT:s_running_min:<tt>     %3.0lf</tt>\\n');
     try {
         $rrdGraph->setOptions($options);
         return $rrdGraph->save();
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
 }
Example #4
0
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $dt = date("M j, Y H:i:s");
     $rrdGraph = new RRDGraph($image_path);
     $options = array("--step" => $r["step"], "--pango-markup", "--vertical-label" => 'Percent CPU Utilization', "--title" => "CPU Utilization ({$dt})", "--upper-limit" => 100, "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--border" => 0, "--color" => "BACK#FFFFFF", "--x-grid" => $r["x_grid"], "--end" => $r["end"], "--start" => $r["start"], "--width" => 440, "--height" => 160, "--font-render-mode" => "normal", "DEF:a={$rrddbpath}:user:AVERAGE", "DEF:b={$rrddbpath}:system:AVERAGE", "DEF:c={$rrddbpath}:nice:AVERAGE", "DEF:d={$rrddbpath}:idle:AVERAGE", "CDEF:total=a,b,c,d,+,+,+", "CDEF:a_perc=a,total,/,100,*", "VDEF:a_perc_last=a_perc,LAST", "VDEF:a_perc_avg=a_perc,AVERAGE", "VDEF:a_perc_max=a_perc,MAXIMUM", "CDEF:b_perc=b,total,/,100,*", "VDEF:b_perc_last=b_perc,LAST", "VDEF:b_perc_avg=b_perc,AVERAGE", "VDEF:b_perc_max=b_perc,MAXIMUM", "CDEF:c_perc=c,total,/,100,*", "VDEF:c_perc_last=c_perc,LAST", "VDEF:c_perc_avg=c_perc,AVERAGE", "VDEF:c_perc_max=c_perc,MAXIMUM", "CDEF:d_perc=d,total,/,100,*", "VDEF:d_perc_last=d_perc,LAST", "VDEF:d_perc_avg=d_perc,AVERAGE", "VDEF:d_perc_max=d_perc,MAXIMUM", 'COMMENT:<b><tt>               Current    Average    Maximum</tt></b>\\j', 'AREA:a_perc#eacc00:<tt>user    </tt>', 'GPRINT:a_perc_last:<tt>    %3.0lf%%</tt>', 'GPRINT:a_perc_avg:<tt>     %3.0lf%%</tt>', 'GPRINT:a_perc_max:<tt>     %3.0lf%%</tt>\\n', 'AREA:b_perc#ea8f00:<tt>system  </tt>:STACK', 'GPRINT:b_perc_last:<tt>    %3.0lf%%</tt>', 'GPRINT:b_perc_avg:<tt>     %3.0lf%%</tt>', 'GPRINT:b_perc_max:<tt>     %3.0lf%%</tt>\\n', 'AREA:c_perc#ff3932:<tt>nice    </tt>:STACK', 'GPRINT:c_perc_last:<tt>    %3.0lf%%</tt>', 'GPRINT:c_perc_avg:<tt>     %3.0lf%%</tt>', 'GPRINT:c_perc_max:<tt>     %3.0lf%%</tt>\\n', 'AREA:d_perc#fafdce:<tt>idle    </tt>:STACK', 'GPRINT:d_perc_last:<tt>    %3.0lf%%</tt>', 'GPRINT:d_perc_avg:<tt>     %3.0lf%%</tt>', 'GPRINT:d_perc_max:<tt>     %3.0lf%%</tt>\\n');
     $rrdGraph->setOptions($options);
     try {
         return $rrdGraph->save();
     } catch (Exception $e) {
         var_dump($e);
     }
 }
Example #5
0
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $dt = date("M j, Y H:i:s");
     $rrdGraph = new RRDGraph($image_path);
     $options = array("--step" => $r["step"], "--pango-markup", "--vertical-label" => 'Memory Usage', "--title" => "Memory Usage ({$dt})", "--lower-limit" => '0', "--base" => 1024, "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--x-grid" => $r["x_grid"], "--end" => $r["end"], "--start" => $r["start"], "--border" => 0, "--color" => "BACK#FFFFFF", "--width" => 440, "--height" => 180, "--font-render-mode" => "normal", "DEF:mem1={$rrddbpath}:swap:AVERAGE", "DEF:mem2={$rrddbpath}:swapavail:AVERAGE", "DEF:mem3={$rrddbpath}:total:AVERAGE", "DEF:mem4={$rrddbpath}:avail:AVERAGE", "DEF:mem5={$rrddbpath}:free:AVERAGE", "DEF:mem6={$rrddbpath}:shared:AVERAGE", "DEF:mem7={$rrddbpath}:buffer:AVERAGE", "DEF:mem8={$rrddbpath}:cached:AVERAGE", "CDEF:swap_total=mem1,1024,*", "VDEF:swap_total_min=swap_total,MINIMUM", "VDEF:swap_total_last=swap_total,LAST", "VDEF:swap_total_avg=swap_total,AVERAGE", "VDEF:swap_total_max=swap_total,MAXIMUM", "CDEF:swap_avail=mem2,1024,*", "VDEF:swap_avail_min=swap_avail,MINIMUM", "VDEF:swap_avail_last=swap_avail,LAST", "VDEF:swap_avail_avg=swap_avail,AVERAGE", "VDEF:swap_avail_max=swap_avail,MAXIMUM", "CDEF:swap_used=swap_total,swap_avail,-", "VDEF:swap_used_min=swap_used,MINIMUM", "VDEF:swap_used_last=swap_used,LAST", "VDEF:swap_used_avg=swap_used,AVERAGE", "VDEF:swap_used_max=swap_used,MAXIMUM", "CDEF:mem_total=mem3,1024,*", "VDEF:mem_total_min=mem_total,MINIMUM", "VDEF:mem_total_last=mem_total,LAST", "VDEF:mem_total_avg=mem_total,AVERAGE", "VDEF:mem_total_max=mem_total,MAXIMUM", "CDEF:mem_avail=mem4,1024,*", "VDEF:mem_avail_min=mem_avail,MINIMUM", "VDEF:mem_avail_last=mem_avail,LAST", "VDEF:mem_avail_avg=mem_avail,AVERAGE", "VDEF:mem_avail_max=mem_avail,MAXIMUM", "CDEF:mem_free=mem5,1024,*", "VDEF:mem_free_min=mem_free,MINIMUM", "VDEF:mem_free_last=mem_free,LAST", "VDEF:mem_free_avg=mem_free,AVERAGE", "VDEF:mem_free_max=mem_free,MAXIMUM", "CDEF:mem_shared=mem6,1024,*", "VDEF:mem_shared_min=mem_shared,MINIMUM", "VDEF:mem_shared_last=mem_shared,LAST", "VDEF:mem_shared_avg=mem_shared,AVERAGE", "VDEF:mem_shared_max=mem_shared,MAXIMUM", "CDEF:mem_buffer=mem7,1024,*", "VDEF:mem_buffer_min=mem_buffer,MINIMUM", "VDEF:mem_buffer_last=mem_buffer,LAST", "VDEF:mem_buffer_avg=mem_buffer,AVERAGE", "VDEF:mem_buffer_max=mem_buffer,MAXIMUM", "CDEF:mem_cached=mem8,1024,*", "VDEF:mem_cached_min=mem_cached,MINIMUM", "VDEF:mem_cached_last=mem_cached,LAST", "VDEF:mem_cached_avg=mem_cached,AVERAGE", "VDEF:mem_cached_max=mem_cached,MAXIMUM", 'COMMENT:<b><tt>                        Minimum       Current       Average      Maximum</tt></b>\\j', 'AREA:mem_shared' . self::COLOR_MEM_SHRD . ':<tt>Shared        </tt>', 'GPRINT:swap_total_min:<tt>  %4.1lf%s</tt>', 'GPRINT:swap_total_last:<tt>  %4.1lf%s</tt>', 'GPRINT:swap_total_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:swap_total_max:<tt>  %4.1lf%s</tt>\\j', 'AREA:mem_buffer' . self::COLOR_MEM_BUFF . ':<tt>Buffer         </tt>', 'GPRINT:mem_buffer_min:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_buffer_last:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_buffer_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_buffer_max:<tt>  %4.1lf%s</tt>\\j', 'AREA:mem_cached' . self::COLOR_MEM_CACH . ':<tt>Cached        </tt>:STACK', 'GPRINT:mem_cached_min:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_cached_last:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_cached_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_cached_max:<tt>  %4.1lf%s</tt>\\j', 'AREA:mem_free' . self::COLOR_MEM_FREE . ':<tt>Free           </tt>:STACK', 'GPRINT:mem_free_min:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_free_last:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_free_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_free_max:<tt>  %4.1lf%s</tt>\\j', 'AREA:mem_avail' . self::COLOR_MEM_REAL . ':<tt>Real           </tt>:STACK', 'GPRINT:mem_avail_min:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_avail_last:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_avail_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:mem_avail_max:<tt>  %4.1lf%s</tt>\\j', 'LINE1:swap_used' . self::COLOR_MEM_SWAP . ':<tt>Swap In Use  </tt>:STACK', 'GPRINT:swap_used_min:<tt>  %4.1lf%s</tt>', 'GPRINT:swap_used_last:<tt>  %4.1lf%s</tt>', 'GPRINT:swap_used_avg:<tt>  %4.1lf%s</tt>', 'GPRINT:swap_used_max:<tt>  %4.1lf%s</tt>\\j');
     $rrdGraph->setOptions($options);
     try {
         $retval = $rrdGraph->save();
     } catch (Exception $e) {
         var_dump($e);
     }
     return $retval;
 }
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $graph = new RRDGraph(440, 100, CONFIG::$RRDTOOL_PATH);
     $graph->AddDEF("in", $rrddbpath, "in", "AVERAGE");
     $graph->AddDEF("out", $rrddbpath, "out", "AVERAGE");
     $graph->AddCDEF("in_bits", "in,8,*");
     $graph->AddCDEF("out_bits", "out,8,*");
     $graph->AddVDEF("in_last", "in_bits,LAST");
     $graph->AddVDEF("in_avg", "in_bits,AVERAGE");
     $graph->AddVDEF("in_max", "in_bits,MAXIMUM");
     $graph->AddVDEF("out_last", "out_bits,LAST");
     $graph->AddVDEF("out_avg", "out_bits,AVERAGE");
     $graph->AddVDEF("out_max", "out_bits,MAXIMUM");
     $graph->AddComment('<b><tt>           Current   Average   Maximum</tt></b>\\j');
     $graph->AddArea("in_bits", self::COLOR_INBOUND, "<tt>In:    </tt>");
     $graph->AddGPrint("in_last", '<tt>  %4.1lf%s</tt>');
     $graph->AddGPrint("in_avg", '<tt>  %4.1lf%s</tt>');
     $graph->AddGPrint("in_max", '<tt>  %4.1lf%s</tt>\\n');
     $graph->AddLine(1, "out_bits", self::COLOR_OUBOUND, "<tt>Out:   </tt>");
     $graph->AddGPrint("out_last", '<tt>  %4.1lf%s</tt>');
     $graph->AddGPrint("out_avg", '<tt>  %4.1lf%s</tt>');
     $graph->AddGPrint("out_max", '<tt>  %4.1lf%s</tt>\\n');
     if (CONFIG::$RRD_DEFAULT_FONT_PATH) {
         $graph->AddFont("DEFAULT", "0", CONFIG::$RRD_DEFAULT_FONT_PATH);
     }
     $dt = date("M j, Y H:i:s");
     $res = $graph->Plot($image_path, $r["start"], $r["end"], array("--step", $r["step"], "--pango-markup", "-v", "Bits per second", "-t", "Network usage ({$dt})", "-l", "0", "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--x-grid", $r["x_grid"]));
     return true;
 }
Example #7
0
 function testRRDGraph()
 {
     $graph = new RRDGraph(450, 150);
     //Add DEF
     $graph->AddDEF("L1", dirname(__FILE__) . "/test.rrd", "L1", "AVERAGE");
     $graph->AddDEF("L2", dirname(__FILE__) . "/test.rrd", "L2", "AVERAGE");
     $graph->AddDEF("L3", dirname(__FILE__) . "/test.rrd", "L3", "AVERAGE");
     //Add Lines
     $graph->AddLine(1, "L1", "#00FF00", "Test line 1");
     $graph->AddLine(2, "L2", "#FF0000", "Test line 2");
     // Add  Area
     $graph->AddArea("L3", "#0000FF", "Test area");
     $graph->SetXGridStyle("WEEK", 1, "MONTH", 1, "MONTH", 1, 1, "%b");
     $graph->Title = "TEST GRAPH";
     $res = $graph->Plot("/tmp/test.gif", "-1y", "now");
     $this->assertTrue($res, "Graph created");
 }
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $graph = new RRDGraph(440, 140, CONFIG::$RRDTOOL_PATH);
     $graph->AddDEF("la1", $rrddbpath, "la1", "AVERAGE");
     $graph->AddVDEF("la1_min", "la1,MINIMUM");
     $graph->AddVDEF("la1_last", "la1,LAST");
     $graph->AddVDEF("la1_avg", "la1,AVERAGE");
     $graph->AddVDEF("la1_max", "la1,MAXIMUM");
     $graph->AddDEF("la5", $rrddbpath, "la5", "AVERAGE");
     $graph->AddVDEF("la5_min", "la5,MINIMUM");
     $graph->AddVDEF("la5_last", "la5,LAST");
     $graph->AddVDEF("la5_avg", "la5,AVERAGE");
     $graph->AddVDEF("la5_max", "la5,MAXIMUM");
     $graph->AddDEF("la15", $rrddbpath, "la15", "AVERAGE");
     $graph->AddVDEF("la15_min", "la15,MINIMUM");
     $graph->AddVDEF("la15_last", "la15,LAST");
     $graph->AddVDEF("la15_avg", "la15,AVERAGE");
     $graph->AddVDEF("la15_max", "la15,MAXIMUM");
     $graph->AddComment('<b><tt>                              Minimum     Current     Average     Maximum</tt></b>\\j');
     $graph->AddArea("la15", self::COLOR_LA15, "<tt>15 Minutes system load:</tt>");
     $graph->AddGPrint("la15_min", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la15_last", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la15_avg", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la15_max", '<tt>%3.2lf</tt>\\j');
     $graph->AddLine(1, "la5", self::COLOR_LA5, "<tt> 5 Minutes system load:</tt>");
     $graph->AddGPrint("la5_min", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la5_last", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la5_avg", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la5_max", '<tt>%3.2lf</tt>\\j');
     $graph->AddLine(1, "la1", self::COLOR_LA1, "<tt> 1 Minute  system load:</tt>");
     $graph->AddGPrint("la1_min", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la1_last", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la1_avg", '<tt>%3.2lf</tt>');
     $graph->AddGPrint("la1_max", '<tt>%3.2lf</tt>\\j');
     if (CONFIG::$RRD_DEFAULT_FONT_PATH) {
         $graph->AddFont("DEFAULT", "0", CONFIG::$RRD_DEFAULT_FONT_PATH);
     }
     $dt = date("M j, Y H:i:s");
     $res = $graph->Plot($image_path, $r["start"], $r["end"], array("--step", $r["step"], "--pango-markup", "-v", "Load averages", "-t", "Load averages ({$dt})", "-l", "0", "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--alt-y-grid", "-X0", "--x-grid", $r["x_grid"]));
     return true;
 }
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $graph = new RRDGraph(440, 180, CONFIG::$RRDTOOL_PATH);
     $graph->AddDEF("mem1", $rrddbpath, "swap", "AVERAGE");
     $graph->AddDEF("mem2", $rrddbpath, "swapavail", "AVERAGE");
     $graph->AddDEF("mem3", $rrddbpath, "total", "AVERAGE");
     $graph->AddDEF("mem4", $rrddbpath, "avail", "AVERAGE");
     $graph->AddDEF("mem5", $rrddbpath, "free", "AVERAGE");
     $graph->AddDEF("mem6", $rrddbpath, "shared", "AVERAGE");
     $graph->AddDEF("mem7", $rrddbpath, "buffer", "AVERAGE");
     $graph->AddDEF("mem8", $rrddbpath, "cached", "AVERAGE");
     $graph->AddCDEF("swap_total", "mem1,1024,*");
     $graph->AddVDEF("swap_total_min", "swap_total,MINIMUM");
     $graph->AddVDEF("swap_total_last", "swap_total,LAST");
     $graph->AddVDEF("swap_total_avg", "swap_total,AVERAGE");
     $graph->AddVDEF("swap_total_max", "swap_total,MAXIMUM");
     $graph->AddCDEF("swap_avail", "mem2,1024,*");
     $graph->AddVDEF("swap_avail_tot", "swap_avail,LAST");
     $graph->AddVDEF("swap_avail_min", "swap_avail,MINIMUM");
     $graph->AddVDEF("swap_avail_last", "swap_avail,LAST");
     $graph->AddVDEF("swap_avail_avg", "swap_avail,AVERAGE");
     $graph->AddVDEF("swap_avail_max", "swap_avail,MAXIMUM");
     $graph->AddCDEF("swap_used", "swap_total,swap_avail,-");
     $graph->AddVDEF("swap_used_min", "swap_used,MINIMUM");
     $graph->AddVDEF("swap_used_last", "swap_used,LAST");
     $graph->AddVDEF("swap_used_avg", "swap_used,AVERAGE");
     $graph->AddVDEF("swap_used_max", "swap_used,MAXIMUM");
     $graph->AddCDEF("mem_total", "mem3,1024,*");
     $graph->AddVDEF("mem_total_min", "mem_total,MINIMUM");
     $graph->AddVDEF("mem_total_last", "mem_total,LAST");
     $graph->AddVDEF("mem_total_avg", "mem_total,AVERAGE");
     $graph->AddVDEF("mem_total_max", "mem_total,MAXIMUM");
     $graph->AddCDEF("mem_avail", "mem4,1024,*");
     $graph->AddVDEF("mem_avail_min", "mem_avail,MINIMUM");
     $graph->AddVDEF("mem_avail_last", "mem_avail,LAST");
     $graph->AddVDEF("mem_avail_avg", "mem_avail,AVERAGE");
     $graph->AddVDEF("mem_avail_max", "mem_avail,MAXIMUM");
     $graph->AddCDEF("mem_free", "mem5,1024,*");
     $graph->AddVDEF("mem_free_min", "mem_free,MINIMUM");
     $graph->AddVDEF("mem_free_last", "mem_free,LAST");
     $graph->AddVDEF("mem_free_avg", "mem_free,AVERAGE");
     $graph->AddVDEF("mem_free_max", "mem_free,MAXIMUM");
     $graph->AddCDEF("mem_shared", "mem6,1024,*");
     $graph->AddVDEF("mem_shared_min", "mem_shared,MINIMUM");
     $graph->AddVDEF("mem_shared_last", "mem_shared,LAST");
     $graph->AddVDEF("mem_shared_avg", "mem_shared,AVERAGE");
     $graph->AddVDEF("mem_shared_max", "mem_shared,MAXIMUM");
     $graph->AddCDEF("mem_buffer", "mem7,1024,*");
     $graph->AddVDEF("mem_buffer_min", "mem_buffer,MINIMUM");
     $graph->AddVDEF("mem_buffer_last", "mem_buffer,LAST");
     $graph->AddVDEF("mem_buffer_avg", "mem_buffer,AVERAGE");
     $graph->AddVDEF("mem_buffer_max", "mem_buffer,MAXIMUM");
     $graph->AddCDEF("mem_cached", "mem8,1024,*");
     $graph->AddVDEF("mem_cached_min", "mem_cached,MINIMUM");
     $graph->AddVDEF("mem_cached_last", "mem_cached,LAST");
     $graph->AddVDEF("mem_cached_avg", "mem_cached,AVERAGE");
     $graph->AddVDEF("mem_cached_max", "mem_cached,MAXIMUM");
     $graph->AddComment('<b><tt>                      Minimum       Current       Average       Maximum</tt></b>\\j');
     $graph->AddArea("mem_shared", self::COLOR_MEM_SHRD, "<tt>Shared        </tt>");
     $graph->AddGPrint("swap_total_min", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("swap_total_last", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("swap_total_avg", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("swap_total_max", '<tt>%4.1lf %s</tt>\\j');
     $graph->AddArea("mem_buffer", self::COLOR_MEM_BUFF, "<tt>Buffer        </tt>", "STACK");
     $graph->AddGPrint("mem_buffer_min", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_buffer_last", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_buffer_avg", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_buffer_max", '<tt>%4.1lf %s</tt>\\j');
     $graph->AddArea("mem_cached", self::COLOR_MEM_CACH, "<tt>Cached        </tt>", "STACK");
     $graph->AddGPrint("mem_cached_min", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_cached_last", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_cached_avg", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_cached_max", '<tt>%4.1lf %s</tt>\\j');
     $graph->AddArea("mem_free", self::COLOR_MEM_FREE, "<tt>Free          </tt>", "STACK");
     $graph->AddGPrint("mem_free_min", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_free_last", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_free_avg", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_free_max", '<tt>%4.1lf %s</tt>\\j');
     $graph->AddArea("mem_avail", self::COLOR_MEM_REAL, "<tt>Real          </tt>", "STACK");
     $graph->AddGPrint("mem_avail_min", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_avail_last", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_avail_avg", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("mem_avail_max", '<tt>%4.1lf %s</tt>\\j');
     //$graph->AddGPrint("swap_avail_tot", '       Mem Total: %4.1lf%S\\j');
     $graph->AddLine(1, "swap_used", self::COLOR_MEM_SWAP, "<tt>Swap In Use   </tt>");
     $graph->AddGPrint("swap_used_min", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("swap_used_last", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("swap_used_avg", '<tt>%4.1lf %s</tt>');
     $graph->AddGPrint("swap_used_max", '<tt>%4.1lf %s</tt>\\j');
     // $graph->AddGPrint("swap_used_last", '            Swap Total:%4.1lf%S\\j');
     if (CONFIG::$RRD_DEFAULT_FONT_PATH) {
         $graph->AddFont("DEFAULT", "0", CONFIG::$RRD_DEFAULT_FONT_PATH);
     }
     $dt = date("M j, Y H:i:s");
     //
     // Plot graphics
     //
     $res = $graph->Plot($image_path, $r["start"], $r["end"], array("--step", $r["step"], "--pango-markup", "-v", "Memory Usage", "-t", "Memory Usage ({$dt})", "-l", "0", "-b", "1024", "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--x-grid", $r["x_grid"]));
     return true;
 }
Example #10
0
 /**
  * 绘制图片 
  * 
  * @param string $monitor_id 
  * @static
  * @access public
  * @return void
  */
 public static function graph($monitor_id, $metric_id, $options = array())
 {
     // 创建 rrd 数据库
     if (!isset(self::$__redis)) {
         self::$__redis = \swan\redis\sw_redis::singleton();
     }
     $monitor_info = self::$__redis->get(SWAN_CACHE_MONITOR_PREFIX . $monitor_id);
     if (!$monitor_info) {
         throw new sw_exception('graph rrd file faild. reason is get dm info fail.');
     }
     $monitor_info = json_decode($monitor_info, true);
     $madapter_id = $monitor_info['madapter_id'];
     // 获取metric info
     $metric_info = self::$__redis->get(SWAN_CACHE_METRIC_PREFIX . $madapter_id . '_' . $metric_id);
     if (!$metric_info) {
         throw new sw_exception('graph rrd file faild. reason is get monitor metric info fail.');
     }
     $metric_info = json_decode($metric_info, true);
     $graph_params = self::_get_graph_params($monitor_info, $metric_info, $options);
     $time_grid = isset($options['time_grid']) ? $options['time_grid'] : self::T_15_MIN;
     if (!array_key_exists($options['time_grid'], self::$__x_grid)) {
         $time_grid = self::T_15_MIN;
     }
     $out_file = PATH_SWAN_RRD_GRAPH . $time_grid . '/' . $monitor_id . '_' . $metric_id . '.png';
     try {
         $graph = new \RRDGraph($out_file);
         $graph->setOptions($graph_params);
         $graph->save();
     } catch (\Exception $e) {
         throw new sw_exception($e);
     }
     return $out_file;
 }
Example #11
0
<?php

$outputPngFile = "/root/i_code/swan_docs/swansoft/public/speed.png";
unlink($outputPngFile);
$tmp = '/usr/local/swan/smeta/data/rrd/1_4.rrd';
$graphObj = new RRDGraph($outputPngFile);
$options = array('--color' => "SHADEA#DDDDDD", '--color' => "SHADEB#808080", '--color' => "FRAME#006600", '--color' => "FONT#006699", '--color' => "ARROW#FF0000", '--color' => "AXIS#000000", '--color' => "BACK#FFFFFF", '--x-grid' => "MINUTE:12:HOUR:1:HOUR:1:0:%H", "-X 1 ", "-t 服务器 /dev/sdb1 统计", "-v GB", "-s " . (time() - 7200), "-e " . time(), "DEF:value1={$tmp}:used:AVERAGE", "COMMENT: \\n", "COMMENT: \\n", "AREA:value1#00ff00:已使用 ", "GPRINT:value1:LAST:当前\\:%.0lf", "GPRINT:value1:AVERAGE:平均\\:%.0lf ", "GPRINT:value1:MAX:最大\\:%.0lf", "GPRINT:value1:MIN:最小\\:%.0lf", "COMMENT: \\n", "COMMENT: \\t\\t\\t\\t\\t\\t\\t最后更新 \\:" . date('Y-m-d H\\\\:m', time()) . "\\n", "COMMENT: \\t\\t\\t\\t\\t\\t\\tSWAN 监控数据中心\\n");
$graphObj->setOptions($options);
$graphObj->save();
 /**
  * Plot graphic
  *
  * @param integer $serverid
  */
 public static function PlotGraphic($rrddbpath, $image_path, $r)
 {
     $graph = new RRDGraph(440, 160, CONFIG::$RRDTOOL_PATH);
     $graph->AddDEF("a", $rrddbpath, "user", "AVERAGE");
     $graph->AddDEF("b", $rrddbpath, "system", "AVERAGE");
     $graph->AddDEF("c", $rrddbpath, "nice", "AVERAGE");
     $graph->AddDEF("d", $rrddbpath, "idle", "AVERAGE");
     $graph->AddCDEF("total", "a,b,c,d,+,+,+");
     $graph->AddCDEF("a_perc", "a,total,/,100,*");
     $graph->AddVDEF("a_perc_last", "a_perc,LAST");
     $graph->AddVDEF("a_perc_avg", "a_perc,AVERAGE");
     $graph->AddVDEF("a_perc_max", "a_perc,MAXIMUM");
     $graph->AddCDEF("b_perc", "b,total,/,100,*");
     $graph->AddVDEF("b_perc_last", "b_perc,LAST");
     $graph->AddVDEF("b_perc_avg", "b_perc,AVERAGE");
     $graph->AddVDEF("b_perc_max", "b_perc,MAXIMUM");
     $graph->AddCDEF("c_perc", "c,total,/,100,*");
     $graph->AddVDEF("c_perc_last", "c_perc,LAST");
     $graph->AddVDEF("c_perc_avg", "c_perc,AVERAGE");
     $graph->AddVDEF("c_perc_max", "c_perc,MAXIMUM");
     $graph->AddCDEF("d_perc", "d,total,/,100,*");
     $graph->AddVDEF("d_perc_last", "d_perc,LAST");
     $graph->AddVDEF("d_perc_avg", "d_perc,AVERAGE");
     $graph->AddVDEF("d_perc_max", "d_perc,MAXIMUM");
     $graph->AddComment('<b><tt>               Current    Average    Maximum</tt></b>\\j');
     $graph->AddArea("a_perc", self::COLOR_CPU_USER, "<tt>user    </tt>");
     $graph->AddGPrint("a_perc_last", '<tt>    %3.0lf%%</tt>');
     $graph->AddGPrint("a_perc_avg", '<tt>     %3.0lf%%</tt>');
     $graph->AddGPrint("a_perc_max", '<tt>     %3.0lf%%</tt>\\n');
     $graph->AddArea("b_perc", self::COLOR_CPU_SYST, "<tt>system  </tt>", "STACK");
     $graph->AddGPrint("b_perc_last", '<tt>    %3.0lf%%</tt>');
     $graph->AddGPrint("b_perc_avg", '<tt>     %3.0lf%%</tt>');
     $graph->AddGPrint("b_perc_max", '<tt>     %3.0lf%%</tt>\\n');
     $graph->AddArea("c_perc", self::COLOR_CPU_NICE, "<tt>nice    </tt>", "STACK");
     $graph->AddGPrint("c_perc_last", '<tt>    %3.0lf%%</tt>');
     $graph->AddGPrint("c_perc_avg", '<tt>     %3.0lf%%</tt>');
     $graph->AddGPrint("c_perc_max", '<tt>     %3.0lf%%</tt>\\n');
     $graph->AddArea("d_perc", self::COLOR_CPU_IDLE, "<tt>idle    </tt>", "STACK");
     $graph->AddGPrint("d_perc_last", '<tt>    %3.0lf%%</tt>');
     $graph->AddGPrint("d_perc_avg", '<tt>     %3.0lf%%</tt>');
     $graph->AddGPrint("d_perc_max", '<tt>     %3.0lf%%</tt>\\n');
     if (CONFIG::$RRD_DEFAULT_FONT_PATH) {
         $graph->AddFont("DEFAULT", "0", CONFIG::$RRD_DEFAULT_FONT_PATH);
     }
     $dt = date("M j, Y H:i:s");
     $res = $graph->Plot($image_path, $r["start"], $r["end"], array("--step", $r["step"], "--pango-markup", "-v", "Percent CPU Utilization", "-t", "CPU Utilization ({$dt})", "-u", "100", "--alt-autoscale-max", "--alt-autoscale-min", "--rigid", "--no-gridfit", "--slope-mode", "--x-grid", $r["x_grid"]));
     return true;
 }