<?php

namespace web\admin\rigger;

class statssrv {
    public static function json_init() {
        $status = array();
        $status['PHP版本'] = array('value' => phpversion());
        $status['操作系统'] = array('value' => php_uname());

        $cpuCount = shell_exec("cat /proc/cpuinfo | grep processor | wc -l");
        $status['CPU数量'] = array('value' => $cpuCount);
        $status['CPU占用率'] = array('value' => $cpuCount);
        $status['PHP占用率'] = array('value' => $cpuCount);
        $status['数据库占用率'] = array('value' => $cpuCount);

        $memTotal = shell_exec("cat /proc/meminfo | grep MemTotal | grep -o '[0-9]*'");
        $memTotal = round($memTotal / 1024 / 1024, 2); // 转换为GB
        $status['内存总量'] = array('value' => $memTotal);
        $status['空闲内存'] = array('value' => $memTotal);
        $status['PHP内存占用'] = array('value' => $memTotal);
        $status['数据库内存占用'] = array('value' => $memTotal);
        $status['缓存内存占用'] = array('value' => $memTotal);
        $status['其他内存占用'] = array('value' => $memTotal);

        $diskSpace = shell_exec("df -h / | grep / | grep -v Filesystem | awk '{print $2}'");
        $status['总磁盘空间'] = array('value' => $diskSpace);
        $status['空闲磁盘空间'] = array('value' => $diskSpace);

        $ret['stats'] = $status;
        return succjson($ret);
    }
}
