This code alone works great for generating the server load as a dynamic bar graph. However, I'm unsure of how to include this into a section of a webpage.
I'm imagining there is a way to save the php into another php file say "status.php" and then call on that php file to display the results in a section of the page.
So can anyone tell me how I could do this if possible? Thanks.
<?php
// Get the server load
$server_load = explode(" ", exec("cat /proc/loadavg"));
$server_load = $server_load[0];
// Round the server load and get the width of the colored bar
$load = round($server_load,2);
$width = ($load > 10) ? 150 : floor($load*15);
// Get the color of the colored bar
if($load <= 5){ $colors = array("r"=>0,"g"=>128,"b"=>0); }
elseif($load <= 10){ $colors = array("r"=>255,"g"=>128,"b"=>64); }
else{ $colors = array("r"=>128,"g"=>0,"b"=>0); }
extract($colors);
header("Content-type: image/png");
// Create a grey image
$image = imagecreate(156, 14);
imagecolorallocate($image, 232, 232, 232);
// Add the main white background, creating the border
$white = imagecreate(156, 14);
imagecolorallocate($white, 255, 255, 255);
imagecopy($image, $white, 1, 1, 0, 0, 154, 12);
// Add the colored bar to the image
$color = imagecreate(150, 8);
imagecolorallocate($color, $r, $g, $b);
imagecopy($image, $color, 3, 3, 0, 0, $width, 8);
// Output the image
imagepng($image);
imagedestroy($image);
?>