Get parameter Value FreeBSD
function Get_key ($keyName)
{
Return Do_command (' Sysctl ', "-N $keyName");
}
Determine the execution file location FreeBSD
function Find_command ($commandName)
{
$path = Array ('/bin ', '/sbin ', '/usr/bin ', '/usr/sbin ', '/usr/local/bin ', '/usr/local/sbin ');
foreach ($path as $p)
{
if (@is_executable ("$p/$commandName") return "$p/$commandName";
}
return false;
}
function Sys_freebsd ()
{
Cpu
if (false = = = = ($res [' CPU '] [' num '] = Get_key ("Hw.ncpu")) return false;
$res [' CPU '] [' detail '] = Get_key ("Hw.model");
LOAD AVG
if (false = = = ($res [' loadavg '] = Get_key ("Vm.loadavg")) return false;
$res [' loadavg '] = Str_replace ("{", "", $res [' loadavg ']);
$res [' loadavg '] = Str_replace ("}", "", $res [' loadavg ']);
UPTIME
if (false = = ($buf = Get_key ("Kern.boottime")) return false;
$buf = Explode (", $buf);
$sys _ticks = time ()-Intval ($buf [3]);
$min = $sys _ticks/60;
$hours = $min/60;
$days = Floor ($hours/24);
$hours = Floor ($hours-($days * 24));
$min = Floor ($min-($days *)-($hours * 60));
if ($days!== 0) $res [' uptime '] = $days. " Days ";
if ($hours!== 0) $res [' uptime ']. = $hours. " Hours ";
$res [' uptime ']. = $min. " Minutes ";
MEMORY
if (false = = ($buf = Get_key ("Hw.physmem")) return false;
$res [' memtotal '] = round ($buf/1024/1024, 2);
$buf = Explode ("", Do_command ("Vmstat", ""));
$buf = Explode ("", Trim ($buf [2]));
$res [' memfree '] = round ($buf [5]/1024, 2);
$res [' memused '] = ($res [' Memtotal ']-$res [' Memfree ']);
$res [' mempercent '] = (floatval ($res [' memtotal '])!=0)? Round ($res [' memused ']/$res [' Memtotal ']*100,2]: 0;
$buf = Explode ("", Do_command ("Swapinfo", "K"));
$buf = $buf [1];
Preg_match_all ("/([0-9]+) s+ ([0-9]+) s+ ([0-9]+)/", $buf, $BUFARR);
$res [' swaptotal '] = round ($bufArr [1][0]/1024, 2);
$res [' swapused '] = round ($bufArr [2][0]/1024, 2);
$res [' swapfree '] = round ($bufArr [3][0]/1024, 2);
$res [' swappercent '] = (floatval ($res [' swaptotal '])!=0)? Round ($res [' swapused ']/$res [' Swaptotal ']*100,2]: 0;
return $res;
}
The method of needle probe use
Sys_freebsd ();