From 76f40ff5f2581da82fe710fb7f0fd15cd96bbdb3 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 28 Aug 2022 21:13:35 -0500 Subject: average browse response latency also --- src/slskd/Application.cs | 1 + src/slskd/Core/Metrics.cs | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 8f033704..e9b00c6b 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -421,6 +421,7 @@ namespace slskd sw.Stop(); Metrics.Browse.ResponseLatency.Observe(sw.ElapsedMilliseconds); + Metrics.Browse.CurrentResponseLatency.Update(sw.ElapsedMilliseconds); Metrics.Browse.ResponsesSent.Inc(1); return new BrowseResponse(directories); diff --git a/src/slskd/Core/Metrics.cs b/src/slskd/Core/Metrics.cs index d91920f6..98db91d2 100644 --- a/src/slskd/Core/Metrics.cs +++ b/src/slskd/Core/Metrics.cs @@ -54,11 +54,6 @@ namespace slskd public static class Browse { - /// - /// Gets a counter representing the total number of browse responses sent. - /// - public static Counter ResponsesSent { get; } = Prometheus.Metrics.CreateCounter("slskd_browse_responses_sent", "Total number of browse responses sent"); - /// /// Gets a histogram representing the time taken to resolve a response to an incoming browse request, in milliseconds. /// @@ -69,6 +64,18 @@ namespace slskd { Buckets = Histogram.ExponentialBuckets(1, 2, 10), }); + + /// + /// Gets an EMA representing the average time taken to resolve a response to an incoming search request, in milliseconds. + /// + public static ExponentialMovingAverage CurrentResponseLatency { get; } = new ExponentialMovingAverage(smoothingFactor: 0.5, onUpdate: value => CurrentResponseLatencyGauge.Set(value)); + + /// + /// Gets a counter representing the total number of browse responses sent. + /// + public static Counter ResponsesSent { get; } = Prometheus.Metrics.CreateCounter("slskd_browse_responses_sent", "Total number of browse responses sent"); + + private static Gauge CurrentResponseLatencyGauge { get; } = Prometheus.Metrics.CreateGauge("slskd_browse_response_latency_current", "The average time taken to resolve a response to an incoming browse request, in milliseconds"); } public static class DistributedNetwork -- cgit v1.2.3