OPCache info page

This commit is contained in:
Janos Muzsi 2016-01-20 22:12:43 +01:00
parent 1ba2800a30
commit fb6393ad8f
6 changed files with 416 additions and 0 deletions

159
admin_opcacheinfo.php Normal file
View File

@ -0,0 +1,159 @@
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* For the full copyright and license information, please view the COPYING
* file that was distributed with this source code. You can also view the
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
*
* @copyright (c) the authors
* @author Janos Muzsi <muzsij@hypernics.hu> (2016)
* @author Froxlor team <team@froxlor.org> (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Panel
*
* Based on https://github.com/amnuts/opcache-gui
*
*/
define('AREA', 'admin');
require './lib/init.php';
if ($action == 'reset' &&
function_exists('opcache_reset') &&
$userinfo['change_serversettings'] == '1'
) {
opcache_reset();
$log->logAction(ADM_ACTION, LOG_INFO, "reseted OPcache");
header('Location: ' . $linker->getLink(array('section' => 'opcacheinfo', 'page' => 'showinfo')));
exit();
}
if (!function_exists('opcache_get_configuration')
) {
standard_error($lng['error']['no_opcacheinfo']);
exit();
}
if ($page == 'showinfo'
) {
$opcache_info = opcache_get_configuration();
$opcache_status = opcache_get_status(false);
$time = time();
$log->logAction(ADM_ACTION, LOG_NOTICE, "viewed OPcache info");
$runtimelines = '';
if (isset($opcache_info['directives']) && is_array($opcache_info['directives'])) {
foreach ($opcache_info['directives'] as $name => $value) {
$linkname= str_replace('_', '-', $name);
if ($name=='opcache.optimization_level' && is_integer($value)) {
$value='0x'.dechex($value);
}
if ($name=='opcache.memory_consumption' && is_integer($value) && $value%(1024*1024)==0) {
$value=$value/(1024*1024);
}
if ($value===null || $value==='') {
$value=$lng['opcacheinfo']['novalue'];
}
if ($value===true) {
$value=$lng['opcacheinfo']['true'];
}
if ($value===false) {
$value=$lng['opcacheinfo']['false'];
}
if (is_integer($value)) {
$value=number_format($value,0,'.',' ');
}
$name=str_replace('_', ' ', $name);
eval("\$runtimelines.=\"" . getTemplate("settings/opcacheinfo/runtime_line") . "\";");
}
}
$cachehits=@$opcache_status['opcache_statistics']['hits'] ?: 0;
$cachemiss=@$opcache_status['opcache_statistics']['misses'] ?: 0;
$blacklistmiss=@$opcache_status['opcache_statistics']['blacklist_misses'] ?: 0;
$cachetotal=$cachehits+$cachemiss+$blacklistmiss;
$general=array(
'version' => (isset($opcache_info['version']['opcache_product_name']) ? $opcache_info['version']['opcache_product_name'].' ' : '').$opcache_info['version']['version'],
'phpversion' => phpversion(),
'start_time' => @$opcache_status['opcache_statistics']['start_time'] ? date('Y-m-d H:i:s',$opcache_status['opcache_statistics']['start_time']) : '',
'last_restart_time' => @$opcache_status['opcache_statistics']['last_restart_time'] ? date('Y-m-d H:i:s',$opcache_status['opcache_statistics']['last_restart_time']) : $lng['opcacheinfo']['never'],
'oom_restarts' => number_format(@$opcache_status['opcache_statistics']['oom_restarts'] ?: 0,0,'.',' '),
'hash_restarts' => number_format(@$opcache_status['opcache_statistics']['hash_restarts'] ?: 0,0,'.',' '),
'manual_restarts' => number_format(@$opcache_status['opcache_statistics']['manual_restarts'] ?: 0,0,'.',' '),
'status' => (@$opcache_status['restart_in_progress'] ? $lng['opcacheinfo']['restartinprogress'] :
(@$opcache_status['restart_pending'] ? $lng['opcacheinfo']['restartpending'] :
(@$opcache_status['cache_full'] ? $lng['opcacheinfo']['cachefull'] :
(@$opcache_status['opcache_enabled'] ? $lng['opcacheinfo']['enabled'] : $lng['opcacheinfo']['novalue'])))),
'cachedscripts' => number_format(@$opcache_status['opcache_statistics']['num_cached_scripts'] ?: 0,0,'.',' '),
'cachehits' => number_format($cachehits,0,'.',' ') . ($cachetotal>0 ? sprintf(" (%.1f %%)", $cachehits/($cachetotal)*100) : ''),
'cachemiss' => number_format($cachemiss,0,'.',' ') . ($cachetotal>0 ? sprintf(" (%.1f %%)", $cachemiss/($cachetotal)*100) : ''),
'blacklistmiss' => number_format($blacklistmiss,0,'.',' ') . ($cachetotal>0 ? sprintf(" (%.1f %%)", $blacklistmiss/($cachetotal)*100) : ''),
);
$usedmem=@$opcache_status['memory_usage']['used_memory'] ?: 0;
$usedmemstr=bsize($usedmem);
$freemem=@$opcache_status['memory_usage']['free_memory'] ?: 0;
$freememstr=bsize($freemem);
$totalmem=$usedmem+$freemem;
$wastedmem=@$opcache_status['memory_usage']['wasted_memory'] ?: 0;
$wastedmemstr=bsize($wastedmem);
if ($totalmem) {
$memory=array(
'total' => bsize($totalmem),
'used' => $usedmemstr . ($totalmem>0 ? sprintf(" (%.1f %%)", $usedmem/($totalmem)*100) : ''),
'free' => $freememstr . ($totalmem>0 ? sprintf(" (%.1f %%)", $freemem/($totalmem)*100) : ''),
'wasted' => $wastedmemstr . ($totalmem>0 ? sprintf(" (%.1f %%)", $wastedmem/($totalmem)*100) : ''),
);
}
if (isset($opcache_status['interned_strings_usage'])) {
$usedstring=@$opcache_status['interned_strings_usage']['used_memory'] ?: 0;
$usedstringstr=bsize($usedstring);
$freestring=@$opcache_status['interned_strings_usage']['free_memory'] ?: 0;
$freestringstr=bsize($freestring);
$totalstring=$totalstring+$freestring;
$stringbuffer=array(
'total' => bsize($totalstring),
'used' => $usedstringstr . ($totalstring>0 ? sprintf(" (%.1f %%)", $usedstring/$totalstring*100) : ''),
'free' => $freestringstr . ($totalstring>0 ? sprintf(" (%.1f %%)", $freestring/$totalstring*100) : ''),
'strcount' => number_format(@$opcache_status['interned_strings_usage']['number_of_strings'] ?: 0,0,'.',' '),
);
}
$usedkey=@$opcache_status['opcache_statistics']['num_cached_keys'] ?: 0;
$usedkeystr=number_format($usedkey,0,'.',' ');
$totalkey=@$opcache_status['opcache_statistics']['max_cached_keys'] ?: 0;
$wastedkey=$usedkey - (@$opcache_status['opcache_statistics']['num_cached_scripts'] ?: 0);
if (isset($opcache_status['opcache_statistics'])) {
$keystat=array(
'total' => number_format($totalkey,0,'.',' '),
'used' => $usedkeystr . ($totalkey>0 ? sprintf(" (%.1f %%)", $usedkey/($totalkey)*100) : ''),
'wasted' => number_format($wastedkey,0,'.',' ') . ($totalkey>0 ? sprintf(" (%.1f %%)", $wastedkey/($totalkey)*100) : ''),
);
}
$blacklistlines = '';
if (isset($opcache_info['blacklist']) && is_array($opcache_info['blacklist'])) {
foreach ($opcache_info['blacklist'] as $value) {
eval("\$blacklistlines.=\"" . getTemplate("settings/opcacheinfo/blacklist_line") . "\";");
}
}
eval("echo \"" . getTemplate("settings/opcacheinfo/showinfo") . "\";");
}
function bsize($s) {
foreach (array('', 'K', 'M', 'G') as $i => $k) {
if ($s < 1024)
break;
$s/=1024;
}
return sprintf("%5.1f %sBytes", $s, $k);
}

View File

@ -223,6 +223,14 @@ return array (
function_exists('apcu_cache_info') === true
),
),
array (
'url' => 'admin_opcacheinfo.php?page=showinfo',
'label' => $lng['admin']['opcacheinfo'],
'required_resources' => 'change_serversettings',
'show_element' => (
function_exists('opcache_get_configuration') === true
),
),
array (
'url' => 'admin_ipsandports.php?page=ipsandports',
'label' => $lng['admin']['ipsandports']['ipsandports'],

View File

@ -1883,3 +1883,44 @@ $lng['apcuinfo']['used'] = 'Used';
$lng['apcuinfo']['hitmiss'] = 'Hits & Misses';
$lng['apcuinfo']['detailmem'] = 'Detailed Memory Usage and Fragmentation';
$lng['apcuinfo']['fragment'] = 'Fragmentation';
// Added for opcache info
$lng['admin']['opcacheinfo'] = 'OPcache info';
$lng['error']['no_opcacheinfo'] = 'No cache info available. OPCache does not appear to be running.';
$lng['opcacheinfo']['generaltitle'] = 'General Information';
$lng['opcacheinfo']['resetcache'] = 'Reset OPcache';
$lng['opcacheinfo']['version'] = 'OPCache version';
$lng['opcacheinfo']['phpversion'] = 'PHP version';
$lng['opcacheinfo']['runtimeconf'] = 'Runtime Configuration';
$lng['opcacheinfo']['start'] = 'Start time';
$lng['opcacheinfo']['lastreset'] = 'Last restart';
$lng['opcacheinfo']['oomrestarts'] = 'OOM restart count';
$lng['opcacheinfo']['hashrestarts'] = 'Hash restart count';
$lng['opcacheinfo']['manualrestarts'] = 'Manual restart count';
$lng['opcacheinfo']['hitsc'] = 'Hits count';
$lng['opcacheinfo']['missc'] = 'Miss count';
$lng['opcacheinfo']['blmissc'] = 'Blacklist miss count';
$lng['opcacheinfo']['status'] = 'Status';
$lng['opcacheinfo']['never'] = 'never';
$lng['opcacheinfo']['enabled'] = 'OPcache Enabled';
$lng['opcacheinfo']['cachefull'] = 'Cache full';
$lng['opcacheinfo']['restartpending'] = 'Pending restart';
$lng['opcacheinfo']['restartinprogress'] = 'Restart in progress';
$lng['opcacheinfo']['cachedscripts'] = 'Cached scripts count';
$lng['opcacheinfo']['memusage'] = 'Memory usage';
$lng['opcacheinfo']['totalmem'] = 'Total memory';
$lng['opcacheinfo']['usedmem'] = 'Used memory';
$lng['opcacheinfo']['freemem'] = 'Free memory';
$lng['opcacheinfo']['wastedmem'] = 'Wasted memory';
$lng['opcacheinfo']['maxkey'] = 'Maximum keys';
$lng['opcacheinfo']['usedkey'] = 'Used keys';
$lng['opcacheinfo']['wastedkey'] = 'Wasted keys';
$lng['opcacheinfo']['strinterning'] = 'String interning';
$lng['opcacheinfo']['strcount'] = 'String count';
$lng['opcacheinfo']['keystat'] = 'Cached keys statistic';
$lng['opcacheinfo']['used'] = 'Used';
$lng['opcacheinfo']['free'] = 'Free';
$lng['opcacheinfo']['blacklist'] = 'Blacklist';
$lng['opcacheinfo']['novalue'] = '<i>no value</i>';
$lng['opcacheinfo']['true'] = '<i>true</i>';
$lng['opcacheinfo']['false'] = '<i>false</i>';

View File

@ -0,0 +1,3 @@
<tr>
<td colspan="2">{$value}</td>
</tr>

View File

@ -0,0 +1,4 @@
<tr>
<td><a href="http://php.net/manual/en/opcache.configuration.php#ini.{$linkname}" target="_blank">{$name}</a></td>
<td>{$value}</td>
</tr>

View File

@ -0,0 +1,201 @@
$header
<article>
<header>
<h2>
<img src="templates/{$theme}/assets/img/icons/res_recalculate_big.png" alt="" />&nbsp;
{$lng['admin']['opcacheinfo']}
</h2>
</header>
<section>
<div>
<if ($totalmem) >
<div class="canvasbox">
<input type="hidden" id="usedmem" class="circular" data-used="{$usedmem}" data-available="{$totalmem}">
<canvas id="usedmem-canvas" width="120" height="76"></canvas><br />
{$lng['opcacheinfo']['memusage']}<br />
<small>
{$lng['opcacheinfo']['used']}: {$usedmemstr} <br />
{$lng['opcacheinfo']['free']}: {$freememstr}
</small>
</div>
<div class="canvasbox">
<input type="hidden" id="wastedmem" class="circular" data-used="{$wastedmem}" data-available="{$totalmem}">
<canvas id="wastedmem-canvas" width="120" height="76"></canvas><br />
{$lng['opcacheinfo']['wastedmem']}<br />
<small>
{$wastedmemstr}
</small>
</div>
</if>
<if (isset($stringbuffer)) >
<div class="canvasbox">
<input type="hidden" id="stringused" class="circular" data-used="{$usedstring}" data-available="{$totalstring}">
<canvas id="stringused-canvas" width="120" height="76"></canvas><br />
{$lng['opcacheinfo']['strinterning']}<br />
<small>
{$lng['opcacheinfo']['used']}: {$usedstringstr} <br />
{$lng['opcacheinfo']['free']}: {$freestringstr}
</small>
</div>
</if>
<if ($totalkey) >
<div class="canvasbox">
<input type="hidden" id="usedkeystat" class="circular" data-used="{$usedkey}" data-available="{$totalkey}">
<canvas id="usedkeystat-canvas" width="120" height="76"></canvas><br />
{$lng['opcacheinfo']['usedkey']}<br />
<small>
{$usedkeystr}
</small>
</div>
</if>
<if ($cachetotal) >
<div class="canvasbox">
<input type="hidden" id="cachehit" class="circular" data-used="{$cachehits}" data-available="{$cachetotal}">
<canvas id="cachehit-canvas" width="120" height="76"></canvas><br />
{$lng['opcacheinfo']['hitsc']}
</div>
</if>
</div>
<table class="full">
<tr class="section">
<th>{$lng['opcacheinfo']['generaltitle']}</th>
<th class="right">
<a href="{$linker->getLink(array('section' => 'opcacheinfo', 'page' => 'showinfo', 'action' => 'reset'))}">{$lng['opcacheinfo']['resetcache']}</a>
&nbsp;
</th>
</tr>
<tr>
<td>{$lng['opcacheinfo']['version']}</td>
<td>{$general['version']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['phpversion']}</td>
<td>{$general['phpversion']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['start']}</td>
<td>{$general['start_time']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['lastreset']}</td>
<td>{$general['last_restart_time']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['oomrestarts']}</td>
<td>{$general['oom_restarts']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['hashrestarts']}</td>
<td>{$general['hash_restarts']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['manualrestarts']}</td>
<td>{$general['manual_restarts']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['status']}</td>
<td>{$general['status']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['cachedscripts']}</td>
<td>{$general['cachedscripts']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['hitsc']}</td>
<td>{$general['cachehits']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['missc']}</td>
<td>{$general['cachemiss']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['blmissc']}</td>
<td>{$general['blacklistmiss']}</td>
</tr>
<if ($totalmem) >
<tr>
<th colspan="2">{$lng['opcacheinfo']['memusage']}</th>
</tr>
<tr>
<td>{$lng['opcacheinfo']['totalmem']}</td>
<td>{$memory['total']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['usedmem']}</td>
<td>{$memory['used']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['freemem']}</td>
<td>{$memory['free']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['wastedmem']}</td>
<td>{$memory['wasted']}</td>
</tr>
</if>
<if (isset($stringbuffer)) >
<tr>
<th colspan="2">{$lng['opcacheinfo']['strinterning']}</th>
</tr>
<tr>
<td>{$lng['opcacheinfo']['totalmem']}</td>
<td>{$stringbuffer['total']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['usedmem']}</td>
<td>{$stringbuffer['used']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['freemem']}</td>
<td>{$stringbuffer['free']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['strcount']}</td>
<td>{$stringbuffer['strcount']}</td>
</tr>
</if>
<if (isset($keystat)) >
<tr>
<th colspan="2">{$lng['opcacheinfo']['keystat']}</th>
</tr>
<tr>
<td>{$lng['opcacheinfo']['maxkey']}</td>
<td>{$keystat['total']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['usedkey']}</td>
<td>{$keystat['used']}</td>
</tr>
<tr>
<td>{$lng['opcacheinfo']['wastedkey']}</td>
<td>{$keystat['wasted']}</td>
</tr>
</if>
<if $runtimelines >
<tr class="section">
<th colspan="2">{$lng['opcacheinfo']['runtimeconf']}</th>
</tr>
{$runtimelines}
</if>
<if $blacklistlines >
<tr class="section">
<th colspan="2">{$lng['opcacheinfo']['blacklist']}</th>
</tr>
{$blacklistlines}
</if>
</table>
</section>
</article>
$footer