mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
Merge pull request #48738 from nextcloud/perf/log-high-memory-requests
perf: Log requests using high amount of memory as warning
This commit is contained in:
commit
8c69bf1219
1 changed files with 16 additions and 0 deletions
16
lib/base.php
16
lib/base.php
|
|
@ -18,6 +18,7 @@ use OCP\Security\Bruteforce\IThrottler;
|
|||
use OCP\Server;
|
||||
use OCP\Share;
|
||||
use OCP\User\Events\UserChangedEvent;
|
||||
use OCP\Util;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
|
||||
use function OCP\Log\logger;
|
||||
|
|
@ -828,6 +829,21 @@ class OC {
|
|||
register_shutdown_function(function () use ($eventLogger) {
|
||||
$eventLogger->end('request');
|
||||
});
|
||||
|
||||
register_shutdown_function(function () {
|
||||
$memoryPeak = memory_get_peak_usage();
|
||||
$logLevel = match (true) {
|
||||
$memoryPeak > 500_000_000 => ILogger::FATAL,
|
||||
$memoryPeak > 400_000_000 => ILogger::ERROR,
|
||||
$memoryPeak > 300_000_000 => ILogger::WARN,
|
||||
default => null,
|
||||
};
|
||||
if ($logLevel !== null) {
|
||||
$message = 'Request used more than 300 MB of RAM: ' . Util::humanFileSize($memoryPeak);
|
||||
$logger = Server::get(LoggerInterface::class);
|
||||
$logger->log($logLevel, $message, ['app' => 'core']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue