Changeset 522 for trunk/admin

Show
Ignore:
Timestamp:
02/17/2008 04:49:46 PM (11 months ago)
Author:
moo
Message:

slide hits per second and hour

Location:
trunk/admin
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/common-zh-simplified-utf-8.lang.php

    r521 r522  
    2828        'Hits' 
    2929        => '命中', 
     30        'Hits 24H' 
     31        => '24H 分布', 
     32        'Hits/H' 
     33        => '命中/H', 
     34        'Hits/S' 
     35        => '命中/S', 
    3036        'Misses' 
    3137        => '错过', 
  • trunk/admin/common-zh-traditional-utf-8.lang.php

    r521 r522  
    2828        'Hits' 
    2929        => '命中', 
     30        'Hits 24H' 
     31        => '24H 分布', 
     32        'Hits/H' 
     33        => '命中/H', 
     34        'Hits/S' 
     35        => '命中/S', 
    3036        'Misses' 
    3137        => '錯過', 
  • trunk/admin/help-en.lang.php

    r458 r522  
    88<dt><?php echo _T('Compiling'); ?>: </dt><dd>Compiling flag, "yes" if the cache is busy compiling php script</dd> 
    99<dt><?php echo _T('Hits'); ?>: </dt><dd>Cache Hits, hit=a var/php is loaded from this cache</dd> 
     10<dt><?php echo _T('Hits/H'); ?>: </dt><dd>Average Hits per Hour. Only last 24 hours is logged</dd> 
     11<dt><?php echo _T('Hits 24H'); ?>: </dt><dd>Hits 24 Hours. Hits graph of last 24 hours</dd> 
     12<dt><?php echo _T('Hits/S'); ?>: </dt><dd>Average Hits per Second. Only last 5 seconds is logged</dd> 
    1013<dt><?php echo _T('Misses'); ?>: </dt><dd>Cache Misses, miss=a var/php is requested but not in the cache</dd> 
    1114<dt><?php echo _T('Clogs'); ?>: </dt><dd>Compiling Clogs, clog=compiling is needed but avoided to wait(be blocked) when the cache is busy compiling already</dd> 
  • trunk/admin/help-zh-simplified-utf-8.lang.php

    r458 r522  
    88<dt><?php echo _T('Compiling'); ?>: </dt><dd>编译标记, 当共享内存区正在编译 php 脚本时标记为 "yes"</dd> 
    99<dt><?php echo _T('Hits'); ?>: </dt><dd>共享内存命中次数, 命中=从该共享内存载入php或者变量</dd> 
     10<dt><?php echo _T('Hits/H'); ?>: </dt><dd>每小时命中次数. 只统计最后 24 小时</dd> 
     11<dt><?php echo _T('Hits 24H'); ?>: </dt><dd>24 小时命中分布图. 图表现是最后 24 小时的命中次数</dd> 
     12<dt><?php echo _T('Hits/S'); ?>: </dt><dd>每秒命中次数. 只统计最后 5 秒</dd> 
    1013<dt><?php echo _T('Misses'); ?>: </dt><dd>共享内存错过次数, 错过=请求的php或者变量并不在该共享内存内</dd> 
    1114<dt><?php echo _T('Clogs'); ?>: </dt><dd>编译阻塞跳过, 阻塞=当需该共享内存区负责编译时, 其他进程/现成无法访问此共享内存. 跳过=XCache 自动判断阻塞的共享内存区自动跳过阻塞等待, 直接使用非共享内存方式继续处理请求</dd> 
  • trunk/admin/xcache.css

    r521 r522  
    2828.freeblockgraph { border: 1px solid gray; border-bottom: 0px; } 
    2929 
     30.hitsgraph { height: 20px; border: solid gray; border-width: 1px 0 1px 0; margin: auto; } 
     31.hitsgraph div { float: left; width: 2px; height: 100%; } 
     32.bitsgraph div div { float: none; width: 100%; } 
     33 
    3034.switcher, h1, h2 { text-align: center; display: block; } 
    3135.switcher * { color: blue; } 
  • trunk/admin/xcache.php

    r521 r522  
    110110        $b = $c; 
    111111        $html[] = '<div style="background: rgb(' . "$r,$g,$b" . ')"></div>'; 
     112    } 
     113    return implode('', $html); 
     114} 
     115 
     116function calc_total(&$total, $data) 
     117{ 
     118    foreach ($data as $k => $v) { 
     119        switch ($k) { 
     120        case 'type': 
     121        case 'cache_name': 
     122        case 'cacheid': 
     123        case 'free_blocks': 
     124            continue 2; 
     125        } 
     126        if (!isset($total[$k])) { 
     127            $total[$k] = $v; 
     128        } 
     129        else { 
     130            switch ($k) { 
     131            case 'his_by_hour': 
     132            case 'his_by_second': 
     133                foreach ($data[$k] as $kk => $vv) { 
     134                    $total[$k][$kk] += $vv; 
     135                } 
     136                break; 
     137 
     138            default: 
     139                $total[$k] += $v; 
     140            } 
     141        } 
     142    } 
     143} 
     144 
     145function array_avg($a) 
     146{ 
     147    if (count($a) == 0) { 
     148        return ''; 
     149    } 
     150    return array_sum($a) / count($a); 
     151} 
     152 
     153function bar_percent($percent) 
     154{ 
     155    $r = 220 + (int) ($percent * 25); 
     156    $g = $b = 220 - (int) ($percent * 220); 
     157    $percent = (int) ($percent * 100); 
     158    return '<div>' 
     159        . '<div style="height: ' . (100 - $percent) . '%"></div>' 
     160        . '<div style="background: rgb(' . "$r,$g,$b" . '); height: ' . $percent . '%"></div>' 
     161        . '</div>'; 
     162} 
     163 
     164function hits_to_graph($hits) 
     165{ 
     166    $max = 0; 
     167    foreach ($hits as $v) { 
     168        if ($max < $v) { 
     169            $max = $v; 
     170        } 
     171    } 
     172    if (!$max) { 
     173        return ''; 
     174    } 
     175    $html = array(); 
     176    foreach ($hits as $v) { 
     177        $html[] = bar_percent($v / $max); 
    112178    } 
    113179    return implode('', $html); 
     
    196262    $cacheinfos[] = $data; 
    197263    if ($pcnt >= 2) { 
    198         foreach ($data as $k => $v) { 
    199             switch ($k) { 
    200             case 'type': 
    201             case 'cache_name': 
    202             case 'cacheid': 
    203             case 'free_blocks': 
    204                 continue 2; 
    205             } 
    206             if (!isset($total[$k])) { 
    207                 $total[$k] = $v; 
    208             } 
    209             else { 
    210                 $total[$k] += $v; 
    211             } 
    212         } 
     264        calc_total($total, $data); 
    213265    } 
    214266} 
     
    234286    $cacheinfos[] = $data; 
    235287    if ($pcnt >= 2) { 
    236         foreach ($data as $k => $v) { 
    237             switch ($k) { 
    238             case 'type': 
    239             case 'cache_name': 
    240             case 'cacheid': 
    241             case 'free_blocks': 
    242             case 'gc': 
    243                 continue 2; 
    244             } 
    245             if (!isset($total[$k])) { 
    246                 $total[$k] = $v; 
    247             } 
    248             else { 
    249                 $total[$k] += $v; 
    250             } 
    251         } 
     288        calc_total($total, $data); 
    252289    } 
    253290} 
  • trunk/admin/xcache.tpl.php

    r521 r522  
    1717    <col align="right" /> 
    1818    <col align="right" /> 
     19    <col /> 
     20    <col align="right" /> 
     21    <col align="right" /> 
    1922    <col align="right" /> 
    2023    <col align="right" /> 
     
    3235        <th><?php echo _T('Compiling'); ?></th> 
    3336        <th><?php echo _T('Hits'); ?></th> 
     37        <th><?php echo _T('Hits/H'); ?></th> 
     38        <th><?php echo _T('Hits 24H'); ?></th> 
     39        <th><?php echo _T('Hits/S'); ?></th> 
    3440        <th><?php echo _T('Misses'); ?></th> 
    3541        <th><?php echo _T('Clogs'); ?></th> 
     
    6571        $ci_avail = size($ci['avail']); 
    6672        $ci = number_formats($ci, $numkeys); 
     73 
     74        $hits_avg_h     = number_format(array_avg($ci['hits_by_hour']), 2); 
     75        $hits_avg_s     = number_format(array_avg($ci['hits_by_second']), 2); 
     76        $hits_graph_h   = hits_to_graph($ci['hits_by_hour']); 
     77        $hits_graph_h_w = count($ci['hits_by_hour']) * 2; 
     78 
    6779        if (!empty($ci['istotal'])) { 
    6880            $ci['compiling']    = '-'; 
     
    95107        <td>{$ci['compiling']}</td> 
    96108        <td>{$ci['hits']}</td> 
     109        <td>{$hits_avg_h}</td> 
     110        <td><div class="hitsgraph" style="width: {$hits_graph_h_w}px">{$hits_graph_h}</div></td> 
     111        <td>{$hits_avg_s}</td> 
    97112        <td>{$ci['misses']}</td> 
    98113        <td>{$ci['clogs']}</td>