From cedd5183a1973400d6d2b4a4b2c29ff18fcc1af0 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 28 Aug 2022 00:34:44 -0500 Subject: add more metrics. remove Measure() --- src/slskd/Core/Metrics.cs | 64 ++++++++++++++++------------------------------- 1 file changed, 21 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/slskd/Core/Metrics.cs b/src/slskd/Core/Metrics.cs index 0c31e514..d91920f6 100644 --- a/src/slskd/Core/Metrics.cs +++ b/src/slskd/Core/Metrics.cs @@ -17,9 +17,6 @@ namespace slskd { - using System; - using System.Diagnostics; - using System.Threading.Tasks; using Prometheus; public static class Metrics @@ -37,6 +34,11 @@ 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 search requests received. /// @@ -46,6 +48,8 @@ namespace slskd /// Gets a counter representing the total number of search responses sent. /// public static Counter ResponsesSent { get; } = Prometheus.Metrics.CreateCounter("slskd_search_responses_sent", "Total number of search responses sent"); + + private static Gauge CurrentResponseLatencyGauge { get; } = Prometheus.Metrics.CreateGauge("slskd_search_response_latency_current", "The average time taken to resolve a response to an incoming search request, in milliseconds"); } public static class Browse @@ -88,48 +92,22 @@ namespace slskd /// Gets a gauge representing the current distributed branch level. /// public static Gauge BranchLevel { get; } = Prometheus.Metrics.CreateGauge("slskd_dnet_branch_level", "Current distributed branch level"); - } - - /// - /// Measure the duration of the provided with the specified . - /// - /// - /// - /// - /// - public static T Measure(Histogram histogram, Func action) - { - var sw = new Stopwatch(); - sw.Start(); - - var result = action(); - - sw.Stop(); - - histogram.Observe(sw.ElapsedMilliseconds); - - return result; - } - /// - /// Measure the duration of the provided with the specified . - /// - /// - /// - /// - /// - public static async Task MeasureAsync(Histogram histogram, Func> action) - { - var sw = new Stopwatch(); - sw.Start(); - - var result = await action(); - - sw.Stop(); - - histogram.Observe(sw.ElapsedMilliseconds); + /// + /// Gets a gauge representing the most recent average time tekn to broadcast incoming search requests to connected children. + /// + public static Gauge CurrentBroadcastLatency { get; } = Prometheus.Metrics.CreateGauge("slskd_dnet_broadcast_latency_current", "The average time taken to broadcast incoming search requests to connected children"); - return result; + /// + /// Gets a histogram representing the time taken to resolve a response to an incoming browse request, in milliseconds. + /// + public static Histogram BroadcastLatency { get; } = Prometheus.Metrics.CreateHistogram( + "slskd_dnet_broadcast_latency", + "The time taken to broadcast incoming search requests to connected children, in milliseconds", + new HistogramConfiguration + { + Buckets = Histogram.ExponentialBuckets(0.5, 2, 12), + }); } } } -- cgit v1.2.3