Changes

Jump to navigation Jump to search
4,040 bytes added ,  00:27, 27 November 2015
no edit summary
Line 143: Line 143:  
  Execution of dynamic content (CGI, PHP, SSI) : enabled
 
  Execution of dynamic content (CGI, PHP, SSI) : enabled
 
  Force secure connections : Disbaled
 
  Force secure connections : Disbaled
 +
 +
So now we have the place holder for the Google Chart scripts .
 +
 +
8. Create the needed scripts ( working example below ) and transfer them to the iBay created above :
 +
 +
Script to monitor http memory usage (mysqli_apache_memory_used.php ) :
 +
 +
<?php
 +
// Hostname: 127.0.0.1, username: your_user, password: your_pass, db: your_db
 +
 +
$mysqli = new mysqli('localhost', 'username', 'password', 'db_name');
 +
 +
// Oh no! A connect_errno exists so the connection attempt failed!
 +
if ($mysqli->connect_errno) {
 +
    // The connection failed. What do you want to do?
 +
    // You could contact yourself (email?), log the error, show a nice page, etc.
 +
    // You do not want to reveal sensitive information
 +
 +
    // Let's try this:
 +
    echo "Sorry, this website is experiencing problems.";
 +
// Something you should not do on a public site, but this example will show you
 +
    // anyways, is print out MySQL error related information -- you might log this
 +
    echo "Error: Failed to make a MySQL connection, here is why: \n";
 +
    echo "Errno: " . $mysqli->connect_errno . "\n";
 +
    echo "Error: " . $mysqli->connect_error . "\n";
 +
 +
    // You might want to show them something nice, but we will simply exit
 +
    exit;
 +
}
 +
// Perform an SQL query
 +
//$query = "SELECT number, period, process_size, processors_used  FROM performance LIMIT 50";
 +
$query ="SELECT number, period, process_size, processors_used, mem_used  FROM performance WHERE period > DATE_SUB(NOW(), INTERVAL 48 HOUR)";
 +
if (!$result = $mysqli->query($query)) {
 +
    // Oh no! The query failed.
 +
    echo "Sorry, the website is experiencing problems.";
 +
 +
    // Again, do not do this on a public site, but we'll show you how
 +
    // to get the error information
 +
    echo "Error: Our query failed to execute and here is why: \n";
 +
    echo "Query: " . $sql . "\n";
 +
    echo "Errno: " . $mysqli->errno . "\n";
 +
    echo "Error: " . $mysqli->error . "\n";
 +
    exit;
 +
}
 +
 +
// Phew, we made it. We know our MySQL connection and query
 +
// succeeded, but do we have a result?
 +
if ($result->num_rows === 0) {
 +
    // Oh, no rows! Sometimes that's expected and okay, sometimes
 +
    // it is not. You decide. In this case, maybe actor_id was too
 +
    // large?
 +
    echo "We could not find a match , sorry about that. Please try again.";
 +
    exit;
 +
}
 +
$qresult = $mysqli->query($query);
 +
$results = array();
 +
 +
while($res = $qresult->fetch_assoc()) {
 +
$results[] = $res;
 +
}
 +
$curvechart_data = array();
 +
foreach($results as $result)
 +
{
 +
//$curvechart_data[] = array($result['period'],(int)$result['process_size'], (int)$result['processors_used'],(int)$result['mem_used']);
 +
$curvechart_data[] = array($result['period'],(int)$result['mem_used']);
 +
}
 +
$curvechart_data = json_encode($curvechart_data);
 +
//echo $curvechart_data;
 +
 +
// The script will automatically free the result and close the MySQL
 +
// connection when it exits, but let's just do it anyways
 +
//$result->free();
 +
//$mysqli->close();
 +
 +
 +
$html =<<<XYZ
 +
 +
<html>
 +
<head>
 +
  <script type="text/javascript" src="https://www.google.com/jsapi"></script>
 +
  <script type="text/javascript">
 +
    google.load('visualization', '1.1', {packages: ['line']});
 +
    google.setOnLoadCallback(drawChart);
 +
 +
    function drawChart() {
 +
 +
      var data = new google.visualization.DataTable();
 +
                data.addColumn('string','Period');
 +
//data.addColumn('number', 'No. Processors');
 +
                //data.addColumn('number', 'Process size');
 +
data.addColumn('number', 'Memory Used');
 +
                data.addRows({$curvechart_data});
 +
 +
 +
var options = {
 +
        chart: {
 +
          title: 'Apache HTTP Memory used ',
 +
          subtitle: 'in last 48 Hrs '
 +
        },colors:['red']
 +
        width: 1400,
 +
        height: 700
 +
      };
 +
 +
      var chart = new google.charts.Line(document.getElementById('linechart_material'));
 +
 +
      chart.draw(data, options);
 +
    }
 +
  </script>
 +
</head>
 +
<body>
 +
  <div id="linechart_material"></div>
 +
</body>
 +
</html>
 +
 +
XYZ;
 +
 +
echo $html;
 +
echo date('l jS \of F Y h:i:s A');
 +
 +
?>
80

edits

Navigation menu