Location: PHPKode > projects > Monolith - MySQL DBA Console > monolith-1.4-release/api-monitor-visualmining.php
<?php
//Similar to api-monitor.php but displays Db_size, Connections, Memory Allocation, Query rate

error_reporting(E_ALL);
ini_set('display_errors', false);
ini_set('html_errors', true);

session_start();
require('inc/functions.php');

$api_user = $_GET['zone0']; //username
$api_pass = $_GET['zone1']; //password
$range = $_GET['range']; // date range for queries
$host_id = $_GET['host_id']; //id of hostname from monitor.hosts

function check_auth($api_user,$api_pass,$host_id,$range) {
  if(isset($api_user)) {
    $valid=get_credentials_api($api_user,$api_pass);
    if($valid == 1) {
      print_xml($host_id,$range,$var0,$var1);
    }
    else {
      print "Invalid credentials. Please authenticate properly.\n";
    }
  }
  else {
    print "Invalid credentials. Please authenticate properly.\n";
  }
}

function print_xml($host_id,$range) {
  header("Content-Type: text/xml");
  echo("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
  echo("<client_list>\n");
  
  require('inc/dbconn_api.php');
  $link = mysql_connect($dbhost, $dbuser, $dbpass) OR die(mysql_error());

  $sql = "select t1.id, t1.client, t1.hostname, t1.ip_address, t1.ram_bytes, t2.Connections, t2.Db_size, t2.Uptime, t2.Questions, t3.max_allocated, t2.Creation_time from hosts as t1, reporting_variables as t2, memory_allocation as t3 WHERE t2.host_id='$host_id' AND t1.id = t2.host_id AND t2.id = t3.reporting_variables_id AND DATE_SUB(CURDATE(),INTERVAL $range DAY) <= t2.Creation_time order by t2.Creation_time;";
  
  $rowstack = (api_sql_exec("$sql"));
  $count = count($rowstack);
  for ($i = 0; $i < $count; $i++) {
    $row = ($rowstack[$i]);
    $id = $row['id'];
    $mem_alloc = ($row['max_allocated'] / $row['ram_bytes']);
    $query_rate  = ($row['Questions'] / $row['Uptime']);
    $Creation_time = $row['Creation_time'];
    //array_pop($row);

    $row['Query_rate_sec'] = round($query_rate,2);
    $row['Memory_allocation'] = round($mem_alloc,2);
    //$row['Creation_time'] = $Creation_time;

    //$row=array_splice($row, 11, 0, $query_rate);
    //$row=array_splice($row, 12, 0, $mem_alloc);

    //$varArray=array_push($row, $mem_alloc, $query_rate);

    echo ("\n  <customer id=\"$id\">\n");
    
    // This will start the entry for each row result. 
    // htmlspecialcharacters helps to ensure valid XML data formatting.
    foreach (array_keys($row) as $item) {
      echo ("    <$item>\n");
      echo ("      <string>");
      echo (htmlspecialchars($row["$item"]));
      echo ("</string>\n");
      echo ("    </$item>\n");
    }
    echo ("  </customer>\n");
  }
  echo("</client_list>\n");
}

check_auth($api_user,$api_pass,$host_id,$range);

?>
Return current item: Monolith - MySQL DBA Console