public static 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 * 60 * 24 - $hours * 60);
     if ($days !== 0) {
         $res['uptime'] = $days . "天";
     }
     if ($hours !== 0) {
         $res['uptime'] .= $hours . "小时";
     }
     $res['uptime'] .= $min . "分钟";
     //MEMORY
     if (false === ($buf = get_key("hw.physmem"))) {
         return false;
     }
     $res['memTotal'] = round($buf / 1024 / 1024, 2);
     $buf = explode("\n", 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("\n", 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;
 }
Example #2
0
if ($argcount > $cmdidx) {
    // The command is the first thing after the options
    $args = array_slice($argv, $cmdidx);
    do_command($args);
}
/*
 * Start running the commands if we are in interactive mode
 -------------------------------------------------------------------- */
if ($interactive) {
    $cmd = '';
    while ($cmd != 'exit') {
        $args = do_readline();
        if ($args === null) {
            continue;
        }
        do_command($args);
    }
}
/*
 * Start reading lines from the command line and adding them to
 * our history 
 * -------------------------------------------------------------------- */
function do_readline($prompt = 'command > ')
{
    if (function_exists('readline')) {
        $cmd = readline($prompt);
        if ($cmd === '') {
            return null;
        }
        readline_add_history($cmd);
    } else {
Example #3
0
File: p.php Project: php360/ltnmp
function get_key($keyName)
{
    return do_command('sysctl', "-n {$keyName}");
}
Example #4
0
 public function sys_freebsd()
 {
     //freeBSD系统探测
     $res['cpu']['num'] = do_command('sysctl', 'hw.ncpu');
     //CPU
     $res['cpu']['model'] = do_command('sysctl', 'hw.model');
     $res['loadAvg'] = do_command('sysctl', 'vm.loadavg');
     //Load AVG  系统负载
     //uptime
     $buf = do_command('sysctl', 'kern.boottime');
     $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 * 60 * 24 - $hours * 60);
     $res['uptime'] = $days . '天' . $hours . '小时' . $min . '分钟';
     //内存
     $buf = do_command('sysctl', 'hw.physmem');
     $resmem['memTotal'] = round($buf / 1024 / 1024, 2);
     $str = do_command('sysctl', 'vm.vmtotal');
     preg_match_all("/\nVirtual Memory[\\:\\s]*\\(Total[\\:\\s]*([\\d]+)K[\\,\\s]*Active[\\:\\s]*([\\d]+)K\\)\n/i", $str, $buff, PREG_SET_ORDER);
     preg_match_all("/\nReal Memory[\\:\\s]*\\(Total[\\:\\s]*([\\d]+)K[\\,\\s]*Active[\\:\\s]*([\\d]+)K\\)\n/i", $str, $buf, PREG_SET_ORDER);
     $resmem['memRealUsed'] = round($buf[0][2] / 1024, 2);
     $resmem['memCached'] = round($buff[0][2] / 1024, 2);
     $resmem['memUsed'] = round($buf[0][1] / 1024, 2) + $resmem['memCached'];
     $resmem['memFree'] = $resmem['memTotal'] - $resmem['memUsed'];
     $resmem['memPercent'] = floatval($resmem['memTotal']) != 0 ? round($resmem['memUsed'] / $resmem['memTotal'] * 100, 2) : 0;
     $resmem['memRealPercent'] = floatval($resmem['memTotal']) != 0 ? round($resmem['memRealUsed'] / $resmem['memTotal'] * 100, 2) : 0;
     $resmem = $this->formatmem($resmem);
     $res = array_merge($res, $resmem);
     return $res;
 }