Topics

Server Load for android 2.1

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

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 :





  • Oleh

    Thanks for the widget. would it be hard to update load data on icon tap (click)?