GadElKareem

Server Load for android 2.1

Server load is open source widgets for android that retrieve your current server average load and display it on a widget on your android home screen, you can add more widgets for each server. The widget will update every 30 min to display your server’s current average load. Check the php example for extracting your servers’ current load.

Program test on Galaxy s2

Download
Source Code
GitHub

Get from Android Market

php file ex:

<?php
$load = getServerLoad();

if( $load !== NULL ){
    $load = explode(' ', $load['load']);
    echo $load[0];
}

function getServerLoad(){
    $os=strtolower(PHP_OS);
    if(strpos($os, 'win') === false){
        if(file_exists('/proc/loadavg')){
            $load = file_get_contents('/proc/loadavg');
            $load = explode(' ', $load, 1);
            $load = $load[0];
        }elseif(function_exists('shell_exec')){
            $load = explode(' ', `uptime`);
            $load = $load[count($load)-1];
        }else{
            return NULL;
        }

        if(function_exists('shell_exec'))
            $cpu_count = shell_exec('cat /proc/cpuinfo | grep processor | wc -l');        

        return array('load'=>$load, 'procs'=>$cpu_count);
    }else{
        if(class_exists('COM')){
            $wmi=new COM('WinMgmts:\\\\.');
            $cpus=$wmi->InstancesOf('Win32_Processor');
            $load=0;
            $cpu_count=0;
            if(version_compare('4.50.0', PHP_VERSION) == 1){
                while($cpu = $cpus->Next()){
                    $load += $cpu->LoadPercentage;
                    $cpu_count++;
                }
            }else{
                foreach($cpus as $cpu){
                    $load += $cpu->LoadPercentage;
                    $cpu_count++;
                }
            }
            return array('load'=>$load, 'procs'=>$cpu_count);
        }
        return NULL;
    }
    return NULL;
}

?>


ScreenShots :