|
|
@ -40,25 +40,25 @@ namespace Jellyfin.Server.Middleware
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
/// <returns>Task.</returns>
|
|
|
|
public async Task Invoke(HttpContext context, IServerConfigurationManager serverConfigurationManager)
|
|
|
|
public async Task Invoke(HttpContext context, IServerConfigurationManager serverConfigurationManager)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var watch = new Stopwatch();
|
|
|
|
var startTimestamp = Stopwatch.GetTimestamp();
|
|
|
|
watch.Start();
|
|
|
|
|
|
|
|
var enableWarning = serverConfigurationManager.Configuration.EnableSlowResponseWarning;
|
|
|
|
var enableWarning = serverConfigurationManager.Configuration.EnableSlowResponseWarning;
|
|
|
|
var warningThreshold = serverConfigurationManager.Configuration.SlowResponseThresholdMs;
|
|
|
|
var warningThreshold = serverConfigurationManager.Configuration.SlowResponseThresholdMs;
|
|
|
|
context.Response.OnStarting(() =>
|
|
|
|
context.Response.OnStarting(() =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
watch.Stop();
|
|
|
|
var responseTime = Stopwatch.GetElapsedTime(startTimestamp);
|
|
|
|
var responseTimeForCompleteRequest = watch.ElapsedMilliseconds;
|
|
|
|
var responseTimeMs = responseTime.TotalMilliseconds;
|
|
|
|
if (enableWarning && responseTimeForCompleteRequest > warningThreshold && _logger.IsEnabled(LogLevel.Debug))
|
|
|
|
if (enableWarning && responseTimeMs > warningThreshold && _logger.IsEnabled(LogLevel.Debug))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogDebug(
|
|
|
|
_logger.LogDebug(
|
|
|
|
"Slow HTTP Response from {Url} to {RemoteIp} in {Elapsed:g} with Status Code {StatusCode}",
|
|
|
|
"Slow HTTP Response from {Url} to {RemoteIp} in {Elapsed:g} with Status Code {StatusCode}",
|
|
|
|
context.Request.GetDisplayUrl(),
|
|
|
|
context.Request.GetDisplayUrl(),
|
|
|
|
context.GetNormalizedRemoteIp(),
|
|
|
|
context.GetNormalizedRemoteIp(),
|
|
|
|
watch.Elapsed,
|
|
|
|
responseTime,
|
|
|
|
context.Response.StatusCode);
|
|
|
|
context.Response.StatusCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
context.Response.Headers[ResponseHeaderResponseTime] = responseTimeForCompleteRequest.ToString(CultureInfo.InvariantCulture);
|
|
|
|
context.Response.Headers[ResponseHeaderResponseTime] = responseTimeMs.ToString(CultureInfo.InvariantCulture);
|
|
|
|
return Task.CompletedTask;
|
|
|
|
return Task.CompletedTask;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|