From 3f6a49bae3ec616469f21dfbbbaff052055b0c0e Mon Sep 17 00:00:00 2001 From: ShevAbam Date: Wed, 18 Jun 2014 10:15:18 +0200 Subject: - System : fix to get the distro name - Services : fix on service names with accent - Services : ability to specify a host for each service - Network usage : fix to retrieve the name of the network interfaces - Memory : the cached and buffers memory are added to free memory now - Load Average : taking into account the number of cores - Disk usage : new option to hide tmpfs mountpoints - General : remove all PHP short tags --- libs/Utils/Config.class.php | 4 ++-- libs/disk.php | 15 ++++++--------- libs/load_average.php | 12 ++++++++---- libs/memory.php | 4 ++-- libs/network.php | 2 +- libs/services.php | 4 ++-- libs/swap.php | 1 - libs/system.php | 17 ++++++++++++++++- 8 files changed, 37 insertions(+), 22 deletions(-) (limited to 'libs') diff --git a/libs/Utils/Config.class.php b/libs/Utils/Config.class.php index 8111b32..a332b91 100644 --- a/libs/Utils/Config.class.php +++ b/libs/Utils/Config.class.php @@ -7,7 +7,7 @@ class Config public function __construct() { - $this->file = $_SERVER['DOCUMENT_ROOT'].'/esm.config.json'; + $this->file = __DIR__.'/../../esm.config.json'; if (file_exists($this->file)) $this->_readFile(); @@ -16,7 +16,7 @@ class Config private function _readFile() { $content = file_get_contents($this->file); - $this->config = json_decode($content, true); + $this->config = json_decode(utf8_encode($content), true); } diff --git a/libs/disk.php b/libs/disk.php index d3d3199..811b0b8 100644 --- a/libs/disk.php +++ b/libs/disk.php @@ -1,9 +1,11 @@ 'N.A', @@ -15,19 +17,14 @@ if (!(exec('/bin/df | awk \'{print $2","$3","$4","$5","$6}\'', $df))) } else { - $first_line = false; - $mounted_points = array(); foreach ($df as $mounted) { - if ($first_line === false) - { - $first_line = true; - continue; - } + list($type, $total, $used, $free, $percent, $mount) = explode(',', $mounted); - list($total, $used, $free, $percent, $mount) = explode(',', $mounted); + if (strpos($type, 'tmpfs') !== false && $Config->get('disk:show_tmpfs') === false) + continue; if (!in_array($mount, $mounted_points)) { diff --git a/libs/load_average.php b/libs/load_average.php index 8eea8f9..6251c0e 100644 --- a/libs/load_average.php +++ b/libs/load_average.php @@ -1,21 +1,25 @@ 100) $v = 100; return $v; }, - $load_exp + $load_exp, + array_fill(0, 3, $cores) ); } diff --git a/libs/memory.php b/libs/memory.php index 27a783e..67fee34 100644 --- a/libs/memory.php +++ b/libs/memory.php @@ -2,13 +2,13 @@ require 'Utils/Misc.class.php'; // Free -if (!($free = shell_exec('grep MemFree /proc/meminfo | awk \'{print $2}\''))) +if (!($free = shell_exec('/usr/bin/free -to | grep Mem: | awk \'{print $4+$6+$7}\''))) { $free = 0; } // Total -if (!($total = shell_exec('grep MemTotal /proc/meminfo | awk \'{print $2}\''))) +if (!($total = shell_exec('/usr/bin/free -to | grep Mem: | awk \'{print $2}\''))) { $total = 0; } diff --git a/libs/network.php b/libs/network.php index 12521bf..e486fc5 100644 --- a/libs/network.php +++ b/libs/network.php @@ -3,7 +3,7 @@ require 'Utils/Misc.class.php'; $datas = array(); -if (!(exec('/sbin/ifconfig | awk -F " " \'{print $1}\' | sed -e \'/^$/d\'', $getInterfaces))) +if (!(exec('/sbin/ifconfig |awk -F \'[/ |: ]\' \'{print $1}\' |sed -e \'/^$/d\'', $getInterfaces))) { $datas[] = array('interface' => 'N.A', 'ip' => 'N.A'); } diff --git a/libs/services.php b/libs/services.php index eaedf3a..9b83acb 100644 --- a/libs/services.php +++ b/libs/services.php @@ -9,8 +9,8 @@ if (count($Config->get('services')) > 0) { foreach ($Config->get('services') as $service) { - $ip = 'localhost'; - $sock = @fsockopen($ip, $service['port'], $num, $error, 5); + $host = $service['host']; + $sock = @fsockopen($host, $service['port'], $num, $error, 5); if ($sock) { diff --git a/libs/swap.php b/libs/swap.php index 93bd323..522660b 100644 --- a/libs/swap.php +++ b/libs/swap.php @@ -1,7 +1,6 @@