mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* add slow query logging * add slow api logging for jellyfin * add configurable jellyfin page size * feedbackpull/2746/head
6 changed files with 135 additions and 12 deletions
@ -0,0 +1,38 @@ |
|||||||
|
using ErsatzTV.Core; |
||||||
|
|
||||||
|
namespace ErsatzTV; |
||||||
|
|
||||||
|
using System.Diagnostics; |
||||||
|
|
||||||
|
public class SlowApiHandler(ILogger<SlowApiHandler> logger) : DelegatingHandler |
||||||
|
{ |
||||||
|
protected override async Task<HttpResponseMessage> SendAsync( |
||||||
|
HttpRequestMessage request, |
||||||
|
CancellationToken cancellationToken) |
||||||
|
{ |
||||||
|
if (SystemEnvironment.SlowApiMs > 0) |
||||||
|
{ |
||||||
|
var stopwatch = Stopwatch.StartNew(); |
||||||
|
|
||||||
|
var response = await base.SendAsync(request, cancellationToken); |
||||||
|
|
||||||
|
stopwatch.Stop(); |
||||||
|
|
||||||
|
if (stopwatch.ElapsedMilliseconds > SystemEnvironment.SlowApiMs.Value) |
||||||
|
{ |
||||||
|
string uri = request.RequestUri?.ToString() ?? "Unknown URI"; |
||||||
|
string method = request.Method.Method; |
||||||
|
|
||||||
|
logger.LogDebug( |
||||||
|
"[SLOW API] {Method} {Uri} took {Milliseconds}ms", |
||||||
|
method, |
||||||
|
uri, |
||||||
|
stopwatch.ElapsedMilliseconds); |
||||||
|
} |
||||||
|
|
||||||
|
return response; |
||||||
|
} |
||||||
|
|
||||||
|
return await base.SendAsync(request, cancellationToken); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,24 @@ |
|||||||
|
using System.Data.Common; |
||||||
|
using Microsoft.EntityFrameworkCore.Diagnostics; |
||||||
|
|
||||||
|
namespace ErsatzTV; |
||||||
|
|
||||||
|
public class SlowQueryInterceptor(int threshold) : DbCommandInterceptor |
||||||
|
{ |
||||||
|
public override ValueTask<DbDataReader> ReaderExecutedAsync( |
||||||
|
DbCommand command, |
||||||
|
CommandExecutedEventData eventData, |
||||||
|
DbDataReader result, |
||||||
|
CancellationToken cancellationToken = default) |
||||||
|
{ |
||||||
|
if (eventData.Duration.TotalMilliseconds > threshold) |
||||||
|
{ |
||||||
|
Serilog.Log.Logger.Debug( |
||||||
|
"[SLOW QUERY] ({Milliseconds}ms): {Command}", |
||||||
|
eventData.Duration.TotalMilliseconds, |
||||||
|
command.CommandText); |
||||||
|
} |
||||||
|
|
||||||
|
return base.ReaderExecutedAsync(command, eventData, result, cancellationToken); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue