Browse Source

show free blocks as graph

git-svn-id: svn://svn.lighttpd.net/xcache/trunk@517 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
3.0
Xuefer 14 years ago
parent
commit
4f92e56498
  1. 3
      admin/common.php
  2. 3
      admin/config.php.example
  3. 12
      admin/xcache.css
  4. 33
      admin/xcache.php
  5. 38
      admin/xcache.tpl.php

3
admin/common.php

@ -108,5 +108,8 @@ include(get_language_file("common"));
if (!isset($lang)) {
$lang = 'en-us';
}
if (!isset($free_graph_width)) {
$free_graph_width = 120;
}
?>

3
admin/config.php.example

@ -11,6 +11,9 @@ $charset = "UTF-8";
// developers only
$show_todo_strings = false;
// width of graph for free blocks
$free_graph_width = 120;
// this function is detected by xcache.tpl.php, and enabled if function_exists
// this ob filter is applied for the cache list, not the whole page
function ob_filter_path_nicer($o)

12
admin/xcache.css

@ -19,9 +19,15 @@ span.sortarrow { color: white; text-decoration: none; }
.freeblocks { float: left; margin-right: 4px;}
.freeblocks td { text-align: right; }
form {margin: 0; padding: 0}
.percent { border: 1px solid black; width: 80%; height: 20px; }
.percent div { font-size: 1px; line-height: 1px; width: 100%;}
.percent .pavail { background: blue; }
.percent { height: 3px; margin-bottom: 1px; background: gray; border: 1px solid gray; border-top: 0px; border-bottom: 0px; }
.percent div { float: left; height: 100%; }
.percent .pavail { background: green; }
.usagegraph { height: 16px; }
.usagegraph div { float: left; height: 3px; width: 4px; border: solid gray; border-width: 0 0px 1px 0; }
.usagegraph { border: 1px solid gray; border-bottom: 0px; }
.switcher, h1, h2 { text-align: center; display: block; }
.switcher * { color: blue; }
.switcher a.active { font-weight: bold; font-size: 130%; color: black; }

33
admin/xcache.php

@ -74,6 +74,39 @@ function age($time)
return '0 s';
}
function freeblock_to_graph($freeblocks, $size)
{
global $free_graph_width;
// cached in static variable
static $graph_initial;
if (!isset($graph_initial)) {
for ($i = 0; $i < $free_graph_width; $i ++) {
$graph_initial[$i] = 0;
}
}
$graph = $graph_initial;
foreach ($freeblocks as $b) {
$begin = $b['offset'] / $size * $free_graph_width;
$end = ($b['offset'] + $b['size']) / $size * $free_graph_width;
$graph[(int) $begin] += 1 - ($begin - (int) $begin);
$graph[(int) $end] += ($end - (int) $end);
for ($i = (int) $begin + 1, $e = (int) $end; $i < $e; $i ++) {
$graph[$i] = 1;
}
}
$html = array();
$c = 255;
foreach ($graph as $k => $v) {
$v = (int) ($v * $c);
$r = $g = $c - $v;
$b = $c;
$html[] = '<div style="background: rgb(' . "$r,$g,$b" . ')"></div>';
}
return implode('', $html);
}
function switcher($name, $options)
{
$n = isset($_GET[$name]) ? $_GET[$name] : null;

38
admin/xcache.tpl.php

@ -50,6 +50,10 @@ $b = new Cycle('class="col1"', 'class="col2"');
$pavail = (int) ($ci['avail'] / $ci['size'] * 100);
$pused = 100 - $pavail;
$graph = freeblock_to_graph($ci['free_blocks'], $ci['size']);
$w = $free_graph_width;
$tdwidth = $w + 2;
$ci_slots = size($ci['slots']);
$ci_size = size($ci['size']);
$ci_avail = size($ci['avail']);
@ -61,7 +65,13 @@ $b = new Cycle('class="col1"', 'class="col2"');
<td title="{$ci['slots']}">{$ci_slots}</td>
<td title="{$ci['size']}">{$ci_size}</td>
<td title="{$ci['avail']}">{$ci_avail}</td>
<td title="{$pavail} %"><div class="percent"><div style="height: {$pused}%" class="pused">&nbsp;</div><div style="height: {$pavail}%" class="pavail">&nbsp;</div></div></td>
<td title="{$pavail} %" width="{$tdwidth}"
><div class="percent" style="width: {$w}px"
><div style="width: {$pavail}%" class="pavail"></div
><div style="width: {$pused}%" class="pused"></div
></div
><div class="usagegraph" style="width: {$w}px">{$graph}</div
></td>
<td>
<form method="post">
<div>
@ -88,32 +98,6 @@ EOS;
</tr>
<?php } ?>
</table>
<div>
<?php echo _T('Free Blocks'); ?>:
</div>
<?php
foreach ($cacheinfos as $i => $ci) {
$b->reset();
?>
<table cellspacing="0" cellpadding="4" class="cycles freeblocks">
<tr>
<th><?php echo $ci['cache_name']; ?> <?php echo _T("size"); ?><br><?php echo _T("offset"); ?></th>
<?php
foreach ($ci['free_blocks'] as $block) {
$size = size($block['size']);
$offset = size($block['offset']);
$c = $b->next();
echo "
<td $c><nobr>$size<br>$offset</nobr></td>";
}
?>
</tr>
</table>
<?php
}
?>
<div style="clear: both">&nbsp;</div>
<?php

Loading…
Cancel
Save