The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Uptime Percentage Script

Discussion in 'General Discussion' started by d10sfan, May 1, 2005.

  1. d10sfan

    d10sfan Registered

    Joined:
    Feb 25, 2005
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Sorry if this is in the wrong forum but are there any free scripts that grabs information for the cpanel logs and tells you what the uptime percentage is? Or something sort of liek that.
     
  2. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    I know this post is old, but its exactly what im looking for, so i might as well not start a new post. I have been googling and havent found any type of php/mysql script that is open source. Heck, even something cgi would work. Figure the data needs stored somewhere though, so i would think that a php/mysql combo would be best. Anyone have any recommendations?
     
  3. HelloAdam

    HelloAdam Well-Known Member

    Joined:
    Nov 6, 2005
    Messages:
    145
    Likes Received:
    0
    Trophy Points:
    16
    Hey,


    This might do the trick, not sure what you mean by Uptime percentage, like up for 100% this month or what...


    PHP:
    <?php
    $reguptime 
    trim(exec("uptime"));
    if (
    $reguptime) {
    if (
    preg_match("/, *(\d) (users?), .*: (.*), (.*), (.*)/"$reguptime$uptime)) {
    $users[0] = $uptime[1];
    $users[1] = $uptime[2];
    $loadnow $uptime[3];
    $load15 $uptime[4];
    $load30 $uptime[5];
    } else {
    $users[0] = "Unavailable";
    $users[1] = "--";
    $loadnow "Unavailable";
    $load15 "--";
    $load30 "--";
    }
    $uptime shell_exec("cut -d. -f1 /proc/uptime");
    $days floor($uptime/60/60/24);
    $hours str_pad($uptime/60/60%24,2,"0",STR_PAD_LEFT);
    $mins str_pad($uptime/60%60,2,"0",STR_PAD_LEFT);
    $secs str_pad($uptime%60,2,"0",STR_PAD_LEFT);
    }

    echo 
    "$loadnow (Load like right right right now) - $load15 (load like 15 minutes ago) and $load30 (load like 30 min ago)";
    echo 
    "<br /><br />";
    echo 
    "Server up for $days Days and $hours hours $mins minutes and $secs";

    ?>
    Enjoy!

    From,
    Adam
     
  4. celliott

    celliott Well-Known Member

    Joined:
    Jan 2, 2006
    Messages:
    460
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    United Kingdom
    Hi,

    I am guessing you want a script that shows you the uptime percentage for each service? If thats the case I would highley reccomend the Status2K script. I use this on a number of servers and its excellent for the price($20).

    Demo Here: http://www.status2k.com/demo/

    You can find more info on http://www.status2k.com

    Chris.
     
  5. MACscr

    MACscr Well-Known Member

    Joined:
    Sep 30, 2003
    Messages:
    190
    Likes Received:
    1
    Trophy Points:
    18
    cPanel Access Level:
    Root Administrator
    each service is not an issue, im basically just wanting to dupicate the type of service some third party site offer for web hosts for showing the uptime percentage average or whatever of there servers over a specified time period. Some i have seen show each month for a year, how many down times there were, for how long and what percentage that resulted in. The reason i dont want a third party site to do this is that i dont want them linking to another company that lists other hosts or offers a service i sell, etc. Plus i would rather not have the additional monthly expense. I already have a remote server that i could use to monitor the rest of my servers, just need the script now. =P

    Plus this way i will have full control of the layout of the data, be able to use it for other purposes, etc, etc.

    I really dont have to keep track of the number of downtimes and the downtime totals, but this would kind of need to stored anyway if it properly kept track of downtime over a particular time period.
     
  6. HelloAdam

    HelloAdam Well-Known Member

    Joined:
    Nov 6, 2005
    Messages:
    145
    Likes Received:
    0
    Trophy Points:
    16
    Hey,

    I don't know of any scripts that you can make on your own. But you can use cURL and get stuff from SiteUptime.com

    PHP:
    <?php

    // Enter your siteuptime.com ID
    $siteId 'http://www.siteuptime.com/statistics.php?Id=ID NUMBER&UserId=ID NUMBER';

    // YOU DON'T NEED TO EDIT THIS UNLESS YOU KNOW WHAT YOU'RE DOING
    // IF YOU TOUCH THIS AND IT BREAKS, SCREW YOURSELF, I WARNED YOU

    // THIS IS YOUR LOAD AVERAGES. TAKEN FROM YOUR APACHE SERVER

        
    $reguptime trim(exec("uptime"));
        if(
    $reguptime) {
            if(
    preg_match("/, *(\d) (users?), .*: (.*), (.*), (.*)/"$reguptime$uptime)) {
                
    $loadnow $uptime[3];
                
    $load15 $uptime[4];
            } else {
                
    $loadnow 'Unavailable';
                
    $load15 'Unavailable';
            }
        }

    // THIS IS FROM THE SITE, situptime.com, IT HANDLES YOUR UPTIME STATS
    // DO NOT TOUCH THIS STUFF

        // Put your siteuptime ID here for your summary stats
        
    $url file_get_contents($siteId);
        
    // Matches the first summary of information.
        // The basic information and such
        
    preg_match_all("/\<div\>(.*?)\<\/div\>/i"$url$matches);
        
    // Matches the average response time
        
    preg_match("/\<p\>(.*?)\<\/p\>\<br\>/i"$url$match);
        
    // Matches your yearly stats.
        
    preg_match_all("/\<table(.*?)\>(.*?)\<\/table\>/is"$url$m4tch);

    // LETS DO A CLEANUP!
    // THIS IS NOT REQUIRED. I JUST LIKED IT. >_>

        // Removes the gay classes from teh site
        
    $m4tch[2][1] = preg_replace("/ class='(.*?)'/is"''$m4tch[2][1]);
        
    // Replace the <td><strong> with th
        
    $m4tch[2][1] = preg_replace("/\<td\>\<strong\>(.*?)\<\/strong\>\<\/td\>/is""<th>\\1</th>"$m4tch[2][1]);
        
    // Reindent/newline the <tr>
        // $m4tch[2][1] = preg_replace("/\<tr\>(.*?)\<\/tr\>/is", "\t<tr>\\1</tr>\n", $m4tch[2][1]);
        // Rewords "Since:"
        
    $matches[0][0] = preg_replace("/Since:/i""Monitored Since:"$matches[0][0]);
        
    // Rewords "Lask Check"
        
    $matches[0][3] = preg_replace("/Last Check:/i""Last Checked:"$matches[0][3]);
        
    // Replaces PST +3.0 to EST
        
    $matches[0][3] = preg_replace("/\bPST\+3\.0/i""EST"$matches[0][3]);

    ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xml:lang="en" lang="en">
    <head>
        <title><?php echo $_SERVER['HTTP_HOST'].' - Server Statistics'?></title>
        <link rel="stylesheet" href="/mainstyle.css" title="Main Stylesheet" />
        <link rel="shortcut icon" href="/favicon.png" type="image/png" />
        <style type="text/css">
            table#monthly { width: 70%; margin: 0 auto; border: 1px solid #000; }
            table#monthly caption { width: 70%; margin: 0 auto; padding: 0.3em; font-weight: bold; }
            table#monthly td { text-align: right; }
            table#monthly th { background: #eee; border-bottom: 1px solid #000 }
            table#monthly td, table#monthly th { padding: 0.5em; border-right: 1px solid #000; }
            table#monthly { border-right-width: 0; }
        </style>
    </head>
    <body>
        <h1 title="Server stats powered by siteuptime.com">Server Statistics</h1>
    <?php

        
    echo "\t" '<ul>';
        for(
    $i 0$i count($matches[0]); $i++) {
            
    // The basic information and such.
            
    echo "\n\t\t" '<li>' strip_tags($matches[0][$i]) . '</li>';
        }
        
    // The average response time
        
    echo "\n\t\t" '<li>' strip_tags($match[0]) . '</li>';
        
    // Your server loadnow
        
    echo "\n\t\t" '<li>Server Load: ' $loadnow ' (now), ' $load15 ' (15 minutes ago)</li>';
        echo 
    "\n\t" '</ul>' "\n";

        echo 
    '<table id="monthly" cellspacing="0" cellpadding="0">' "\n\t" '<caption>Monthly Statistics</caption>';
        
    // Matches the 3rd table (1 = site, 2 = year, 3 = montly
        // Seconds wildcard (first to match all the attributes and shit
        
    echo $m4tch[2][1];
        echo 
    "\n" '</table>' "\n";

    ?>
    </body>
    </html>
     
  7. kistler

    kistler Well-Known Member

    Joined:
    Jan 27, 2005
    Messages:
    136
    Likes Received:
    0
    Trophy Points:
    16
    You could create a script on a remote server to run with cron that would log the "uptime" in a db. This doesn’t mean it will be 100% right, it will be relying on the network and remote server to be up 100% of the time.

    I have a script that I've created but it wasn’t coded for massive use, I would need to edit it, it has a few nice graphs – there are a few scripts that I can think of you’d most likely still need to tweak to your liking, one is at: http://scripts.freemans-web.com/
     
  8. 1337Host

    1337Host Registered

    Joined:
    Nov 20, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I am currently writing something like this for my company which will be incorporated into an analytics package as well.

    Some of the options we had in mind was to use PHP to execute a ping every 10 or 15 minutes, if the ping does not resolve, or exceeds a certain range an email alert would be dispatched to an administrator and/or client.

    Let me know if you need a hand with the development side of things, as I have a ton of code lying around from toying with this concept.
     

Share This Page