<?php


function get_server_memory_usage(){
    $free = shell_exec('free');
    $free = (string)trim($free);
    $free_arr = explode("\n", $free);
    $mem = explode(" ", $free_arr[1]);
    $mem = array_filter($mem);
    $mem = array_merge($mem);
    $memory_usage = $mem[2]/$mem[1]*100;
    return $memory_usage;
}


function getLoadPercentage() {
    $load = sys_getloadavg();
    $loadPercentage = $load[0]*100;
    return $loadPercentage;
}


while(true){
    $gb = disk_free_space("/")/1073741824;
    $message = json_encode([
        'cpu'=>round(getLoadPercentage()),
        'memory'=>round(get_server_memory_usage()),
        'disk'=>round((437-$gb)/437*100),
        'disk_gb'=>round((437-$gb),2)
    ]);




    shell_exec("php /var/www/html/admin/artisan redis:publish '{$message}'");
    sleep(2);
}
