Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions esm.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
"disk": {
"show_tmpfs": false
},
"servers": {
"hosts": [
"localhost"
]
},
"ping": {
"hosts": [
"facebook.com",
Expand Down
73 changes: 39 additions & 34 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php
require 'libs/Utils/Misc.class.php';
require 'libs/Utils/Config.class.php';
$Config = new Config();
$update = $Config->checkUpdate();

require 'libs/Utils/changeServer.php';
$config = new Config();
$update = $config->checkUpdate();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<?php if ($Config->get('esm:auto_refresh') > 0): ?>
<meta http-equiv="refresh" content="<?php echo $Config->get('esm:auto_refresh'); ?>">
<?php if ($config->get('esm:auto_refresh') > 0): ?>
<meta http-equiv="refresh" content="<?php echo $config->get('esm:auto_refresh'); ?>">
<?php endif; ?>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>eZ Server Monitor - <?php echo Misc::getHostname(); ?></title>
Expand Down Expand Up @@ -45,11 +45,18 @@
<nav role="main">
<div id="appname">
<a href="index.php"><span class="icon-gauge"></span>eSM</a>
<a href="<?php echo $Config->get('esm:website'); ?>"><span class="subtitle">eZ Server Monitor - v<?php echo $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">
<?php echo Misc::getHostname(); ?> - <?php echo Misc::getLanIP(); ?>
<div class="styled-select blue semi-square" id="serverChoice">
<select onchange="esm.changeServer(this.value)">
<?php echo Misc::getListServer(); ?>
</select>
</div>

<div class="blue semi-square blue-styled" id="hostname">
<!-- <?php echo Misc::getHostname(); ?> - <?php echo Misc::getLanIP(); ?> -->
<?php echo $_SESSION['server']; ?>
</div>

<?php if (!is_null($update)): ?>
Expand Down Expand Up @@ -175,31 +182,6 @@
</div>



<div class="box column-left" id="esm-network">
<div class="box-header">
<h1>Network usage</h1>
<ul>
<li><a href="#" class="reload" onclick="esm.reloadBlock('network');"><span class="icon-cycle"></span></a></li>
</ul>
</div>

<div class="box-content">
<table>
<thead>
<tr>
<th class="w15p">Interface</th>
<th class="w20p">IP</th>
<th>Receive</th>
<th>Transmit</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>


<div class="cls"></div>


Expand Down Expand Up @@ -357,6 +339,29 @@


<div class="cls"></div>

<div class="box column-left" id="esm-network">
<div class="box-header">
<h1>Network usage</h1>
<ul>
<li><a href="#" class="reload" onclick="esm.reloadBlock('network');"><span class="icon-cycle"></span></a></li>
</ul>
</div>

<div class="box-content">
<table>
<thead>
<tr>
<th class="w15p">Interface</th>
<th class="w20p">IP</th>
<th>Receive</th>
<th>Transmit</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>

</div>

Expand Down
45 changes: 30 additions & 15 deletions js/esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
var esm = {};

esm.changeServer = function(serverName) {
$.post("libs/Utils/changeServer.php",{
server: serverName
},
function(){
// esm.reloadBlock('all');
location.reload();
// alert("server : " + data);
})
}

esm.getSystem = function() {

Expand Down Expand Up @@ -163,7 +173,7 @@ esm.getNetwork = function() {

var $box = $('.box#esm-network .box-content tbody');
$box.empty();

for (var line in data)
{
var html = '';
Expand Down Expand Up @@ -211,22 +221,27 @@ esm.getServices = function() {

var $box = $('.box#esm-services .box-content tbody');
$box.empty();

for (var line in data)
{
var label_color = data[line].status == 1 ? 'success' : 'error';
var label_status = data[line].status == 1 ? 'online' : 'offline';

var html = '';
html += '<tr>';
html += '<td class="w15p"><span class="label '+label_color+'">'+label_status+'</span></td>';
html += '<td>'+data[line].name+'</td>';
html += '<td class="w15p">'+data[line].port+'</td>';
html += '</tr>';


if (data.length === 0) {
var html = '<tr><td>No services configured</td></tr>';
$box.append(html);
} else {
for (var line in data)
{
var label_color = data[line].status == 1 ? 'success' : 'error';
var label_status = data[line].status == 1 ? 'online' : 'offline';

var html = '';
html += '<tr>';
html += '<td class="w15p"><span class="label '+label_color+'">'+label_status+'</span></td>';
// html += '<td>'+data[line].host+'</td>';
html += '<td>'+data[line].name+'</td>';
html += '<td class="w15p">'+data[line].port+'</td>';
html += '</tr>';

$box.append(html);
}
}

}, 'json');

}
Expand Down
1 change: 0 additions & 1 deletion libs/Utils/Config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function get($var)
return $tab == $this->config ? null : $tab;
}


/**
* Returns all config variables
*/
Expand Down
40 changes: 37 additions & 3 deletions libs/Utils/Misc.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,36 @@ public static function getSize($filesize, $precision = 2)
return round($filesize, $precision).' '.$units[$idUnit].'B';
}

public static function getListServer() {
$output = '';
foreach ($_SESSION['serverList'] as $server) {
if ($_SESSION['server'] == $server) {
$output .= '<option value="'. $server .'" SELECTED>'. $server .'</option>';
} else {
$output .= '<option value="'. $server .'">'. $server .'</option>';
}
}
return $output;
}

/**
* Returns hostname
*/
public static function getHostname()
{
return php_uname('n');
return self::execShellServer('hostname');
}


/**
* Returns server IP
*/
public static function getLanIp()
{
return $_SERVER['SERVER_ADDR'];
$cmd = self::execShellServer('hostname -I | awk \'{print $1}\'');
if (strpos($cmd, '127.')!== false) {
$cmd = self::execShellServer('hostname -I | awk \'{print $2}\'');
}
return $cmd;
}

/**
Expand All @@ -54,4 +68,24 @@ public static function pluralize($nb, $plural = 's', $singular = '')
{
return $nb > 1 ? $plural : $singular;
}

/**
*
* @param string $cmd
* @return string
*/
public function execShellServer($cmd) {
if ($_SESSION['server'] != 'localhost') {
$cmd = 'ssh root@' . $_SESSION['server'] .' ' . $cmd;
}
return shell_exec($cmd);
}

public function execServer($cmd) {
if ($_SESSION['server'] != 'localhost') {
$cmd = 'ssh root@' . $_SESSION['server'] .' ' . $cmd;
}
exec($cmd, $ret);
return $ret;
}
}
18 changes: 18 additions & 0 deletions libs/Utils/changeServer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
session_start();
require 'Misc.class.php';
require 'Config.class.php';
$config = new Config();
if (!isset($_SESSION['server'])) {
$_SESSION = array(
'server' => $config->get("servers:hosts")[0],
'serverList' => $config->get("servers:hosts"),
);
}

if (isset($_REQUEST['server'])) {
$_SESSION['server'] = $_REQUEST['server'];
}


?>
6 changes: 3 additions & 3 deletions libs/cpu.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

require 'Utils/changeServer.php';
// Number of cores
if (!($num_cores = shell_exec('/bin/grep -c ^processor /proc/cpuinfo')))
if (!($num_cores = Misc::execShellServer('/bin/grep -c ^processor /proc/cpuinfo')))
{
$num_cores = 'N.A';
}


// CPU info
if (!($cpuinfo = shell_exec('cat /proc/cpuinfo')))
if (!($cpuinfo = Misc::execShellServer('cat /proc/cpuinfo')))
{
$model = 'N.A';
$frequency = 'N.A';
Expand Down
12 changes: 7 additions & 5 deletions libs/disk.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php
require 'Utils/Misc.class.php';
require 'Utils/Config.class.php';
require 'Utils/changeServer.php';
$Config = new Config();

$datas = array();

if (!(exec('/bin/df -T | awk -v c=`/bin/df -T | grep -bo "Type" | awk -F: \'{print $1}\'` \'{print substr($0,c);}\' | tail -n +2 | awk \'{print $1","$2","$3","$4","$5","$6}\'', $df)))
$cmd = '/bin/df -T | awk \'{print $2","$3","$4","$5","$6","$7}\' | sed \'1d\'';
$df = Misc::execServer($cmd);
//echo "<pre>"; var_export($df); flush(); echo "</pre>";
if (!$df)
{
$datas[] = array(
'total' => 'N.A',
Expand All @@ -23,8 +25,9 @@
{
list($type, $total, $used, $free, $percent, $mount) = explode(',', $mounted);

if (strpos($type, 'tmpfs') !== false && $Config->get('disk:show_tmpfs') === false)
if ((strpos($type, 'tmpfs') !== false && $Config->get('disk:show_tmpfs') === false) || (strpos($type, 'fuse') !== false)) {
continue;
}

if (!in_array($mount, $mounted_points))
{
Expand All @@ -42,5 +45,4 @@

}


echo json_encode($datas);
4 changes: 2 additions & 2 deletions libs/last_login.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
require 'Utils/Config.class.php';
require 'Utils/changeServer.php';
$Config = new Config();


$datas = array();

if (!(exec('/usr/bin/lastlog --time 365 | /usr/bin/awk \'{print $1","$3","$4" "$5" "$6" "$7" "$8}\'', $users)))
if (!($users = Misc::execServer('/usr/bin/lastlog --time 365 | /usr/bin/awk \'{print $1","$3","$4" "$5" "$6" "$7" "$8}\'')))
{
$datas[] = array(
'user' => 'N.A',
Expand Down
6 changes: 3 additions & 3 deletions libs/load_average.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

if (!($load_tmp = shell_exec('cat /proc/loadavg | awk \'{print $1","$2","$3}\'')))
require 'Utils/changeServer.php';
if (!($load_tmp = Misc::execShellServer('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');
$cores = (int)Misc::execShellServer('grep -c ^processor /proc/cpuinfo');

$load_exp = explode(',', $load_tmp);

Expand Down
6 changes: 3 additions & 3 deletions libs/memory.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php
require 'Utils/Misc.class.php';
require 'Utils/changeServer.php';

// Free
if (!($free = shell_exec('/usr/bin/free -to | grep Mem: | awk \'{print $4+$6+$7}\'')))
if (!($free = Misc::execShellServer('/usr/bin/free -to | grep Mem: | awk \'{print $4+$6+$7}\'')))
{
$free = 0;
}

// Total
if (!($total = shell_exec('/usr/bin/free -to | grep Mem: | awk \'{print $2}\'')))
if (!($total = Misc::execShellServer('/usr/bin/free -to | grep Mem: | awk \'{print $2}\'')))
{
$total = 0;
}
Expand Down
Loading