Mikor -
Joined: 21 Aug 2006 Posts: 144 Location: Hull, England
|
Posted: Wed Aug 23, 2006 9:03 pm Post subject: PHP: Parsing and Displaying Server Statistics |
|
|
Here are some useful snippits of code that allow you to parse (put in a sensible format) and display server statistics.
Total Uptime
Put this code at the top of your page:
Code: | <?php
$output['time_hours'] = round($_SERVER['X_ABYSS_STATS_SERVER_UPTIME']/60/60,0);
$output['time_remainder'] = ($_SERVER['X_ABYSS_STATS_SERVER_UPTIME']/60/60) - $output['time_hours'];
$output['time_minutes'] = round($output['time_remainder']*60,0);
$output['time_remainder'] = ($output['time_remainder']*60) - $output['time_minutes'];
$output['time_seconds'] = round($output['time_remainder'] * 60,0);
if($output['time_seconds'] < 0){
$output['time_seconds'] = $output['time_seconds'] + 60;
}
if($output['time_minutes'] < 0){
$output['time_minutes'] = $output['time_minutes'] + 60;
}
if($output['time_seconds'] < 10){
$output['time_seconds'] = '0'.$output['time_seconds'];
}
if($output['time_minutes'] < 10){
$output['time_minutes'] = '0'.$output['time_minutes'];
}
$total_uptime = $output['time_hours'] . ':' . $output['time_minutes'] . ':' . $output['time_seconds'];
?> |
And then put this code wherever you want to say the uptime:
Code: | Total Uptime: <?php echo $total_uptime; ?> |
Uptime Since Last Reset
Put this code at the top of your page:
Code: | <?php
$output['time_hours'] = round($_SERVER['X_ABYSS_STATS_SERVER_CURRENT_UPTIME']/60/60,0);
$output['time_remainder'] = ($_SERVER['X_ABYSS_STATS_SERVER_CURRENT_UPTIME']/60/60) - $output['time_hours'];
$output['time_minutes'] = round($output['time_remainder']*60,0);
$output['time_remainder'] = ($output['time_remainder']*60) - $output['time_minutes'];
$output['time_seconds'] = round($output['time_remainder'] * 60,0);
if($output['time_seconds'] < 0){
$output['time_seconds'] = $output['time_seconds'] + 60;
}
if($output['time_minutes'] < 0){
$output['time_minutes'] = $output['time_minutes'] + 60;
}
if($output['time_seconds'] < 10){
$output['time_seconds'] = '0'.$output['time_seconds'];
}
if($output['time_minutes'] < 10){
$output['time_minutes'] = '0'.$output['time_minutes'];
}
$current_uptime = $output['time_hours'] . ':' . $output['time_minutes'] . ':' . $output['time_seconds'];
?> |
And then put this code wherever you want to say the uptime:
Code: | Current Uptime: <?php echo $current_uptime; ?> |
Data Sent
Put this code at the top of your page:
Code: | <?php
$output['data_b'] = $_SERVER['X_ABYSS_STATS_SERVER_OUTPUT'];
$output['data_kb'] = round($_SERVER['X_ABYSS_STATS_SERVER_OUTPUT']/1024,0);
$output['data_mb'] = round($_SERVER['X_ABYSS_STATS_SERVER_OUTPUT']/1024/1024,0);
$output['data_gb'] = round($_SERVER['X_ABYSS_STATS_SERVER_OUTPUT']/1024/1024/1024,0);
if($output['data_b'] < 1024){
$data = $output['data_b'] . ' bytes';
}elseif($output['data_kb'] < 1024){
$data = $output['data_kb'] . ' kilobytes';
}elseif($output['data_mb'] < 1024){
$data = $output['data_mb'] . ' megabytes';
}elseif($output['data_gb'] < 1024){
$data = $output['data_gb'] . ' gigabytes';
}
?> |
Put this where you want the output to be displayed:
Code: | Data Sent: <?php echo $data; ?> |
Display Hit Info
Put this where you want the hits to be displayed:
Code: | Total Hits: <?php echo $_SERVER['X_ABYSS_STATS_SERVER_TOTAL']; ?><br />
Error Hits: <?php echo $_SERVER['X_ABYSS_STATS_SERVER_ERROR']; ?><br />
Html Hits: <?php echo $_SERVER['X_ABYSS_STATS_SERVER_HTML']; ?><br />
Image Hits: <?php echo $_SERVER['X_ABYSS_STATS_SERVER_IMAGE']; ?> |
A demo of all these codes in effect is on the main page of my server (click the image in my signature) _________________ Yarrt.com - Free Arcade
RypNet.co.uk - Online Game
MSN: michael_walker_2004 <at> hotmail <dot> com |
|