Пример #1
0
$users_out = substr($update_out[2], strrpos($update_out[2], ' ') + 1);
$uptime_out = substr($update_out[2], 0, strrpos($update_out[2], ' ') - 2);
// Array containing the three load averages
$load_out = explode(", ", $update_out[4]);
// Hard drive percentage
$hd = explode(" ", exec("df /"));
$hd_out = 100 - calculate_percentage($hd[2], $hd[1]);
$memory = array('Total RAM' => 'MemTotal', 'Free RAM' => 'MemFree', 'Cached RAM' => 'Cached', 'Total Swap' => 'SwapTotal', 'Free Swap' => 'SwapFree');
foreach ($memory as $key => $value) {
    $memory[$key] = kb2bytes(numbers_only(exec('grep -E "^' . $value . '" /proc/meminfo')));
}
$memory['Used Swap'] = $memory['Total Swap'] - $memory['Free Swap'];
$memory['Used RAM'] = $memory['Total RAM'] - $memory['Free RAM'] - $memory['Cached RAM'];
$memory['RAM Percent Free'] = calculate_percentage($memory['Used RAM'], $memory['Total RAM']);
$memory['Swap Percent Free'] = calculate_percentage($memory['Used Swap'], $memory['Total Swap']);
$temp = exec('acpi -t');
$temp = str_replace("Thermal 0: ok, ", "", $temp);
$cpu = exec('cat /proc/cpuinfo | grep "cpu MHz"');
$cpu_ar = explode(" ", $cpu);
$cpu_out = (int) $cpu_ar[2];
define('GREEN', "#3DB015");
define('YELLOW', "#FAFC4F");
define('RED', "#C9362E");
// Since we can't specify checking of any arbitrary process from the AJAX request (injection risk), we pre-define the processes here.
$processes = array("apache" => "", "mysql" => "", "craftbukkit" => "");
foreach ($processes as $key => $value) {
    $processes[$key] = checkProcess($key);
}
$result = array("uptime" => $uptime_out, "temp" => $temp, "load" => array($load_out[0], $load_out[1], $load_out[2]), "proc" => $cpu_out, "disk" => array($hd_out, format_bytes(kb2bytes($hd[2])), format_bytes(kb2bytes($hd[1]))), "memory" => array($memory["RAM Percent Free"], $memory["Used RAM"], $memory["Total RAM"], format_bytes($memory["Used RAM"]), format_bytes($memory["Total RAM"])), "service" => array("apache" => $processes["apache"], "mysql" => $processes["mysql"], "craftbukkit" => $processes["craftbukkit"]));
header("Content-type: application/json");
echo json_encode($result);
Пример #2
0
function status()
{
    if (checkProcess() == FALSE) {
        echo "The Ranksystem does not seem to run.\n";
    } else {
        echo "The Ranksystem seems to be running.\n";
    }
    $GLOBALS['exec'] = TRUE;
}