summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2015-10-21 13:56:04 +0200
committerSimon Rettberg2015-10-21 13:56:04 +0200
commit19abeccb7a047eecbf74c7aec6e91aa8c45a1f50 (patch)
tree5345c3411a7de5ccb23a694fc414737df52925b5
parentUpdate Circles.js to v0.0.6 (diff)
downloadslx-admin-19abeccb7a047eecbf74c7aec6e91aa8c45a1f50.tar.gz
slx-admin-19abeccb7a047eecbf74c7aec6e91aa8c45a1f50.tar.xz
slx-admin-19abeccb7a047eecbf74c7aec6e91aa8c45a1f50.zip
[systemstatus] Live CPU/mem usage stats
-rw-r--r--modules/systemstatus.inc.php100
-rw-r--r--templates/systemstatus/_page.html11
-rw-r--r--templates/systemstatus/systeminfo.html30
3 files changed, 123 insertions, 18 deletions
diff --git a/modules/systemstatus.inc.php b/modules/systemstatus.inc.php
index 253b0849..7c3fe8a1 100644
--- a/modules/systemstatus.inc.php
+++ b/modules/systemstatus.inc.php
@@ -151,12 +151,27 @@ class Page_SystemStatus extends Page
'addresses' => $task['data']['addresses']
));
}
+
+ private function sysInfo()
+ {
+ $data = array();
+ $memInfo = file_get_contents('/proc/meminfo');
+ $stat = file_get_contents('/proc/stat');
+ preg_match_all('/\b(\w+):\s+(\d+)\s/s', $memInfo, $out, PREG_SET_ORDER);
+ foreach ($out as $e) {
+ $data[$e[1]] = $e[2];
+ }
+ if (preg_match('/\bcpu\s+(?<user>\d+)\s+(?<nice>\d+)\s+(?<system>\d+)\s+(?<idle>\d+)\s+(?<iowait>\d+)\s+(?<irq>\d+)\s+(?<softirq>\d+)(\s|$)/', $stat, $out)) {
+ $data['CpuTotal'] = $out['user'] + $out['nice'] + $out['system'] + $out['idle'] + $out['iowait'] + $out['irq'] + $out['softirq'];
+ $data['CpuIdle'] = $out['idle'];
+ $data['CpuSystem'] = $out['iowait'] + $out['irq'] + $out['softirq'];
+ }
+ return $data;
+ }
protected function ajaxSystemInfo()
{
$cpuInfo = file_get_contents('/proc/cpuinfo');
- $memInfo = file_get_contents('/proc/meminfo');
- $stat = file_get_contents('/proc/stat');
$uptime = file_get_contents('/proc/uptime');
$cpuCount = preg_match_all('/\bprocessor\s/', $cpuInfo, $out);
//$cpuCount = count($out);
@@ -171,23 +186,38 @@ class Page_SystemStatus extends Page
if (preg_match('/^(\d+)\D/', $uptime, $out)) {
$data['uptime'] = floor($out[1] / 86400) . ' ' . Dictionary::translate('lang_days') . ', ' . floor(($out[1] % 86400) / 3600) . ' ' . Dictionary::translate('lang_hours'); // TODO: i18n
}
- if (preg_match('/\bMemTotal:\s+(\d+)\s.*\bMemFree:\s+(\d+)\s.*\bBuffers:\s+(\d+)\s.*\bCached:\s+(\d+)\s.*\bSwapTotal:\s+(\d+)\s.*\bSwapFree:\s+(\d+)\s/s', $memInfo, $out)) {
- $data['memTotal'] = Util::readableFileSize($out[1] * 1024);
- $data['memFree'] = Util::readableFileSize(($out[2] + $out[3] + $out[4]) * 1024);
- $data['memPercent'] = 100 - round((($out[2] + $out[3] + $out[4]) / $out[1]) * 100);
- $data['swapTotal'] = Util::readableFileSize($out[5] * 1024);
- $data['swapUsed'] = Util::readableFileSize(($out[5] - $out[6]) * 1024);
- $data['swapPercent'] = 100 - round(($out[6] / $out[5]) * 100);
- $data['swapWarning'] = ($data['swapPercent'] > 50 || ($out[5] - $out[6]) > 100000);
+ $info = $this->sysInfo();
+ if (isset($info['MemTotal']) && isset($info['MemFree']) && isset($info['SwapTotal'])) {
+ $data['memTotal'] = Util::readableFileSize($info['MemTotal'] * 1024);
+ $data['memFree'] = Util::readableFileSize(($info['MemFree'] + $info['Buffers'] + $info['Cached']) * 1024);
+ $data['memPercent'] = 100 - round((($info['MemFree'] + $info['Buffers'] + $info['Cached']) / $info['MemTotal']) * 100);
+ $data['swapTotal'] = Util::readableFileSize($info['SwapTotal'] * 1024);
+ $data['swapUsed'] = Util::readableFileSize(($info['SwapTotal'] - $info['SwapFree']) * 1024);
+ $data['swapPercent'] = 100 - round(($info['SwapFree'] / $info['SwapTotal']) * 100);
+ $data['swapWarning'] = ($data['swapPercent'] > 50 || ($info['SwapTotal'] - $info['SwapFree']) > 200000);
}
- if (preg_match('/\bcpu\s+(?<user>\d+)\s+(?<nice>\d+)\s+(?<system>\d+)\s+(?<idle>\d+)\s+(?<iowait>\d+)\s+(?<irq>\d+)\s+(?<softirq>\d+)(\s|$)/', $stat, $out)) {
- $total = $out['user'] + $out['nice'] + $out['system'] + $out['idle'] + $out['iowait'] + $out['irq'] + $out['softirq'];
- $data['cpuLoad'] = 100 - round(($out['idle'] / $total) * 100);
- $data['cpuSystem'] = round((($out['iowait'] + $out['irq'] + $out['softirq']) / $total) * 100);
+ if (isset($info['CpuIdle']) && isset($info['CpuSystem']) && isset($info['CpuTotal'])) {
+ $data['cpuLoad'] = 100 - round(($info['CpuIdle'] / $info['CpuTotal']) * 100);
+ $data['cpuSystem'] = round(($info['CpuSystem'] / $info['CpuTotal']) * 100);
$data['cpuLoadOk'] = true;
+ $data['CpuTotal'] = $info['CpuTotal'];
+ $data['CpuIdle'] = $info['CpuIdle'];
}
echo Render::parse('systemstatus/systeminfo', $data);
}
+
+ protected function ajaxSysPoll()
+ {
+ $info = $this->sysInfo();
+ $data = array(
+ 'CpuTotal' => $info['CpuTotal'],
+ 'CpuIdle' => $info['CpuIdle'],
+ 'MemPercent' => 100 - round((($info['MemFree'] + $info['Buffers'] + $info['Cached']) / $info['MemTotal']) * 100),
+ 'SwapPercent' => 100 - round(($info['SwapFree'] / $info['SwapTotal']) * 100)
+ );
+ Header('Content-Type: application/json; charset=utf-8');
+ die(json_encode($data));
+ }
protected function ajaxServices()
{
@@ -223,9 +253,51 @@ class Page_SystemStatus extends Page
echo 'Error reading from log file';
return;
}
+ // If we could read less, try the .1 file too
+ $amount = 6000 - strlen($data);
+ if ($amount > 100) {
+ $fh = @fopen('/var/log/dmsd.log.1', 'r');
+ if ($fh !== false) {
+ fseek($fh, -$amount, SEEK_END);
+ $data = fread($fh, $amount) . $data;
+ @fclose($fh);
+ }
+ }
echo '<pre>', htmlspecialchars(substr($data, strpos($data, "\n") + 1)), '</pre>';
}
+ protected function ajaxLdadpLog()
+ {
+ $files = glob('/opt/ldadp/logs/*.log', GLOB_NOSORT);
+ if ($files === false || empty($files)) echo('No logs found');
+ $now = time();
+ foreach ($files as $file) {
+ $mod = filemtime($file);
+ if ($now - $mod > 86400) continue;
+ // New enough - handle
+ preg_match(',/(\d+)\.log,', $file, $out);
+ $module = ConfigModule::get($out[1]);
+ if ($module === false) {
+ echo '<h4>Module ', $out[1], '</h4>';
+ } else {
+ echo '<h4>Module ', htmlspecialchars($module->title()), '</h4>';
+ }
+ $fh = @fopen($file, 'r');
+ if ($fh === false) {
+ echo '<pre>Error opening log file</pre>';
+ continue;
+ }
+ fseek($fh, -5000, SEEK_END);
+ $data = fread($fh, 5000);
+ @fclose($fh);
+ if ($data === false) {
+ echo '<pre>Error reading from log file</pre>';
+ continue;
+ }
+ echo '<pre>', htmlspecialchars(substr($data, strpos($data, "\n") + 1)), '</pre>';
+ }
+ }
+
protected function ajaxNetstat()
{
$taskId = Taskmanager::submit('Netstat');
diff --git a/templates/systemstatus/_page.html b/templates/systemstatus/_page.html
index 546a827b..bb48258c 100644
--- a/templates/systemstatus/_page.html
+++ b/templates/systemstatus/_page.html
@@ -89,6 +89,14 @@
</div>
<div class="panel panel-default">
<div class="panel-heading">
+ {{lang_ldadpLog}}
+ </div>
+ <div class="panel-body" id="ldadp-log">
+ <span class="glyphicon glyphicon-refresh slx-rotation"></span>
+ </div>
+</div>
+<div class="panel panel-default">
+ <div class="panel-heading">
netstat -tulpn
</div>
<div class="panel-body" id="netstat">
@@ -109,10 +117,11 @@
loadContent('#addresses', '?do=SystemStatus&action=AddressList');
loadContent('#systeminfo', '?do=SystemStatus&action=SystemInfo');
loadContent('#services', '?do=SystemStatus&action=Services');
+ loadContent('#dmsd-users', '?do=SystemStatus&action=DmsdUsers');
setTimeout(function() {
loadContent('#dmsd-log', '?do=SystemStatus&action=DmsdLog');
loadContent('#netstat', '?do=SystemStatus&action=Netstat');
loadContent('#pslist', '?do=SystemStatus&action=PsList');
- loadContent('#dmsd-users', '?do=SystemStatus&action=DmsdUsers');
+ loadContent('#ldadp-log', '?do=SystemStatus&action=LdadpLog');
}, 500);
</script>
diff --git a/templates/systemstatus/systeminfo.html b/templates/systemstatus/systeminfo.html
index 11076d52..ed4a1532 100644
--- a/templates/systemstatus/systeminfo.html
+++ b/templates/systemstatus/systeminfo.html
@@ -49,7 +49,7 @@
<script type="text/javascript">
{{#cpuLoadOk}}
- Circles.create({
+ var cpuCircle = Circles.create({
id: 'circles-cpuload',
radius: 60,
value: {{{cpuLoad}}},
@@ -61,9 +61,12 @@
wrpClass: 'circles-wrp',
textClass: 'circles-text'
});
+ var lastCpuTotal = {{CpuTotal}};
+ var lastCpuIdle = {{CpuIdle}};
+ var lastCpuPercent = {{cpuLoad}};
{{/cpuLoadOk}}
{{#memTotal}}
- Circles.create({
+ var memCircle = Circles.create({
id: 'circles-mem',
radius: 60,
value: {{{memPercent}}},
@@ -75,7 +78,7 @@
wrpClass: 'circles-wrp',
textClass: 'circles-text'
});
- Circles.create({
+ var swapCircle = Circles.create({
id: 'circles-swap',
radius: 60,
value: {{{swapPercent}}},
@@ -88,4 +91,25 @@
textClass: 'circles-text'
});
{{/memTotal}}
+ function updateSystem() {
+ if (!cpuCircle && !memCircle) return;
+ $.post('?do=SystemStatus&action=SysPoll', { token: TOKEN }, function(data) {
+ if (memCircle && data.MemPercent) memCircle.update(data.MemPercent);
+ if (swapCircle && data.SwapPercent) swapCircle.update(data.SwapPercent);
+ if (cpuCircle && data.CpuIdle) {
+ var total = data.CpuTotal - lastCpuTotal;
+ var load = total - (data.CpuIdle - lastCpuIdle);
+ var percent = Math.round(100 * load / total);
+ cpuCircle.update(percent, Math.abs(percent - lastCpuPercent) < 5 ? 0 : 250);
+ lastCpuTotal = data.CpuTotal;
+ lastCpuIdle = data.CpuIdle;
+ lastCpuPercent = percent;
+ }
+ }, 'json').fail(function(data) {
+ console.log(data);
+ }).always(function() {
+ setTimeout(updateSystem, 1200);
+ });
+ }
+ setTimeout(updateSystem, 1000);
</script>