Location: PHPKode > projects > Monolith - MySQL DBA Console > monolith-1.4-release/graph-memalloc.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 query_rate($host_id,$range) {
  
  $sql5 = "select t1.id,t1.host_id,t1.max_allocated,t1.max_per_thread,t1.max_per_global,t2.id,t2.ram_bytes,t1.Creation_time from memory_allocation as t1, hosts as t2 where t1.host_id='$host_id' and t2.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]);
    $ram_bytes[] = (($row5['ram_bytes'])/1024/1024/1024);
    $max_per_thread = $row5['max_per_thread']; 
    $max_per_glob = $row5['max_per_global'];
    $max_allocated[] = ((($row5['max_allocated'])/($row5['ram_bytes']))*100);    
    $max_configured[] = ((($max_per_thread+$max_per_glob)/($row5['ram_bytes']))*100);
    //$max_configured[] = ((($max_per_thread+$max_per_glob)/($row5['ram_bytes'])));

    $Timestamp[] = $row5['Creation_time'];
  }
  
  $cMA=round(end($max_allocated));
  $cMC=round(end($max_configured));

  $title="Memory Allocation";
  $legend1="Max_allocated, now: $cMA%";
  $legend2="Max_configured, now: $cMC%";

  $l1datay = $max_allocated;
  $l2datay = $max_configured;
  $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 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");
  
  // Create the bar plot                                                                                                             
  $bplot = new BarPlot($l2datay);
  $bplot->SetLegend("$legend2");
  $bplot->SetFillGradient("navy","lightsteelblue",GRAD_HOR); //blue gradient fil

  // move legend over
  $graph->legend->Pos(0.47,.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();
}

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