From 97a1b160903e9719ab7ef00d23ac3e31dcbfcff5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 2 May 2026 16:55:35 -0500 Subject: add completed metrics and a histogram for average speed --- src/slskd/Telemetry/Metrics.cs | 62 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/slskd/Telemetry/Metrics.cs b/src/slskd/Telemetry/Metrics.cs index 0f998428..dae87699 100644 --- a/src/slskd/Telemetry/Metrics.cs +++ b/src/slskd/Telemetry/Metrics.cs @@ -303,7 +303,7 @@ public static class Metrics /// /// Gets a gauge representing the current total speed, in bytes per second, of in-progress uploads. /// - public static TimedCounter TotalSpeed { get; } = new TimedCounter(TimeSpan.FromSeconds(1), onElapsed: count => CurrentTotalSpeedGauge.Set(count)); + public static ExponentialMovingAverage CurrentTotalSpeed { get; } = new ExponentialMovingAverage(smoothingFactor: 0.5, onUpdate: value => CurrentTotalSpeedGauge.Set(value)); public static Gauge CurrentTotalSpeedGauge { get; } = Prometheus.Metrics.CreateGauge( name: "slskd_transfers_uploads_in_progress_speed_total_current", help: "Current total speed, in bytes per second, of in-progress uploads"); @@ -311,7 +311,7 @@ public static class Metrics /// /// Gets a gauge representing the current average speed, in bytes per second, of in-progress uploads. /// - public static ExponentialMovingAverage AverageSpeed { get; } = new ExponentialMovingAverage(smoothingFactor: 0.5, onUpdate: value => CurrentAverageSpeedGauge.Set(value)); + public static ExponentialMovingAverage CurrentAverageSpeed { get; } = new ExponentialMovingAverage(smoothingFactor: 0.5, onUpdate: value => CurrentAverageSpeedGauge.Set(value)); public static Gauge CurrentAverageSpeedGauge { get; } = Prometheus.Metrics.CreateGauge( name: "slskd_transfers_uploads_in_progress_speed_average_current", help: "Current average speed, in bytes per second, of in-progress uploads"); @@ -343,6 +343,64 @@ public static class Metrics name: "slskd_transfers_uploads_queued_bytes_current", help: "Current total size, in bytes, of queued uploads"); } + + /// + /// Metrics related to completed uploads. + /// + public static class Completed + { + /// + /// Gets a counter representing the total number of uploads that completed successfully. + /// + public static Counter Succeeded { get; } = Prometheus.Metrics.CreateCounter( + name: "slskd_transfers_uploads_completed_succeeded", + help: "Total number of uploads that completed successfully"); + + /// + /// Gets a counter representing the total number of uploads that failed. + /// + public static Counter Failed { get; } = Prometheus.Metrics.CreateCounter( + name: "slskd_transfers_uploads_completed_failed", + help: "Total number of uploads that failed"); + + /// + /// Gets a counter representing the total number of bytes transferred by successfully completed uploads. + /// + public static Counter Bytes { get; } = Prometheus.Metrics.CreateCounter( + name: "slskd_transfers_uploads_completed_bytes", + help: "Total number of bytes transferred by successfully completed uploads"); + + /// + /// Gets a histogram representing the the average speed of completed uploads, in bytes per second. + /// + public static Histogram AverageSpeed { get; } = Prometheus.Metrics.CreateHistogram( + name: "slskd_transfers_uploads_completed_speed_average", + help: "The average speed of completed uploads, in bytes per second", + new HistogramConfiguration + { + Buckets = [ + 1_024, // 1 KB/s + 10_240, // 10 KB/s + 51_200, // 50 KB/s + 102_400, // 100 KB/s + 204_800, // 200 KB/s + 307_200, // 300 KB/s + 409_600, // 400 KB/s + 512_000, // 500 KB/s + 1_048_576, // 1 MB/s + 2_097_152, // 2 MB/s + 4_194_304, // 4 MB/s + 6_291_456, // 6 MB/s + 10_485_760, // 10 MB/s + 26_214_400, // 25 MB/s + 52_428_800, // 50 MB/s + 104_857_600, // 100 MB/s + 262_144_000, // 250 MB/s + 524_288_000, // 500 MB/s + 1_073_741_824, // 1 GB/s + ], + }); + } } /// -- cgit v1.2.3