Server Statistics

  • Uploaded by: Abhilash V Pillai
  • 0
  • 0
  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Server Statistics as PDF for free.

More details

  • Words: 950
  • Pages: 4
Server Statistics If you’ve ever wanted to generate your own server statistics such as those you get with most shared hosting environments, then this tutorial is for you. If you have ever had shared hosting, which I am sure that most of you have, then you will probably know how these hosts pack your account with loads of server statistics tools. This is all well and good but have you ever wanted to make one for yourself? If you do then this tutorial is probably for you. Basic Statistics We will start with showing the average server load and server uptime in days. Most of this can be done with the exec() function. Basically, we will be sending the server the uptime command which will then return the information we need to form our basic server stats script.

If you where to run that script on your website then you would get two statistics back, the server load and then the uptime in days. This may seem very simple. Well, to be honest this whole tutorial is quiet easy actually. In the next sections we will be applying the same principles as this code. In the next section we will be looking at how to show a percentage of how much of the year the server has been online. The basis is already there in this script.

Server Statistics - Uptime in Percentage If you looked at the last code you saw two redundant and useless date() functions. Well in this section they will be used to work out what percentage of the year so far the server has been online. All we do is add a line to calculate the percentage uptime. Here is the whole block of code to work out the percentage of the year so far.
/* Print out percentage */ ?>

This could be used for anything, firstly we use $start and mktime to acquire the number of seconds since 1/1/(the current year) and then we aquire today’s date using the same function. To work out how long in seconds the server has been online we take $start from $end. Now to work out the days we divide the result by 86400 and we will get a number of days which then we divide by $uptime (obtained from the first code snippet) and multiply by 100 to get a percentage. Simple wasn’t it? Next we will work on a more complex version, this will include listing of server variables like the server name, IP, port, software and gateway.

Server Statistics - Final Script As I promised here is a more advanced version which displays server name, IP, port, software, gateway, and a few others. You may recognize this from the codewalkers code gallery where I posted it. This has a nice little html template used for displaying the results so it does look alot nicer than previous scripts.
<table width="100%" cellspacing="0" cellpadding="0" style="border: 1 solid #000000" bo <tr> <td width="50%" bgcolor="#3973AC" style="border: 1 solid #000000"><font colo Details</font></td> <td width="50%" bgcolor="#3973AC" style="border: 1 solid #000000"><font colo Statistics</font></td> </tr> <tr> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000">&nbsp;< <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000">&nbsp;< </tr> <tr> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Name </td> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Upti (days): '.$uptime.'</td> </tr> <tr> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Port '.getenv('SERVER_PORT').'</td> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Upti </b> (%): '.$percentage.'%</td> </tr> <tr> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Soft </b> '.getenv('SERVER_SOFTWARE').'</td> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Load </tr> <tr> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Prot

<td width="50%" bgcolor="#7CA8D3" rowspan="3" style="border: 1 solid #000000">& </tr> <tr> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000"><b>Gate

</tr> <tr> <td width="50%" bgcolor="#7CA8D3" style="border: 1 solid #000000">&nbsp;< </tr> </table> </body> </html>'; echo $page; /* Print the page to browser Done */ ?>

Server Statistics - Conclusion This may not be the best of server statistics scripts around but it certainly shows you how to intergrate a unix/linux command into a PHP script to return results. (This will not work on Windows.) The possibilities of improving this script are endless, for example you could add a daily digest of average results then mail them to the site Administrator/Webmaster. I hope this fairly short tutorial has been of some help to you.

About the Author Andrew Walsh lives in the UK and is engaged in his secondary education. He wishes to pursue a higher education in computer studies. He started programming at the age of 13 years, currently he has knowledge of PHP/MySQL, (X)HTML, CSS and JavaScript.

Related Documents

Server Statistics
December 2019 11
Statistics
May 2020 22
Statistics
May 2020 15
Statistics
July 2020 19
Statistics
November 2019 16
Statistics
November 2019 25

More Documents from ""