Skip to content
Snippets Groups Projects
Commit cdf3541a authored by Tim van Dijen's avatar Tim van Dijen
Browse files

memcacheMonitor: Add Twig template

parent d2ba28ea
No related branches found
No related tags found
No related merge requests found
{% set pagetitle = 'SimpleSAMLphp Memcache Monitor'|trans %}
{% extends "base.twig" %}
{% block preload %}
<link href="{{ baseurlpath }}style.css" rel="stylesheet" />
{% endblock %}
{% block content %}
<h2>{{ title }}</h2>
<table class="statustable">
<tr>
<th>&nbsp;</th>
{% for key, title in colTitles %}
<th>{{ title|escape('html') }}</th>
{% endfor %}
</tr>
{% for rowTitle, rowData in table %}
<tr>
<th class="rowtitle" style="text-align: right">{{ rowTitles[rowTitle]|trans }}</th>
{% for key, colTitle in colTitles %}
{% if rowData[colTitle] is defined %}
<td>{{ rowData[colTitle]|escape('html') }}</td>
{% else %}
<td>&nbsp;</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
{% if usage is defined %}
{% for key, value in usage %}
<h3>Storage usage on [{{ key }}]</h3>
<div class="bmax" style="width: {{ maxpix }}">
<div class="bused" style="width: {{ usage[key] }}">Used: {{ table.bytes[key] }}</div>Total available: {{ table.limit_maxbytes[key] }}</div>
{% endfor %}
{% endif %}
{% endblock %}
...@@ -5,16 +5,17 @@ function tdate($input) { ...@@ -5,16 +5,17 @@ function tdate($input) {
} }
function hours($input) { function hours($input) {
if ($input < 60) return number_format($input, 2) . ' sec'; if ($input < 60) {
if ($input < 60*60) return number_format(($input/60),2) . ' min'; return number_format($input, 2) . ' sec';
if ($input < 24*60*60) return number_format(($input/(60*60)),2) . ' hours'; } else if ($input < 60*60) {
return number_format(($input/60),2) . ' min';
} else if ($input < 24*60*60) {
return number_format(($input/(60*60)),2) . ' hours';
}
return number_format($input/(24*60*60),2) . ' days'; return number_format($input/(24*60*60),2) . ' days';
} }
function humanreadable($input) { function humanreadable($input) {
$output = ""; $output = "";
$input = abs($input); $input = abs($input);
...@@ -24,44 +25,36 @@ function humanreadable($input) { ...@@ -24,44 +25,36 @@ function humanreadable($input) {
$output = sprintf("%5.1fEi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0*1024.0) ); $output = sprintf("%5.1fEi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*1024*1024*1024*1024)) { } else if ($input >= (1024*1024*1024*1024*1024*1024)) {
$output = sprintf("%5.2fEi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0*1024.0) ); $output = sprintf("%5.2fEi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*1024*1024*1024*100)) { } else if ($input >= (1024*1024*1024*1024*1024*100)) {
$output = sprintf("%5ldPi", $input / (1024*1024*1024*1024*1024) ); $output = sprintf("%5ldPi", $input / (1024*1024*1024*1024*1024) );
} else if ($input >= (1024*1024*1024*1024*1024*10)) { } else if ($input >= (1024*1024*1024*1024*1024*10)) {
$output = sprintf("%5.1fPi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0) ); $output = sprintf("%5.1fPi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*1024*1024*1024)) { } else if ($input >= (1024*1024*1024*1024*1024)) {
$output = sprintf("%5.2fPi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0) ); $output = sprintf("%5.2fPi", $input / (1024.0*1024.0*1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*1024*1024*100)) { } else if ($input >= (1024*1024*1024*1024*100)) {
$output = sprintf("%5ldTi", $input / (1024*1024*1024*1024) ); $output = sprintf("%5ldTi", $input / (1024*1024*1024*1024) );
} else if ($input >= (1024*1024*1024*1024*10)) { } else if ($input >= (1024*1024*1024*1024*10)) {
$output = sprintf("%5.1fTi", $input / (1024.0*1024.0*1024.0*1024.0) ); $output = sprintf("%5.1fTi", $input / (1024.0*1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*1024*1024)) { } else if ($input >= (1024*1024*1024*1024)) {
$output = sprintf("%5.2fTi", $input / (1024.0*1024.0*1024.0*1024.0) ); $output = sprintf("%5.2fTi", $input / (1024.0*1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*1024*100)) { } else if ($input >= (1024*1024*1024*100)) {
$output = sprintf("%5ldGi", $input / (1024*1024*1024) ); $output = sprintf("%5ldGi", $input / (1024*1024*1024) );
} else if ($input >= (1024*1024*1024*10)) { } else if ($input >= (1024*1024*1024*10)) {
$output = sprintf("%5.1fGi", $input / (1024.0*1024.0*1024.0) ); $output = sprintf("%5.1fGi", $input / (1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*1024)) { } else if ($input >= (1024*1024*1024)) {
$output = sprintf("%5.2fGi", $input / (1024.0*1024.0*1024.0) ); $output = sprintf("%5.2fGi", $input / (1024.0*1024.0*1024.0) );
} else if ($input >= (1024*1024*100)) { } else if ($input >= (1024*1024*100)) {
$output = sprintf("%5ldMi", $input / (1024*1024) ); $output = sprintf("%5ldMi", $input / (1024*1024) );
} else if ($input >= (1024*1024*10)) { } else if ($input >= (1024*1024*10)) {
$output = sprintf("%5.1fM", $input / (1024.0*1024.0) ); $output = sprintf("%5.1fM", $input / (1024.0*1024.0) );
} else if ($input >= (1024*1024)) { } else if ($input >= (1024*1024)) {
$output = sprintf("%5.2fMi", $input / (1024.0*1024.0) ); $output = sprintf("%5.2fMi", $input / (1024.0*1024.0) );
} else if ($input >= (1024 * 100)) { } else if ($input >= (1024 * 100)) {
$output = sprintf("%5ldKi", $input / (1024) ); $output = sprintf("%5ldKi", $input / (1024) );
} else if ($input >= (1024 * 10)) { } else if ($input >= (1024 * 10)) {
$output = sprintf("%5.1fKi", $input / 1024.0 ); $output = sprintf("%5.1fKi", $input / 1024.0 );
} else if ($input >= (1024)) { } else if ($input >= (1024)) {
$output = sprintf("%5.2fKi", $input / 1024.0 ); $output = sprintf("%5.2fKi", $input / 1024.0 );
} else { } else {
$output = sprintf("%5ld", $input ); $output = sprintf("%5ld", $input );
} }
...@@ -69,15 +62,11 @@ function humanreadable($input) { ...@@ -69,15 +62,11 @@ function humanreadable($input) {
return $output; return $output;
} }
$config = SimpleSAML_Configuration::getInstance(); $config = SimpleSAML_Configuration::getInstance();
// Make sure that the user has admin access rights // Make sure that the user has admin access rights
SimpleSAML\Utils\Auth::requireAdmin(); SimpleSAML\Utils\Auth::requireAdmin();
$formats = array( $formats = array(
'bytes' => 'humanreadable', 'bytes' => 'humanreadable',
'bytes_read' => 'humanreadable', 'bytes_read' => 'humanreadable',
...@@ -87,18 +76,16 @@ $formats = array( ...@@ -87,18 +76,16 @@ $formats = array(
'uptime' => 'hours', 'uptime' => 'hours',
); );
$statsraw = SimpleSAML_Memcache::getStats(); $statsRaw = SimpleSAML_Memcache::getStats();
$stats = $statsRaw;
$stats = $statsraw;
foreach($stats AS $key => &$entry) { foreach ($stats as $key => &$entry) {
if (array_key_exists($key, $formats)) { if (array_key_exists($key, $formats)) {
$func = $formats[$key]; $func = $formats[$key];
foreach($entry AS $k => $val) { foreach ($entry as $k => $val) {
$entry[$k] = $func($val); $entry[$k] = $func($val);
} }
} }
} }
$t = new SimpleSAML_XHTML_Template($config, 'memcacheMonitor:memcachestat.tpl.php'); $t = new SimpleSAML_XHTML_Template($config, 'memcacheMonitor:memcachestat.tpl.php');
...@@ -140,8 +127,30 @@ $rowTitles = array( ...@@ -140,8 +127,30 @@ $rowTitles = array(
'uptime' => $t->noop('{memcacheMonitor:memcachestat:uptime}'), 'uptime' => $t->noop('{memcacheMonitor:memcachestat:uptime}'),
'version' => $t->noop('{memcacheMonitor:memcachestat:version}'), 'version' => $t->noop('{memcacheMonitor:memcachestat:version}'),
); );
// Identify column headings
$colTitles = array();
foreach ($stats as $rowTitle => $rowData) {
foreach ($rowData as $colTitle => $foo) {
if (!in_array($colTitle, $colTitles, true)) {
$colTitles[] = $colTitle;
}
}
}
if (array_key_exists('bytes', $statsRaw) && array_key_exists('limit_maxbytes', $statsRaw)) {
$usage = array();
$maxpix = 400;
foreach ($statsRaw['bytes'] as $key => $row_data) {
$pix = floor($statsRaw['bytes'][$key] * $maxpix / $statsRaw['limit_maxbytes'][$key]);
$usage[$key] = $pix . 'px';
}
$t->data['maxpix'] = $maxpix . 'px';
$t->data['usage'] = $usage;
}
$t->data['title'] = 'Memcache stats'; $t->data['title'] = 'Memcache stats';
$t->data['rowtitles'] = $rowTitles; $t->data['rowTitles'] = $rowTitles;
$t->data['colTitles'] = $colTitles;
$t->data['table'] = $stats; $t->data['table'] = $stats;
$t->data['statsraw'] = $statsraw;
$t->show(); $t->show();
table.statustable td, table.statustable th {
border: 1px solid #eee;
padding: 2px 6px;
}
table.statustable {
border-collapse: collapse;
}
.bmax {
border: 1px solid #555;
background: #eee;
}
.bused {
border-right: 1px solid #555;
border-bottom: 1px solid #555;
color: white;
background: #833;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment