Server,Uptime,Statistics,php

Ron 10/11/2016 0

Server Uptime Statistics in PHP

PHP
<?php 

$uptime = @exec('uptime'); 
preg_match("/averages?: ([0-9\.] ),[\s] ([0-9\.] ),[\s] ([0-9\.] )/",$uptime,$avgs); 
  $uptime = explode(' up ', $uptime); 
  $uptime = explode(',', $uptime[1]); 
  $uptime = $uptime[0].', '.$uptime[1]; 
  $start=mktime(0, 0, 0, 1, 1, date("Y"), 0); 
$end=mktime(0, 0, 0, date("m"), date("j"), date("y"), 0); 
$diff=$end-$start; 
$days=$diff/86400; 
$percentage=($uptime/$days) * 100; 
$load=$avgs[1].",".$avgs[2].",".$avgs[3].""; 
$page='<html> 
<head> 
<title>Server Statistics For '.getenv('SERVER_NAME').'</title> 
<style type="text/css"> 
td{ 
border-style: solid; 
border-width: 1px; 
color: #000000; 
} 
table{ 
border-style: solid; 
border-width: 1px; 
color: #000000; 
} 
tr{ 
border-style: solid; 
border-width: 1px; 
color: #000000; 
} 
</style> 
</head> 

<body> 

<table width="100%" cellspacing="0" cellpadding="0" style="border: 1 solid #000000" border="1"> 
  <tr> 
    <td width="50%" bgcolor="#3973AC" style="border: 1 solid #000000"><font color="#FFFFFF">Server 
      Details</font></td> 
    <td width="50%" bgcolor="#3973AC" style="border: 1 solid #000000"><font color="#FFFFFF">Server 
      Statistics</font></td> 
  </tr> 
  <tr> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"> </td> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"> </td> 
  </tr> 
  <tr> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Name:</b> '.getenv('SERVER_NAME').' 
      </td> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Uptime</b> 
      (days): '.$uptime.'</td> 
  </tr> 
  <tr> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Port:</b> 
      '.getenv('SERVER_PORT').'</td> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Uptime 
      </b> 
      (%): '.$percentage.'%</td> 
  </tr> 
  <tr> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Software: 
      </b> 
      '.getenv('SERVER_SOFTWARE').'</td> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Load:</b>  '.$load.'  </td> 
  </tr> 
  <tr> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Protocol:</b>  '.getenv('SERVER_PROTOCOL').'</td> 
    <td width="50%" bgcolor="#7CA8D3" rowspan="3" style="border: 1 solid #000000"></td> 
  </tr> 
  <tr> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Gateway:</b> '.getenv('GATEWAY_INTERFACE').'</td> 
  </tr> 
  <tr> 
    <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"> </td> 
  </tr> 
</table> 
<p align="center"></p> 
</body> 

</html>'; 
echo $page; 
?> 
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments