1
0
Fork 0
mirror of https://github.com/Findus23/matomo-DiagnosticsExtended.git synced 2024-09-19 16:03:46 +02:00

add OPcache check

This commit is contained in:
Lukas Winkler 2021-04-12 17:28:42 +02:00
parent 08a6e8d320
commit e0ea80006f
Signed by: lukas
GPG key ID: 54DE4D798D244853
5 changed files with 166 additions and 24 deletions

111
Diagnostic/OpcacheCheck.php Normal file
View file

@ -0,0 +1,111 @@
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\DiagnosticsExtended\Diagnostic;
use Piwik\Piwik;
use Piwik\Plugins\Diagnostics\Diagnostic\Diagnostic;
use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResult;
use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResultItem;
use Piwik\Plugins\DiagnosticsExtended\Utils;
use Psr\Log\LoggerInterface;
class OpcacheCheck implements Diagnostic
{
private const MEGABYTE = 1024 * 1024;
/**
* @var LoggerInterface
*/
private $logger;
/**
* @var string
*/
private $label;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
$this->label = "🧪 " . "OPcache";
}
/**
* @return DiagnosticResult[]
*/
public function execute()
{
$result = new DiagnosticResult($this->label);
if (!Utils::booleanIni("opcache.enable")) {
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_WARNING,
Piwik::translate("DiagnosticsExtended_OpcacheCheckOpcacheDisabled")
));
return [$result];
} else {
$status = opcache_get_status();
$memoryUsage = $status["memory_usage"];
$interned = $status["interned_strings_usage"];
$statistics = $status["opcache_statistics"];
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_OK,
Piwik::translate("DiagnosticsExtended_OpcacheCheckOpcacheEnabled", [
round($memoryUsage["used_memory"] / self::MEGABYTE),
round(($memoryUsage["used_memory"] + $memoryUsage["free_memory"]) / self::MEGABYTE),
round($memoryUsage["current_wasted_percentage"] * 100, 2),
round($interned["used_memory"] / self::MEGABYTE),
round($interned["buffer_size"] / self::MEGABYTE),
round($statistics["opcache_hit_rate"])
])
));
}
if (!Utils::booleanIni("opcache.save_comments")) {
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_ERROR,
Piwik::translate("DiagnosticsExtended_OpcacheCheckSaveComments")
));
}
$minimum_files = 7963;
if (Utils::intIni("opcache.max_accelerated_files") <= $minimum_files) {
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_WARNING,
Piwik::translate("DiagnosticsExtended_OpcacheCheckMaxFiles", [$minimum_files])
));
}
if (Utils::intIni("opcache.memory_consumption") < 128) {
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_WARNING,
Piwik::translate("DiagnosticsExtended_OpcacheCheckMemory")
));
}
if (Utils::intIni("opcache.interned_strings_buffer") < 8) {
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_WARNING,
Piwik::translate("DiagnosticsExtended_OpcacheCheckInternedStrings")
));
}
if (!Utils::intIni("opcache.validate_timestamps")) {
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_INFORMATIONAL,
Piwik::translate("DiagnosticsExtended_OpcacheCheckValidateTimestamps")
));
}
$jit = ini_get("opcache.jit");
if (PHP_MAJOR_VERSION >= 8 && (!$jit || $jit == "0" || $jit == "off")) {
$result->addItem(new DiagnosticResultItem(
DiagnosticResult::STATUS_INFORMATIONAL,
Piwik::translate("DiagnosticsExtended_OpcacheCheckJIT")
));
}
return [$result];
}
}

View file

