Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php system info script

<?php
        //cpu stat
        $prevVal = shell_exec("cat /proc/stat");
        $prevArr = explode(' ',trim($prevVal));
        $prevTotal = $prevArr[2] + $prevArr[3] + $prevArr[4] + $prevArr[5];
        $prevIdle = $prevArr[5];
        usleep(0.15 * 1000000);
        $val = shell_exec("cat /proc/stat");
        $arr = explode(' ', trim($val));
        $total = $arr[2] + $arr[3] + $arr[4] + $arr[5];
        $idle = $arr[5];
        $intervalTotal = intval($total - $prevTotal);
        $stat['cpu'] =  intval(100 * (($intervalTotal - ($idle - $prevIdle)) / $intervalTotal));
        $cpu_result = shell_exec("cat /proc/cpuinfo | grep model name");
        $stat['cpu_model'] = strstr($cpu_result, "
", true);
        $stat['cpu_model'] = str_replace("model name    : ", "", $stat['cpu_model']);
        //memory stat
        $stat['mem_percent'] = round(shell_exec("free | grep Mem | awk '{print $3/$2 * 100.0}'"), 2);
        $mem_result = shell_exec("cat /proc/meminfo | grep MemTotal");
        $stat['mem_total'] = round(preg_replace("#[^0-9]+(?:.[0-9]*)?#", "", $mem_result) / 1024 / 1024, 3);
        $mem_result = shell_exec("cat /proc/meminfo | grep MemFree");
        $stat['mem_free'] = round(preg_replace("#[^0-9]+(?:.[0-9]*)?#", "", $mem_result) / 1024 / 1024, 3);
        $stat['mem_used'] = $stat['mem_total'] - $stat['mem_free'];
        //hdd stat
        $stat['hdd_free'] = round(disk_free_space("/") / 1024 / 1024 / 1024, 2);
        $stat['hdd_total'] = round(disk_total_space("/") / 1024 / 1024/ 1024, 2);
        $stat['hdd_used'] = $stat['hdd_total'] - $stat['hdd_free'];
        $stat['hdd_percent'] = round(sprintf('%.2f',($stat['hdd_used'] / $stat['hdd_total']) * 100), 2);
        //network stat
        $stat['network_rx'] = round(trim(file_get_contents("/sys/class/net/eth0/statistics/rx_bytes")) / 1024/ 1024/ 1024, 2);
        $stat['network_tx'] = round(trim(file_get_contents("/sys/class/net/eth0/statistics/tx_bytes")) / 1024/ 1024/ 1024, 2);
        //output headers
        header('Content-type: text/json');
        header('Content-type: application/json');
        //output data by json
        echo    
        "{"cpu": " . $stat['cpu'] . ", "cpu_model": "" . $stat['cpu_model'] . """ . //cpu stats
        ", "mem_percent": " . $stat['mem_percent'] . ", "mem_total":" . $stat['mem_total'] . ", "mem_used":" . $stat['mem_used'] . ", "mem_free":" . $stat['mem_free'] . //mem stats
        ", "hdd_free":" . $stat['hdd_free'] . ", "hdd_total":" . $stat['hdd_total'] . ", "hdd_used":" . $stat['hdd_used'] . ", "hdd_percent":" . $stat['hdd_percent'] . ", " . //hdd stats
        ""network_rx":" . $stat['network_rx'] . ", "network_tx":" . $stat['network_tx'] . //network stats
        "}";
        ?>
Comment

PREVIOUS NEXT
Code Example
Php :: php echo "<style" posts css text 
Php :: php laravel rount price to 99 
Php :: How to find data in other row with laravel-excel 
Php :: Export database to sql dump in php 
Php :: php mysql delete from multiple tables 
Php :: notify in piperx 
Php :: symfony 3.4 migrer database 
Php :: enset laravel session 
Php :: laravel This package is not auto-updated. Please set up the GitHub Hook for Packagist so that it gets updated whenever you push! 
Php :: if cat 1 then send email woocommerce functions 
Php :: traduction website with i18n 
Php :: count vs sizeof php 
Php :: php file request 
Php :: laravel session wont update 
Php :: Initialisez un tableau de 4 cases (contenant des nombres) et en faire la somme en créant une fonction somme php 
Php :: Reading the Blockchain PHP code 
Php :: Laravel You may determine if a template inheritance section has content using the @hasSection directive: 
Php :: wordpress plugin public page 
Php :: laravel collection mode 
Php :: Laravel Exclude URI from csrf token verification 
Php :: php mysql insert record if not exists in table 
Php :: how to disable laravel cors 
Php :: web.php file handling user request 
Php :: How to add watermark in FPDF PHP - Parte 1 
Php :: php execute script wait for response 
Php :: php if class exists 
Php :: sail laravel mix hot 
Php :: model all 
Php :: withCount laravel assign generic name 
Php :: run url in php 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =