aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Telemetry/PrometheusService.cs
diff options
context:
space:
mode:
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 };