@ -13,6 +13,7 @@ use Piwik\Plugins\Diagnostics\Diagnostic\Diagnostic;
use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResult;
use Piwik\Plugins\Diagnostics\Diagnostic\DiagnosticResultItem;
use Piwik\Plugins\DiagnosticsExtended\Diagnostic\IniSettings\IniSetting;
use Piwik\Plugins\DiagnosticsExtended\Utils;
use Psr\Log\LoggerInterface;
class PhpIniCheck implements Diagnostic
@ -42,7 +43,7 @@ class PhpIniCheck implements Diagnostic
$result = new DiagnosticResult($this->label);
foreach ($this->iniSettings as $setting) {
$key = $setting::$key;
if ($this->booleanIni($key) === $setting::$targetValue) {
if (Utils::booleanIni($key) === $setting::$targetValue) {
$item = new DiagnosticResultItem(
DiagnosticResult::STATUS_OK,
$setting::$targetValue
@ -65,29 +66,6 @@ class PhpIniCheck implements Diagnostic
}
private function booleanIni(string $key): bool
{
return $this->IniValueToBoolean(ini_get($key));
}
private function IniValueToBoolean(string $iniValue): bool
{
switch (strtolower($iniValue)) {
case "on":
case "true":
case "yes":
case "1":
return true;
case "off":
case "false":
case "no":
case "0":
case "":
return false;
default:
return $iniValue;
}
}
}

44
Utils.php Normal file
View file

@ -0,0 +1,44 @@
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\DiagnosticsExtended;
class Utils
{
static function booleanIni(string $key): bool
{
return Utils::IniValueToBoolean(ini_get($key));
}
static function intIni(string $key): int
{
return (int)ini_get($key);
}
static function IniValueToBoolean(string $iniValue): bool
{
switch (strtolower($iniValue)) {
case "on":
case "true":
case "yes":
case "1":
return true;
case "off":
case "false":
case "no":
case "0":
case "":
return false;
default:
return $iniValue;
}
}
}

View file

@ -19,6 +19,7 @@ return [
DI\get('\Piwik\Plugins\DiagnosticsExtended\Diagnostic\OpensslVersionCheck'),
DI\get('\Piwik\Plugins\DiagnosticsExtended\Diagnostic\PhpUserCheck'),
DI\get('\Piwik\Plugins\DiagnosticsExtended\Diagnostic\URLCheck'),
DI\get('\Piwik\Plugins\DiagnosticsExtended\Diagnostic\OpcacheCheck'),
]),
];

View file

@ -20,6 +20,14 @@
"MatomoJSCheckUnknown": "Matomo could not check if your matomo.js can be fetched properly.",
"NotificationText": "You have enabled the DiagnosticsExtended plugin. It adds a few more experimental system checks (marked with 🧪) to this page that might help you find issues with your Matomo instance. There might still be a few false positives and false negatives, so don't take the results as a truth, but check yourself if something is wrong. Please report issues with the plugin to the %1$sforum%2$s or %3$screate a GitHub issue%4$s so that the checks can be improved.",
"NotificationTitle": "About DiagnosticsExtended",
"OpcacheCheckInternedStrings": "It seems like you have set <code>opcache.interned_strings_buffer</code> below 8MB which might be a bit low. Please increase the value to 8 (Megabyte) or more depending on how many PHP files you serve and how much memory your server has available.",
"OpcacheCheckJIT": "As you are using PHP 8 or newer, you might want to look into enabling the JIT compiler. It might be able to speed up Matomo by a bit. It would also be great if you could report back any experiences after enabling PHP JIT.",
"OpcacheCheckMaxFiles": "It seems like you have set <code>opcache.max_accelerated_files</code> to or below %s which might be too low to keep all Matomo files in the cache, especially if you are also hosting other PHP applications. Please set the option to 7963, 16229 or 32531 depending on the number of PHP files your webserver uses.",
"OpcacheCheckMemory": "It seems like you have set <code>opcache.memory_consumption</code> below 128MB which might be too low to keep all Matomo files in the cache, especially if you are also hosting other PHP applications. Please increase the value to 128 or 256 (Megabyte) depending on how many PHP files you serve and how much memory your server has available.",
"OpcacheCheckOpcacheDisabled": "It seems like OPcache is disabled in your PHP setup. OPcache stores bytecode of PHP scripts in memory and is therefore able to speed up PHP by quite a bit as it avoids loading and parsing PHP files on every request. Check the <code>opcache.enable</code> php.ini setting for more information.",
"OpcacheCheckOpcacheEnabled": "It seems like OPcache is enabled. %1$sMB of %2$sMB are used for PHP scripts (%3$s&percnt; wasted) and %4$sMB of %5$sMB are used for interned strings. %6$s&percnt; of requests hit the OPcache.",
"OpcacheCheckSaveComments": "It seems like you have disabled the <code>opcache.save_comments</code> setting. This removes comments from the OPcache making it smaller, but breaks Matomo. Please set <code>opcache.save_comments</code> to <code>0</code>",
"OpcacheCheckValidateTimestamps": "It seems like you have disabled <code>opcache.validate_timestamps</code> which means that PHP will never check if the actual files on disk have changed, but continue to use the cached ones. In theory, this should be no issue as Matomo invalidates the OPcache on updates and installs, but you might still want to look into this if you encounter weird issues.",
"OpensslVersionCheckLabel": "OpenSSL version check",
"OpensslVersionCheckNoOpenssl": "Your PHP setup doesn't use OpenSSL or curl, so there is nothing to check.",
"OpensslVersionCheckNotOutdated": "Your OpenSSL version (%s) is not really old. Nevertheless, check if there are known vulnerabilities for it and update it if necessary.",