$temp0 = file_get_contents ("/sys/class/thermal/thermal_zone0/temp");
sg('pctemp',$temp0);
//CPU temp
$cpu_temp=shell_exec('cat /sys/class/thermal/thermal_zone0/temp') / 1000;
$cpu_temp=round($cpu_temp,1);
sg("CPU_temp",$cpu_temp);
//CPU usage
$cpu_usage=exec("top -bn 1 | awk '{print $9}' | tail -n +8 | awk '{s+=$1} END {print s}'");
sg("CPU_usage",$cpu_usage);
//System uptime
$sys_uptime=shell_exec("uptime");
$sys_uptime = explode(" up ", $sys_uptime);
$sys_uptime = explode(",", $sys_uptime[1]);
$sys_uptime = $sys_uptime[0].", ".$sys_uptime[1];
sg("System_uptime",$sys_uptime);
//Memory usage/total
$mem_total=exec("cat /proc/meminfo | grep MemTotal | awk '{print $2}'");
$mem_usage=$mem_total - exec("cat /proc/meminfo | grep MemFree | awk '{print $2}'");
$sys_memory=round($mem_usage * 100 / $mem_total, 1);
sg("System_memory",$sys_memory);
//Memory Card
$bytes = disk_free_space(".");
$si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' );
$base = 1024;
$class = min((int)log($bytes , $base) , count($si_prefix) - 1);
$temp = round($bytes / pow($base,$class)) . ' ' . $si_prefix[$class];
sg('System_freespace',$temp);
//CPU 1 5 15
$cpu_load=shell_exec('cat /proc/loadavg');
$pos1 = strpos($cpu_load," ");
$pos2 = strpos($cpu_load," ",$pos1+1);
$pos3 = strpos($cpu_load," ",$pos2+1);
$cpu_load1 = substr($cpu_load,0,$pos1);
$cpu_load5 = substr($cpu_load,$pos1+1,$pos2-$pos1-1);
$cpu_load15 = substr($cpu_load,$pos2+1,$pos3-$pos2-1);
sg("cpu_load1",$cpu_load1);
sg("cpu_load5",$cpu_load5);
sg("cpu_load15",$cpu_load15);
//mem info
$mem_info=shell_exec('cat /proc/meminfo');
$pos1 = strpos($mem_info,"MemTotal");
$pos2 = strpos($mem_info,"MemFree");
$pos3 = strpos($mem_info,"Cached");
$pos4 = strpos($mem_info,"SwapTotal");
$pos5 = strpos($mem_info,"SwapFree");
$mem_total = substr($mem_info,$pos1+11,13)*1;
$mem_free = substr($mem_info,$pos2+11,13)*1;
$mem_cached = substr($mem_info,$pos3+11,13)*1;
$mem_swap_total = substr($mem_info,$pos4+11,13)*1;
$mem_swap_free = substr($mem_info,$pos5+11,13)*1;
$mem_swap_used = $mem_swap_total - $mem_swap_free;
$mem_used = $mem_total - $mem_free - $mem_cached;
sg("mem_total",$mem_total);
sg("mem_free",$mem_free);
sg("mem_cached",$mem_cached);
sg("mem_swap_total",$mem_swap_total);
sg("mem_swap_free",$mem_swap_free);
sg("mem_swap_used",$mem_swap_used);
sg("mem_used",$mem_used);
$sd_info=shell_exec('df /');
$pos0 = strpos($sd_info,"dev");
$pos1 = strpos($sd_info," ",$pos0+5);
$pos2 = strpos($sd_info," ",$pos1+3);
$pos3 = strpos($sd_info," ",$pos2+3);
$pos4 = strpos($sd_info," ",$pos3+4);
$sd_total = substr($sd_info,$pos1,$pos2-$pos1)*1;
$sd_used = substr($sd_info,$pos2,$pos3-$pos2)*1;
$sd_free = substr($sd_info,$pos3,$pos4-$pos3)*1;
sg("sd_total",$sd_total);
sg("sd_used",$sd_used);
sg("sd_free",$sd_free);