diff options
-rw-r--r-- | modules/systemstatus.inc.php | 128 | ||||
-rw-r--r-- | style/default.css | 4 | ||||
-rw-r--r-- | templates/systemstatus/_page.html | 60 | ||||
-rw-r--r-- | templates/systemstatus/addresses.html | 8 | ||||
-rw-r--r-- | templates/systemstatus/diskstat.html | 2 | ||||
-rw-r--r-- | templates/systemstatus/services.html | 6 | ||||
-rw-r--r-- | templates/systemstatus/systeminfo.html | 90 |
7 files changed, 284 insertions, 14 deletions
diff --git a/modules/systemstatus.inc.php b/modules/systemstatus.inc.php index c6d45812..5c670bcb 100644 --- a/modules/systemstatus.inc.php +++ b/modules/systemstatus.inc.php @@ -36,7 +36,7 @@ class Page_SystemStatus extends Page protected function ajaxDiskStat() { $task = Taskmanager::submit('DiskStat'); - $task = Taskmanager::waitComplete($task); + $task = Taskmanager::waitComplete($task, 3000); if (!isset($task['data']['list']) || empty($task['data']['list'])) { Taskmanager::addErrorMessage($task); @@ -50,26 +50,136 @@ class Page_SystemStatus extends Page if ($store === '<local>') $storePoint = '/'; else - $storePoint = '/srv/openslx/nfs'; + $storePoint = CONFIG_VMSTORE_DIR; + // Determine free space foreach ($task['data']['list'] as $entry) { - if ($entry['mountPoint'] === $storePoint) + if ($entry['mountPoint'] === $storePoint) { $storeUsage = array( 'percent' => $entry['usedPercent'], - 'size' => Util::readableFileSize ($entry['sizeKb'] * 1024), - 'color' => dechex(round(($entry['usedPercent'] / 100) * 15)) . dechex(round(((100 - $entry['usedPercent']) / 100) * 15)) . '4' + 'size' => Util::readableFileSize($entry['sizeKb'] * 1024), + 'color' => $this->usageColor($entry['usedPercent']) ); - if ($entry['mountPoint'] === '/') + } + if ($entry['mountPoint'] === '/') { $systemUsage = array( 'percent' => $entry['usedPercent'], - 'size' => Util::readableFileSize ($entry['sizeKb'] * 1024), - 'color' => dechex(round(($entry['usedPercent'] / 100) * 15)) . dechex(round(((100 - $entry['usedPercent']) / 100) * 15)) . '4' + 'size' => Util::readableFileSize($entry['sizeKb'] * 1024), + 'color' => $this->usageColor($entry['usedPercent']) ); + } + } + // Determine if proper vm store is being used + if ($store === '<local>') + $storeError = false; + else + $storeError = 'VM-Store nicht eingebunden! Erwartet: ' . $store; + foreach ($task['data']['list'] as $entry) { + if ($entry['mountPoint'] === CONFIG_VMSTORE_DIR && $store !== $entry['fileSystem']) { + $storeError = 'Falscher VM-Store eingebunden! Erwartet: ' . $store . ' vorgefunden: ' . $entry['fileSystem']; + break; + } elseif ($entry['mountPoint'] === CONFIG_VMSTORE_DIR) { + $storeError = false; + } } } echo Render::parse('systemstatus/diskstat', array( 'store' => $storeUsage, - 'system' => $systemUsage + 'system' => $systemUsage, + 'storeError' => $storeError )); } + protected function ajaxAddressList() + { + $task = Taskmanager::submit('LocalAddressesList'); + $task = Taskmanager::waitComplete($task, 3000); + + if (!isset($task['data']['addresses']) || empty($task['data']['addresses'])) { + Taskmanager::addErrorMessage($task); + Message::renderList(); + return; + } + + $sort = array(); + $primary = Property::getServerIp(); + foreach ($task['data']['addresses'] as &$addr) { + $sort[] = $addr['type'] . $addr['ip']; + if ($addr['ip'] === $primary) + $addr['primary'] = true; + } + array_multisort($sort, SORT_STRING, $task['data']['addresses']); + echo Render::parse('systemstatus/addresses', array( + 'addresses' => $task['data']['addresses'] + )); + } + + protected function ajaxSystemInfo() + { + $cpuInfo = file_get_contents('/proc/cpuinfo'); + $memInfo = file_get_contents('/proc/meminfo'); + $stat = file_get_contents('/proc/stat'); + $cpuCount = preg_match_all('/\bprocessor\s/', $cpuInfo, $out); + //$cpuCount = count($out); + $data = array( + 'cpuCount' => $cpuCount, + 'memTotal' => '???', + 'memFree' => '???', + 'swapTotal' => '???', + 'swapUsed' => '???', + ); + 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); + } + 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); + } + echo Render::parse('systemstatus/systeminfo', $data); + } + + protected function ajaxServices() + { + $data = array(); + + $taskId = Trigger::ldadp(); + $status = Taskmanager::waitComplete($taskId, 10000); + + if (Taskmanager::isFailed($status)) { + if (isset($status['data']['messages'])) + $data['ldadpError'] = $status['data']['messages']; + else + $data['ldadpError'] = print_r($status, true); //'Taskmanager error'; + } + // TODO: Dozentenmodul, tftp, ... + + echo Render::parse('systemstatus/services', $data); + } + + private function usageColor($percent) + { + if ($percent <= 50) { + $r = $b = $percent / 3; + $g = (100 - $percent * (50 / 80)); + } elseif ($percent <= 70) { + $r = 55 + ($percent - 50) * (30 / 20); + $g = 60; + $b = 0; + } else { + $r = ($percent - 70) / 3 + 90; + $g = (100 - $percent) * (60 / 30); + $b = 0; + } + $r = dechex(round($r * 2.55)); + $g = dechex(round($g * 2.55)); + $b = dechex(round($b * 2.55)); + return sprintf("%02s%02s%02s", $r, $g, $b); + } + } diff --git a/style/default.css b/style/default.css index 1cac5ee7..e6104b8f 100644 --- a/style/default.css +++ b/style/default.css @@ -111,3 +111,7 @@ body { float: left; background-color: #eee; } + +.slx-bold { + font-weight: bold; +}
\ No newline at end of file diff --git a/templates/systemstatus/_page.html b/templates/systemstatus/_page.html index 5b1ab375..a62534da 100644 --- a/templates/systemstatus/_page.html +++ b/templates/systemstatus/_page.html @@ -1,13 +1,63 @@ <div class="container"> - <div class="panel panel-default"> - <div class="panel-heading"> - Speicherplatz + + <div class="row"> + + <div class="col-md-6"> + <div class="panel panel-default"> + <div class="panel-heading"> + Speicherplatz + </div> + <div class="panel-body" id="diskstat"> + *dreh dreh dreh dreh* + </div> + </div> </div> - <div class="panel-body" id="diskstat"> - *dreh dreh dreh dreh* + + <div class="col-md-6"> + <div class="panel panel-default"> + <div class="panel-heading"> + Dienste + </div> + <div class="panel-body" id="services"> + *dreh dreh dreh dreh* + </div> + </div> </div> + </div> + + + <div class="row"> + + <div class="col-md-6"> + <div class="panel panel-default"> + <div class="panel-heading"> + Adresskonfiguration + </div> + <div class="panel-body" id="addresses"> + *dreh dreh dreh dreh* + </div> + </div> + </div> + + <div class="col-md-6"> + <div class="panel panel-default"> + <div class="panel-heading"> + Systemlast + </div> + <div class="panel-body" id="systeminfo"> + *dreh dreh dreh dreh* + </div> + </div> + </div> + + </div> + </div> + <script type="text/javascript"> loadContent('#diskstat', '?do=SystemStatus&action=DiskStat'); + loadContent('#addresses', '?do=SystemStatus&action=AddressList'); + loadContent('#systeminfo', '?do=SystemStatus&action=SystemInfo'); + loadContent('#services', '?do=SystemStatus&action=Services'); </script> diff --git a/templates/systemstatus/addresses.html b/templates/systemstatus/addresses.html new file mode 100644 index 00000000..ce92c4d5 --- /dev/null +++ b/templates/systemstatus/addresses.html @@ -0,0 +1,8 @@ +<table class="slx-table"> + {{#addresses}} + <tr {{#primary}} class="slx-bold" {{/primary}}> + <td>{{ip}}</td> + <td>({{iface}})</td> + </tr> + {{/addresses}} +</table>
\ No newline at end of file diff --git a/templates/systemstatus/diskstat.html b/templates/systemstatus/diskstat.html index e1d4a57e..02487c0d 100644 --- a/templates/systemstatus/diskstat.html +++ b/templates/systemstatus/diskstat.html @@ -18,6 +18,8 @@ <b>Fehler beim Ermitteln des verfügbaren Speicherplatzes am VM-Speicherort. Bitte überprüfen Sie die Konfiguration.</b> {{/store}} </div> +<div class="clearfix"></div> +<div>{{storeError}}</div> <script type="text/javascript"> {{#store}} Circles.create({ diff --git a/templates/systemstatus/services.html b/templates/systemstatus/services.html new file mode 100644 index 00000000..6c4f0b93 --- /dev/null +++ b/templates/systemstatus/services.html @@ -0,0 +1,6 @@ +{{#ldadpError}} +<pre>{{ldadpError}}</pre> +{{/ldadpError}} +{{^ldadpError}} +<div class="alert alert-success">LDAP-AD-Proxy: OK</div> +{{/ldadpError}} diff --git a/templates/systemstatus/systeminfo.html b/templates/systemstatus/systeminfo.html new file mode 100644 index 00000000..86aefe8f --- /dev/null +++ b/templates/systemstatus/systeminfo.html @@ -0,0 +1,90 @@ +<div class="slx-storechart"> + <b>CPU-Last</b> + {{#cpuLoad}} + <div id="circles-cpuload"></div> + <div>Durchschnitt: {{cpuLoad}}%</div> + <div>Nur OS: {{cpuSystem}}%</div> + <div>Logische CPUs: {{cpuCount}}</div> + {{/cpuLoad}} + {{^cpuLoad}} + Konnte nicht ermittelt werden + {{/cpuLoad}} +</div> + +<div class="slx-storechart"> + <b>RAM-Nutzung</b> + {{#memPercent}} + <div id="circles-mem"></div> + <div>Gesamt: {{memTotal}}</div> + <div>Frei: {{memFree}}</div> + {{/memPercent}} + {{^memPercent}} + Konnte nicht ermittelt werden + {{/memPercent}} +</div> + +<div class="slx-storechart"> + <b>swap-Nutzung</b> + {{#swapPercent}} + <div id="circles-swap"></div> + <div>Gesamt: {{swapTotal}}</div> + <div>Belegt: {{swapUsed}}</div> + {{/swapPercent}} + {{^swapPercent}} + Konnte nicht ermittelt werden + {{/swapPercent}} +</div> + +<div class="clearfix"></div> + +{{#swapWarning}} +<div> + <b>Achtung!</b> Es wird swap-Speicher genutzt. Dies kann ein Hinweis darauf sein, dass der Satelliten-Server zu wenig physikalischen Speicher zur Verfügung hat. Im Falle von + Performance-Problemen oder Instabilität des Server sollten Sie erwägen, den Server mit mehr RAM auszustatten. +</div> +{{/swapWarning}} + +<script type="text/javascript"> + {{#cpuLoad}} + Circles.create({ + id: 'circles-cpuload', + radius: 60, + value: {{{cpuLoad}}}, + maxValue: 100, + width: 10, + text: function(value){return value + '%'; }, + colors: ['#dbc', '#33f'], + duration: 400, + wrpClass: 'circles-wrp', + textClass: 'circles-text' + }); + {{/cpuLoad}} + {{#memPercent}} + Circles.create({ + id: 'circles-mem', + radius: 60, + value: {{{memPercent}}}, + maxValue: 100, + width: 10, + text: function(value){return value + '%'; }, + colors: ['#dbc', '#33f'], + duration: 400, + wrpClass: 'circles-wrp', + textClass: 'circles-text' + }); + {{/memPercent}} + {{#swapPercent}} + Circles.create({ + id: 'circles-swap', + radius: 60, + value: {{{swapPercent}}}, + maxValue: 100, + width: 10, + text: function(value){return value + '%'; }, + colors: ['#dbc', '#f33'], + duration: 400, + wrpClass: 'circles-wrp', + textClass: 'circles-text' + }); + {{/swapPercent}} +</script>
\ No newline at end of file |