diff options
author | ShevAbam <shevabam@gmail.com> | 2014-06-18 10:15:18 +0200 |
---|---|---|
committer | ShevAbam <shevabam@gmail.com> | 2014-06-18 10:15:18 +0200 |
commit | 3f6a49bae3ec616469f21dfbbbaff052055b0c0e (patch) | |
tree | c59f35c5a6b84b05a2bacd61e4c9655cfb554688 /libs | |
parent | 20705a550df5b13a544dc0865c6aef16e64c99d9 (diff) |
- 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
Diffstat (limited to 'libs')
-rw-r--r-- | libs/Utils/Config.class.php | 4 | ||||
-rw-r--r-- | libs/disk.php | 15 | ||||
-rw-r--r-- | libs/load_average.php | 12 | ||||
-rw-r--r-- | libs/memory.php | 4 | ||||
-rw-r--r-- | libs/network.php | 2 | ||||
-rw-r--r-- | libs/services.php | 4 | ||||
-rw-r--r-- | libs/swap.php | 1 | ||||
-rw-r--r-- | libs/system.php | 17 |
8 files changed, 37 insertions, 22 deletions
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 @@ <?php require 'Utils/Misc.class.php'; +require 'Utils/Config.class.php'; +$Config = new Config(); $datas = array(); -if (!(exec('/bin/df | awk \'{print $2","$3","$4","$5","$6}\'', $df))) +if (!(exec('/bin/df -T | tail -n +2 | awk \'{print $2","$3","$4","$5","$6","$7}\'', $df))) { $datas[] = array( 'total' => '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 @@ <?php -if (!($load_tmp = shell_exec('/bin/cat /proc/loadavg | /usr/bin/awk \'{print $1","$2","$3}\''))) +if (!($load_tmp = shell_exec('cat /proc/loadavg | awk \'{print $1","$2","$3}\''))) { $load = array(0, 0, 0); } else { + // Number of cores + $cores = (int)shell_exec('grep -c ^processor /proc/cpuinfo'); + $load_exp = explode(',', $load_tmp); $load = array_map( - function ($value) { - $v = (int)($value * 100); + function ($value, $cores) { + $v = (int)($value * 100 / $cores); if ($v > 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 @@ <?php require 'Utils/Misc.class.php'; - // Free if (!($free = shell_exec('grep SwapFree /proc/meminfo | awk \'{print $2}\''))) { diff --git a/libs/system.php b/libs/system.php index 3e4ba1a..b814432 100644 --- a/libs/system.php +++ b/libs/system.php @@ -7,7 +7,22 @@ $hostname = php_uname('n'); // OS if (!($os = shell_exec('/usr/bin/lsb_release -ds'))) { - $os = 'N.A'; + if (!($os = shell_exec('cat /etc/fedora-release'))) + { + if (!($os = shell_exec('cat /etc/redhat-release'))) + { + if (!($os = shell_exec('cat /etc/mandriva-release'))) + { + if (!($os = shell_exec('cat /etc/SuSE-release'))) + { + if (!($os = shell_exec('cat /etc/centos-release'))) + { + $os = 'N.A'; + } + } + } + } + } } // Kernel |