Programming Basics

  Home arrow Programming Basics arrow Server Statistics
PROGRAMMING BASICS

Server Statistics
By: Andrew Walsh
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 4
    2004-10-01

    Table of Contents:
  • Server Statistics
  • Uptime in Percentage
  • Final Script
  • Conclusion

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Server Statistics


    (Page 1 of 4 )

    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.

    <?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(00011date("Y"), 0);
    $end=mktime(000date("m"), date("j"), date("y"), 0);
    $diff=$end-$start;
    $days=$diff/86400;
    $percentage=($uptime/$days) * 100;
    $load=$avgs[1].",".$avgs[2].",".$avgs[3]."";
    echo 
    'Average Load: '.$load;
    echo 
    'Uptime: '.$uptime;
    ?>

    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.

    More Programming Basics Articles
    More By Andrew Walsh

    blog comments powered by Disqus

    PROGRAMMING BASICS ARTICLES

    - Control Flow Constructs
    - More Time Manipulation with PHP
    - Validating and Manipulating Dates with PHP
    - Using the Date Constructor in PHP
    - Calendar Construction with PHP
    - PHP`s Calendar Package
    - Getting Modified Versions and Correct Dates ...
    - Combining Date Functions in PHP
    - Using PHP for Date and Time in Programming
    - More Exception Handling with PHP
    - Exception Handling in PHP
    - Error Logging and Handling Exceptions
    - Configuration Directives for Error and Excep...
    - Error and Exception Handling
    - Python Modules for Games


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap