summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShevAbam <shevabam@gmail.com>2014-06-18 10:15:18 +0200
committerShevAbam <shevabam@gmail.com>2014-06-18 10:15:18 +0200
commit3f6a49bae3ec616469f21dfbbbaff052055b0c0e (patch)
treec59f35c5a6b84b05a2bacd61e4c9655cfb554688
parent20705a550df5b13a544dc0865c6aef16e64c99d9 (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
-rw-r--r--.gitignore1
-rw-r--r--esm.config.json9
-rw-r--r--index.php8
-rw-r--r--libs/Utils/Config.class.php4
-rw-r--r--libs/disk.php15
-rw-r--r--libs/load_average.php12
-rw-r--r--libs/memory.php4
-rw-r--r--libs/network.php2
-rw-r--r--libs/services.php4
-rw-r--r--libs/swap.php1
-rw-r--r--libs/system.php17
11 files changed, 50 insertions, 27 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1a0a3d6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/web/css/.sass-cache
diff --git a/esm.config.json b/esm.config.json
index f5812fe..e0a6ebd 100644
--- a/esm.config.json
+++ b/esm.config.json
@@ -1,8 +1,11 @@
{
"esm": {
- "version": "2.0",
+ "version": "2.1",
"website": "http://www.ezservermonitor.com"
},
+ "disk": {
+ "show_tmpfs": false
+ },
"ping": {
"hosts": [
"free.fr",
@@ -16,18 +19,22 @@
"services": [
{
"name": "Web Server (Apache)",
+ "host": "localhost",
"port": 80
},
{
"name": "FTP Server (ProFTPd)",
+ "host": "localhost",
"port": 21
},
{
"name": "Databases (MySQL)",
+ "host": "localhost",
"port": 3306
},
{
"name": "SSH",
+ "host": "localhost",
"port": 22
}
]
diff --git a/index.php b/index.php
index a5178d2..52ba89d 100644
--- a/index.php
+++ b/index.php
@@ -8,7 +8,7 @@ $update = $Config->checkUpdate();
<html lang="en">
<head>
<meta charset="utf-8">
- <title>eZ Server Monitor - <?= Misc::getHostname(); ?></title>
+ <title>eZ Server Monitor - <?php echo Misc::getHostname(); ?></title>
<link rel="stylesheet" href="web/css/utilities.css" type="text/css">
<link rel="stylesheet" href="web/css/frontend.css" type="text/css">
<!--[if IE]>
@@ -40,16 +40,16 @@ $update = $Config->checkUpdate();
<nav role="main">
<div id="appname">
<a href="index.php"><span class="icon-gauge"></span>eSM</a>
- <a href="<?= $Config->get('esm:website'); ?>"><span class="subtitle">eZ Server Monitor - v<?= $Config->get('esm:version'); ?></span></a>
+ <a href="<?php echo $Config->get('esm:website'); ?>"><span class="subtitle">eZ Server Monitor - v<?php echo $Config->get('esm:version'); ?></span></a>
</div>
<div id="hostname">
- <?= Misc::getHostname(); ?> - <?= Misc::getLanIP(); ?>
+ <?php echo Misc::getHostname(); ?> - <?php echo Misc::getLanIP(); ?>
</div>
<?php if (!is_null($update)): ?>
<div id="update">
- <a href="<?= $update['fullpath']; ?>">New version available (<?= $update['availableVersion']; ?>) ! Click here to download</a>
+ <a href="<?php echo $update['fullpath']; ?>">New version available (<?php echo $update['availableVersion']; ?>) ! Click here to download</a>
</div>
<?php endif; ?>
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