Location: PHPKode > projects > Monolith - MySQL DBA Console > monolith-1.4-release/graph-uptime.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', true);

$host_id = $_GET['host'];
$range = $_GET['range'];

include ("/var/www/html/monolith/inc/functions.php");
include ("/var/www/html/monolith/graphs/src/jpgraph.php");
include ("/var/www/html/monolith/graphs/src/jpgraph_bar.php");
include ("/var/www/html/monolith/graphs/src/jpgraph_line.php");
include ("/var/www/html/monolith/graphs/src/jpgraph_utils.inc.php"); 

function uptime_rate($host_id,$range) {
  $sql5 = "select host_id,Uptime,Connections,Connections_global,Creation_time from reporting_variables where host_id='$host_id' and DATE_SUB(CURDATE(),INTERVAL $range DAY)
 <= Creation_time order by Creation_time";
  $rowstack5 = (monitor_sql_exec("$sql5"));
  $count5 = count($rowstack5);
  for ($e = 0; $e < $count5; $e++) {
    $row5 = ($rowstack5[$e]);
    $Uptime[] = (($row5['Uptime'])/60/60/24);
    $Connections[] = $row5['Connections'];
    $Timestamp[] = $row5['Creation_time'];
  }
  
  $max_conn = max($Connections);
  $avg_conn = round(array_sum($Connections)/count($Connections));
  $max_up = round(max($Uptime));
  $title="Uptime & Connections";
  $legend1='Connections, max: '.$max_conn.', avg: '.$avg_conn.'';
  $legend2='Uptime, max: '.$max_up.' days';

  $l1datay = $Connections;
  $l2datay = $Uptime;
  $datax=$Timestamp;

  // Create the graph.                                                                                                                       
  $graph = new Graph(380,160,"auto");
  $graph->SetScale("textlin");
  $graph->SetY2Scale("lin");

  $graph->img->SetMargin(50,50,50,50);
  $graph->SetBackgroundImage("/var/www/html/monolith/images/main_bg_inv.jpg",BGIMG_FILLFRAME); //adding image
  $graph->SetShadow();

  // Create the bar plot                                                                                                                                                
  //$bplot = new BarPlot($l2datay);
  //$bplot->SetLegend("$legend2");
  //$bplot->SetFillGradient("navy","lightsteelblue",GRAD_HOR); //blue gradient fil 

  // Create the linear error plot                                                                                                            
  $l1plot=new LinePlot($l1datay);
  $l1plot->SetColor("red");
  $l1plot->SetWeight(1);
  $l1plot->SetLegend("$legend1");

  $l2plot=new LinePlot($l2datay);
  $l2plot->SetColor("blue");
  $l2plot->SetWeight(1);
  $l2plot->SetLegend("$legend2");

  // move legend over
  $graph->legend->Pos(0.40,.88,"right","center");
  $graph->xaxis->HideLabels(); //no xaxis labels

  $graph->Add($l1plot);
  $graph->AddY2($l2plot); 

  $graph->title->Set("$title - $range Day");
  $graph->xaxis->title->Set("");
  $graph->yaxis->title->Set("");

  $graph->yaxis->SetColor("red");
  $graph->y2axis->SetColor("navy");

  // Display the graph                                                                                                                       
  $graph->Stroke();

}

uptime_rate($host_id,$range);
Return current item: Monolith - MySQL DBA Console