aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Telemetry/PrometheusService.cs
diff options
context:
space:
mode:
authorx0vi <166640642+x0vi@users.noreply.github.com>2025-12-08 17:48:50 +0100
committerGitHub <noreply@github.com>2025-12-08 17:48:50 +0100
commit2940b28785c6a548414fd684941e29d1e3a5b2d9 (patch)
tree80f69a2ec785fc791e7c7581c370f805aec17895 /src/slskd/Telemetry/PrometheusService.cs
parent15dee48db66f3bf0c8490aa1844bad0ba0371523 (diff)
parentf80fbac5eeda5901a106975446d0a11b7cbc38d6 (diff)
downloadslskd-2940b28785c6a548414fd684941e29d1e3a5b2d9.tar.gz
Merge branch 'master' into feature/configurable-ip-address
Diffstat (limited to 'src/slskd/Telemetry/PrometheusService.cs')
-rw-r--r--src/slskd/Telemetry/PrometheusService.cs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/slskd/Telemetry/PrometheusService.cs b/src/slskd/Telemetry/PrometheusService.cs
index 249319d5..06235981 100644
--- a/src/slskd/Telemetry/PrometheusService.cs
+++ b/src/slskd/Telemetry/PrometheusService.cs
@@ -15,7 +15,7 @@
// along with this program. If not, see https://www.gnu.org/licenses/.
// </copyright>
-namespace slskd;
+namespace slskd.Telemetry;
using System;
using System.Collections.Generic;
@@ -30,6 +30,25 @@ public class PrometheusService
private static Regex PrometheusLabelSplittingRegex { get; } = new Regex("([a-zA-Z_][a-zA-Z0-9_]*)\\s*=\\s*\"([^\"]*)\"", RegexOptions.Compiled);
/// <summary>
+ /// These metrics repeat many times with disambiguating labels, and this conflicts with the current approach
+ /// for building metrics in object format; dictionary entries (keyed by the names seen in this list) conflict,
+ /// and values are merged and potentially collide. This could be fixed by pulling disambiguating labels up into
+ /// the names, but these labels are things like HTTP route names, exception types, and server addresses. All of
+ /// which has very little value to an application that wants to display metrics to an end user (which is why this exists).
+ ///
+ /// The easy solution is to just ignore these classes of metrics, and that's what I'm going to do.
+ ///
+ /// This can be revisited if someone feels very strongly.
+ /// </summary>
+ private static Regex[] ExcludedMetrics { get; } = new[]
+ {
+ new Regex("^microsoft_aspnetcore_hosting_http_server_request_duration.*", RegexOptions.Compiled),
+ new Regex("^system_net_http_http_client_request_time_in_queue.*", RegexOptions.Compiled),
+ new Regex("^system_net_http_http_client_request_duration.*", RegexOptions.Compiled),
+ new Regex("^microsoft_aspnetcore_server_kestrel_kestrel_connection_duration.*", RegexOptions.Compiled),
+ };
+
+ /// <summary>
/// Get the current list of Prometheus metrics in Prometheus exposition format (text based).
/// </summary>
/// <returns></returns>
@@ -85,6 +104,12 @@ public class PrometheusService
continue;
}
+ // see the note above about excluded metrics and why this is necessary
+ if (ExcludedMetrics.Any(regex => regex.IsMatch(name)))
+ {
+ continue;
+ }
+
var type = lines[startIndex + 1].Substring(7).Split(' ', 2)[1];
var metric = new PrometheusMetric() { Name = name, Help = help, Type = type };