- 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
This commit is contained in:
ShevAbam 2014-06-18 10:15:18 +02:00
parent 20705a550d
commit 3f6a49bae3
11 changed files with 50 additions and 27 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/web/css/.sass-cache

View File

@ -1,8 +1,11 @@
{ {
"esm": { "esm": {
"version": "2.0", "version": "2.1",
"website": "http://www.ezservermonitor.com" "website": "http://www.ezservermonitor.com"
}, },
"disk": {
"show_tmpfs": false
},
"ping": { "ping": {
"hosts": [ "hosts": [
"free.fr", "free.fr",
@ -16,18 +19,22 @@
"services": [ "services": [
{ {
"name": "Web Server (Apache)", "name": "Web Server (Apache)",
"host": "localhost",
"port": 80 "port": 80
}, },
{ {
"name": "FTP Server (ProFTPd)", "name": "FTP Server (ProFTPd)",
"host": "localhost",
"port": 21 "port": 21
}, },
{ {
"name": "Databases (MySQL)", "name": "Databases (MySQL)",
"host": "localhost",
"port": 3306 "port": 3306
}, },
{ {
"name": "SSH", "name": "SSH",
"host": "localhost",
"port": 22 "port": 22
} }
] ]

View File

@ -8,7 +8,7 @@ $update = $Config->checkUpdate();
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <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/utilities.css" type="text/css">
<link rel="stylesheet" href="web/css/frontend.css" type="text/css"> <link rel="stylesheet" href="web/css/frontend.css" type="text/css">
<!--[if IE]> <!--[if IE]>
@ -40,16 +40,16 @@ $update = $Config->checkUpdate();
<nav role="main"> <nav role="main">
<div id="appname"> <div id="appname">
<a href="index.php"><span class="icon-gauge"></span>eSM</a> <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>
<div id="hostname"> <div id="hostname">
<?= Misc::getHostname(); ?> - <?= Misc::getLanIP(); ?> <?php echo Misc::getHostname(); ?> - <?php echo Misc::getLanIP(); ?>
</div> </div>
<?php if (!is_null($update)): ?> <?php if (!is_null($update)): ?>
<div id="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> </div>
<?php endif; ?> <?php endif; ?>

View File

@ -7,7 +7,7 @@ class Config
public function __construct() public function __construct()
{ {
$this->file = $_SERVER['DOCUMENT_ROOT'].'/esm.config.json'; $this->file = __DIR__.'/../../esm.config.json';
if (file_exists($this->file)) if (file_exists($this->file))
$this->_readFile(); $this->_readFile();
@ -16,7 +16,7 @@ class Config
private function _readFile() private function _readFile()
{ {
$content = file_get_contents($this->file); $content = file_get_contents($this->file);
$this->config = json_decode($content, true); $this->config = json_decode(utf8_encode($content), true);
} }

View File

@ -1,9 +1,11 @@
<?php <?php
require 'Utils/Misc.class.php'; require 'Utils/Misc.class.php';
require 'Utils/Config.class.php';
$Config = new Config();
$datas = array(); $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( $datas[] = array(
'total' => 'N.A', 'total' => 'N.A',
@ -15,19 +17,14 @@ if (!(exec('/bin/df | awk \'{print $2","$3","$4","$5","$6}\'', $df)))
} }
else else
{ {
$first_line = false;
$mounted_points = array(); $mounted_points = array();
foreach ($df as $mounted) foreach ($df as $mounted)
{ {
if ($first_line === false) list($type, $total, $used, $free, $percent, $mount) = explode(',', $mounted);
{
$first_line = true;
continue;
}
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)) if (!in_array($mount, $mounted_points))
{ {

View File

@ -1,21 +1,25 @@
<?php <?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); $load = array(0, 0, 0);
} }
else else
{ {
// Number of cores
$cores = (int)shell_exec('grep -c ^processor /proc/cpuinfo');
$load_exp = explode(',', $load_tmp); $load_exp = explode(',', $load_tmp);
$load = array_map( $load = array_map(
function ($value) { function ($value, $cores) {
$v = (int)($value * 100); $v = (int)($value * 100 / $cores);
if ($v > 100) if ($v > 100)
$v = 100; $v = 100;
return $v; return $v;
}, },
$load_exp $load_exp,
array_fill(0, 3, $cores)
); );
} }

View File

@ -2,13 +2,13 @@
require 'Utils/Misc.class.php'; require 'Utils/Misc.class.php';
// Free // 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; $free = 0;
} }
// Total // 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; $total = 0;
} }

View File

@ -3,7 +3,7 @@ require 'Utils/Misc.class.php';
$datas = array(); $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'); $datas[] = array('interface' => 'N.A', 'ip' => 'N.A');
} }

View File

@ -9,8 +9,8 @@ if (count($Config->get('services')) > 0)
{ {
foreach ($Config->get('services') as $service) foreach ($Config->get('services') as $service)
{ {
$ip = 'localhost'; $host = $service['host'];
$sock = @fsockopen($ip, $service['port'], $num, $error, 5); $sock = @fsockopen($host, $service['port'], $num, $error, 5);
if ($sock) if ($sock)
{ {

View File

@ -1,7 +1,6 @@
<?php <?php
require 'Utils/Misc.class.php'; require 'Utils/Misc.class.php';
// Free // Free
if (!($free = shell_exec('grep SwapFree /proc/meminfo | awk \'{print $2}\''))) if (!($free = shell_exec('grep SwapFree /proc/meminfo | awk \'{print $2}\'')))
{ {

View File

@ -7,7 +7,22 @@ $hostname = php_uname('n');
// OS // OS
if (!($os = shell_exec('/usr/bin/lsb_release -ds'))) 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 // Kernel