Display Server Load in Footer

Looking for a MOD? Have a MOD request? Post here for help. (Note: This forum is community supported; phpBB does not have official MOD authors)
Scam Warning
Locked
trumpet_is_cool
Registered User
Posts: 1
Joined: Sat Feb 10, 2007 11:52 am

Display Server Load in Footer

Post by trumpet_is_cool »

Hi i got this code to get the uptime and average load of the server :

Code: Select all

<?php
function uptime() {
    //Script for reading Uptime
    if( $fd = @fopen('/proc/uptime', 'r')) {
        $ar_buf = split(' ', fgets($fd, 4096));
        fclose($fd);

        $sys_ticks = trim($ar_buf[0]);

        $min   = $sys_ticks / 60;
        $hours = $min / 60;
        $days  = floor($hours / 24);
        $hours = floor($hours - ($days * 24));
        $min   = floor($min - ($days * 60 * 24) - ($hours * 60));

        if ($days != 0) {
            $result = $days."d ";
        }

        if ($hours != 0) {
            $result .= $hours."h ";
        }
            
        $result .= $min ."m";
    } else {
        $result = "n/a";
    }

    return $result;
}


function loadavg() {
    //Serverload
    if ($fd = @fopen('/proc/loadavg', 'r')) {
            $results = split(' ', fgets($fd, 4096));
            fclose($fd);
    } else {
            $results = array('N.A.','N.A.','N.A.');
    }

    return $results;
}

$uptime=uptime();
$loadavg=loadavg();
echo("&raquo; Up: " . $uptime . "<br>");
echo("&raquo; Load: " . $loadavg[0]. "<br>");
?> 
I would like to display this informations either in the mpc_footer or in the overall_footer but i don`t have a clue how to do this :oops:

Any help is appreciated !

Thanks..

Dennis
User avatar
stickerboy
Former Team Member
Posts: 7349
Joined: Mon Mar 29, 2004 2:27 pm
Location: Airdrie, UK (127.0.0.1)
Name: Kenny Cameron
Contact:

Re: Display Server Load in Footer

Post by stickerboy »

Iy you enable php in your template files (ACP -> General -> Server configuration -> Allow php in templates [at the bottom of the page]), it should be quite easy.
Remove the opening and closing tags in the code you have <?php ?>
Replace them with:

Code: Select all

<!-- PHP -->
<!-- ENDPHP -->
Now, add your code between the new php tags and paste it into your template file.
If you're good with html, should be easy to create a table or a new div layer to put it in :)
I'm a web-designing code-decrypting tech-support musician
|| Twitter || Flickr || phpBB Snippets ||
Formerly known as cherokee red
User avatar
m157y
Registered User
Posts: 482
Joined: Mon Apr 30, 2007 9:39 am
Location: Russia, Moscow, Khimki
Contact:

Re: Display Server Load in Footer

Post by m157y »

and for what you post it? go to config.php and uncomment

Code: Select all

// @define('DEBUG', true);
// @define('DEBUG_EXTRA', true);
and enjoy ;)
m157y aka Misty
NO SUPPORT VIA PM
KarmaMOD for phpBB 3.0.x | bbAJAX
Follow me on twitter
yaw_pakhtoon
Registered User
Posts: 107
Joined: Wed Sep 12, 2007 12:18 am

Re: Display Server Load in Footer

Post by yaw_pakhtoon »

m157y wrote:and for what you post it? go to config.php and uncomment

Code: Select all

// @define('DEBUG', true);
// @define('DEBUG_EXTRA', true);
and enjoy ;)

when you say uncomment..what do you mean by that.. :oops:
Image
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34457
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: Display Server Load in Footer

Post by A_Jelly_Doughnut »

Remove the two slashes at the beginning of each the line.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
yaw_pakhtoon
Registered User
Posts: 107
Joined: Wed Sep 12, 2007 12:18 am

Re: Display Server Load in Footer

Post by yaw_pakhtoon »

thanks it works.. :D
Image
Locked

Return to “[3.0.x] MOD Requests”