Created
May 20, 2020 16:17
-
-
Save arifnd/4ab5c5d1cdd9ae63ba4e931d301b479c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| ini_set('max_execution_time', 0); | |
| ini_set('memory_limit', -1); | |
| $host = '127.0.0.1'; | |
| $ports = array(80, 443, 3306); | |
| $mem = @file_get_contents('/proc/meminfo'); | |
| $mem = preg_replace("/[[:blank:]]+/", " ", $mem); | |
| $mem = str_replace(array("\r\n", "\n\r", "\r"), "\n", $mem); | |
| $mem = explode("\n", $mem); | |
| $mem_total = explode(' ',$mem[0])[1]; | |
| $mem_free = explode(' ',$mem[1])[1]; | |
| $mem_buffer = explode(' ',$mem[3])[1]; | |
| $mem_cached = explode(' ',$mem[4])[1]; | |
| //usage = total – free – buffers – cache | |
| $mem_used = ($mem_total - $mem_free - $mem_buffer - $mem_cached); | |
| $uptime = @file_get_contents('/proc/uptime'); | |
| $uptime = floatval($uptime); | |
| $secs = ceil(fmod($uptime, 60)); $uptime = intdiv($uptime, 60); | |
| $mins = $uptime % 60; $uptime = intdiv($uptime, 60); | |
| $hours = $uptime % 24; $uptime = intdiv($uptime, 24); | |
| $days = $uptime; | |
| $data['cpu'] = sys_getloadavg()[0]; | |
| $data['mem_used'] = ceil($mem_used / $mem_total * 100); | |
| $data['uptime'] = "$days days $hours:$mins:$secs"; | |
| foreach ($ports as $port) | |
| { | |
| $connection = @fsockopen($host, $port, $errno, $errstr, 2); | |
| if (is_resource($connection)): | |
| fclose($connection); | |
| $status = TRUE; | |
| else: | |
| $status = FALSE; | |
| endif; | |
| $data['ports'][$port] = $status; | |
| } | |
| header('Content-Type: application/json'); | |
| echo json_encode($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment