From 158db3350522adba33f28bf78e4baad141bc5145 Mon Sep 17 00:00:00 2001 From: Richard Braun Date: Wed, 3 Aug 2016 18:17:23 +0200 Subject: Changes specific to darnassus.sceen.net --- libs/Utils/Misc.php | 11 +++-------- libs/disk.php | 2 +- libs/load_average.php | 2 +- libs/memory.php | 12 ++++++------ libs/system.php | 24 ++++++++++++++++-------- 5 files changed, 27 insertions(+), 24 deletions(-) (limited to 'libs') diff --git a/libs/Utils/Misc.php b/libs/Utils/Misc.php index 7aab276..37e578b 100644 --- a/libs/Utils/Misc.php +++ b/libs/Utils/Misc.php @@ -171,15 +171,10 @@ class Misc { $handle = @fsockopen($host, $port, $errno, $errstr, $timeout); - if (!$handle) - { - return false; - } - else - { - fclose($handle); + if ($handle) return true; - } + else + return false; } elseif ($protocol == 'udp') { diff --git a/libs/disk.php b/libs/disk.php index 8760816..f2b21cb 100644 --- a/libs/disk.php +++ b/libs/disk.php @@ -4,7 +4,7 @@ $Config = new Config(); $datas = array(); -if (!(exec('/bin/df -T -P | awk -v c=`/bin/df -T | grep -bo "Type" | awk -F: \'{print $2}\'` \'{print substr($0,c);}\' | tail -n +2 | awk \'{print $1","$2","$3","$4","$5","$6","$7}\'', $df))) +if (!(exec('/bin/df -T | awk -v c=`/bin/df -T | grep -bo "Type" | awk -F: \'{print $2}\'` \'{print substr($0,c);}\' | tail -n +2 | awk \'{print $1","$2","$3","$4","$5","$6","$7}\'', $df))) { $datas[] = array( 'total' => 'N.A', diff --git a/libs/load_average.php b/libs/load_average.php index 09a2f3c..e736814 100644 --- a/libs/load_average.php +++ b/libs/load_average.php @@ -27,4 +27,4 @@ else $datas = $load; -echo json_encode($datas); \ No newline at end of file +echo json_encode($datas); diff --git a/libs/memory.php b/libs/memory.php index a4eda7b..d2826f2 100644 --- a/libs/memory.php +++ b/libs/memory.php @@ -2,14 +2,13 @@ require '../autoload.php'; $free = 0; +$cached = 0; if (shell_exec('cat /proc/meminfo')) { $free = shell_exec('grep MemFree /proc/meminfo | awk \'{print $2}\''); $buffers = shell_exec('grep Buffers /proc/meminfo | awk \'{print $2}\''); - $cached = shell_exec('grep Cached /proc/meminfo | awk \'{print $2}\''); - - $free = (int)$free + (int)$buffers + (int)$cached; + $cached = $buffers + shell_exec('grep Cached /proc/meminfo | awk \'{print $2}\''); } // Total @@ -19,19 +18,20 @@ if (!($total = shell_exec('grep MemTotal /proc/meminfo | awk \'{print $2}\''))) } // Used -$used = $total - $free; +$used = $total - $free - $cached; // Percent used $percent_used = 0; if ($total > 0) - $percent_used = 100 - (round($free / $total * 100)); + $percent_used = round($used / $total * 100); $datas = array( 'used' => Misc::getSize($used * 1024), 'free' => Misc::getSize($free * 1024), + 'cached ' => Misc::getSize($cached * 1024), 'total' => Misc::getSize($total * 1024), 'percent_used' => $percent_used, ); -echo json_encode($datas); \ No newline at end of file +echo json_encode($datas); diff --git a/libs/system.php b/libs/system.php index 702ef3b..17ed5a4 100644 --- a/libs/system.php +++ b/libs/system.php @@ -1,6 +1,5 @@ $hostname, @@ -70,6 +77,7 @@ $datas = array( 'last_boot' => $last_boot, 'current_users' => $current_users, 'server_date' => $server_date, + 'load_avg' => $load_avg, ); -echo json_encode($datas); \ No newline at end of file +echo json_encode($datas); -- cgit v1.2.3