Programming Basics
  Home arrow Programming Basics arrow Page 3 - Server Statistics
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Server Statistics - Final Script


    (Page 3 of 4 )

    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.

    <?php
    $uptime 
    = @exec('uptime');
    /* Get uptime from uptime command */
    preg_match("/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/",$uptime,$avgs);
    /* Break up result */
      
    $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);
    /* Make dates */
    $diff=$end-$start;
    $days=$diff/86400;
    $percentage=($uptime/$days) * 100;
    /* Work out percentages */
    $load=$avgs[1].",".$avgs[2].",".$avgs[3]."";
    /* Grab average uptime into string */
    /* Format page */
    $page='&lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;Server Statistics For '
    .getenv('SERVER_NAME').'&lt;/title&gt;
    &lt;style type="text/css"&gt;
    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;
    }
    &lt;/style&gt;
    &lt;/head&gt;

    &lt;body&gt;

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

    &lt;/html&gt;'
    ;
    echo 
    $page;
    /* Print the page to browser
    Done
     */
    ?>

    More Programming Basics Articles
    More By Andrew Walsh


       · For human readablity let's throw in a line break between the existing line 14 and...
       · Personall I use <a href="http://status2k.com">Server Statistics - Status2k</a>, it's...
     

    PROGRAMMING BASICS ARTICLES

    - PHP: Hypertext Preprocessor: What is it?
    - Loops and PHP Decision Making
    - Operators, Conditionals, and PHP Decision-Ma...
    - PHP Decision-Making
    - Coding
    - Server Statistics
    - Looping in PHP
    - Cookies in PHP
    - Working with text files
    - Beginning Object Oriented Programming in PHP
    - A Tour of Decision Making Structures in PHP
    - PHP Strings Primer
    - PHP Control Structures
    - Intro to Vim
    - Reading Directorys with PHP





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek