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

Get from Android Market

php file ex:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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 :






Tags : android average CPU java load mobile PHP server

This entry was posted on Sunday, December 25th, 2011 at 4:46 am and is filed under Blog. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

 

Leave a Reply

 


 Top