FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Server status script





Jamatu
Just though i'd post this script up, it's one of my first scripts that uses gd so it isn't exactly 'pretty' at the minute Razz

Code:
<?php
//Jamatu's Dynamic Server status signature script v0.1b

header("Content-type: image/png"); //load the page as an image
header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT"); //expires when created
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); //modified every script execution
header("Cache-Control: no-store, no-cache, must-revalidate"); //HTTP/1.1 no-cache
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); //HTTP/1.0 no-cache

$uptime = shell_exec("cut -d. -f1 /proc/uptime"); //Get the current uptime from the virtual file
$udays = floor($uptime/60/60/24);
$uhours = $uptime/60/60%24;
$umins = $uptime/60%60;
$usecs = $uptime%60;

$sqlinf = mysql_stat(); //get mysql runtime information
$output = explode(' ',$sqlinf);
$mdays = floor($output[1]/60/60/24);
$mhours = $output[1]/60/60%24;
$mmins = $output[1]/60%60;
$msecs = $output[1]%60;

//set some variables to be drawn
$title = 'Website name';
$uptime = "Server uptime: $udays days, $uhours hours, $umins minutes and $usecs seconds";
$sqluptime = "mySQL uptime:  $mdays days, $mhours hours, $mmins minutes and $msecs seconds";
$queries = 'Queries: '.$output[7];
$qps = 'Queries per second: '.$output[28];

$image = imagecreate(400, 80); //create a blank image
$bgColor = imagecolorallocate($image, 255, 255, 255); //set the background color as white
$textColor = imagecolorallocate($image, 0, 0, 0); //set the text color as black
imagestring($image, 5, 150, 5, $title, $textColor); //draw the text
imagestring($image, 2, 5, 22, $uptime, $textColor);
imagestring($image, 2, 5, 36, $sqluptime, $textColor);
imagestring($image, 2, 5, 50, $queries, $textColor);
imagestring($image, 2, 5, 64, $qps, $textColor);

imagepng($image); //create the image
imagedestroy($image); //destroy the image
?>


Example image
n0obie4life
Smile

good job.
photon
hey nice work!! and the image generation thing is really cool!! Smile
Ironz
that's really cool.

does it work on all servers? or does it need a special feature or a specific place to be put in? cuz if i remember correctly, shell scripts should be put in a specific location.

btw what other things can it get other than the uptime and queries?
Jamatu
Ironz wrote:
does it work on all servers? or does it need a special feature or a specific place to be put in? cuz if i remember correctly, shell scripts should be put in a specific location.

It won't work on all servers as you need privliges to use the shell_exec command. Their are other ways of getting different types of data though. It doesn't matter where you place this file either as it's a php scripts, the shell command is just executed from inside the script.

Ironz wrote:

btw what other things can it get other than the uptime and queries?

It can show the output from a query, data stored in a variable or an array, text from a file and more. If your interested in getting a sig like this you can check the stored I opened a few days ago. http://www.frihost.com/forums/vt-36308.html
Atomo64
Nice thing, but maybe you could add something like a cache system, so the information is updated each 30 seconds.
yjwong
This script only works on Linux.

Post ^: Maybe you could modify the script to save the image to somewhere and set up a cron job to run the script like...every 30 minutes.
Jamatu
yjwong wrote:
This script only works on Linux.

Post ^: Maybe you could modify the script to save the image to somewhere and set up a cron job to run the script like...every 30 minutes.

Yeah I designed it for my system, you also need shell access to be able to run the script. I offer a Dynamic image making service where I tailor the script to peoples needs.
Related topics
Server Status
Checking Server Status, Ping a Server (lots of purposes)
Php script Cod server stats
Frihost server status checker
Checking server status (ports) using PHP
Current server status
New Server Status page
Email sending problems
[HOW TO...] Server Staus Script
How about adding server load to the server status script?
Possible to get CPU load for computer?
Server Status Page? Coming back anytime soon?
Is there new Server Status Gif
Mysql Down on Server 4
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.