aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-08-25 22:16:14 -0500
committerJP Dillingham <jp@dillingham.me>2022-08-25 22:16:14 -0500
commit5f6ac691a50deab1a3cf76cc16ac5e941f86580f (patch)
tree70595e47cf34450955093de126af8d84d21c18d3 /src
parentc9ae44e33e3d8b7b8ab8b11f3f094e05dfe9fea5 (diff)
downloadslskd-5f6ac691a50deab1a3cf76cc16ac5e941f86580f.tar.gz
clean up
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Metrics.cs76
1 files changed, 65 insertions, 11 deletions
diff --git a/src/slskd/Core/Metrics.cs b/src/slskd/Core/Metrics.cs
index e3fbfe01..d5e5e7be 100644
--- a/src/slskd/Core/Metrics.cs
+++ b/src/slskd/Core/Metrics.cs
@@ -1,29 +1,76 @@
-using System;
-using System.Diagnostics;
-using System.Threading.Tasks;
-using Prometheus;
+// <copyright file="Metrics.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
namespace slskd
{
+ using System;
+ using System.Diagnostics;
+ using System.Threading.Tasks;
+ using Prometheus;
+
+ /// <summary>
+ /// Application metrics.
+ /// </summary>
public static class Metrics
{
- public static Histogram SearchResponseLatency { get; } = Prometheus.Metrics
- .CreateHistogram($"slskd_search_response_latency", "The time taken to resolve a response to an incoming search request, in milliseconds",
- new HistogramConfiguration
- {
- Buckets = Histogram.ExponentialBuckets(1, 2, 10),
- });
+ /// <summary>
+ /// Gets a histogram representing the time taken to resolve a response to an incoming search request, in milliseconds.
+ /// </summary>
+ public static Histogram SearchResponseLatency { get; } = Prometheus.Metrics.CreateHistogram(
+ "slskd_search_response_latency",
+ "The time taken to resolve a response to an incoming search request, in milliseconds",
+ new HistogramConfiguration
+ {
+ Buckets = Histogram.ExponentialBuckets(1, 2, 10),
+ });
+ /// <summary>
+ /// Gets a counter representing the total number of search requests received.
+ /// </summary>
public static Counter SearchRequestsReceived { get; } = Prometheus.Metrics.CreateCounter("slskd_search_requests_received", "Total number of search requests received");
+
+ /// <summary>
+ /// Gets a counter representing the total number of search responses sent.
+ /// </summary>
public static Counter SearchResponsesSent { get; } = Prometheus.Metrics.CreateCounter("slskd_search_responses_sent", "Total number of search responses sent");
+ /// <summary>
+ /// Gets a counter representing the total number of browse responses sent.
+ /// </summary>
public static Counter BrowseResponsesSent { get; } = Prometheus.Metrics.CreateCounter("slskd_browse_responses_sent", "Total number of browse responses sent");
- public static Histogram BrowseResponseLatency { get; } = Prometheus.Metrics.CreateHistogram("slskd_browse_response_latency", "The time taken to resolve a response to an incoming browse request, in milliseconds",
+
+ /// <summary>
+ /// Gets a histogram representing the the time taken to resolve a response to an incoming browse request, in milliseconds.
+ /// </summary>
+ public static Histogram BrowseResponseLatency { get; } = Prometheus.Metrics.CreateHistogram(
+ "slskd_browse_response_latency",
+ "The time taken to resolve a response to an incoming browse request, in milliseconds",
new HistogramConfiguration
{
Buckets = Histogram.ExponentialBuckets(1, 2, 10),
});
+ /// <summary>
+ /// Measure the duration of the provided <paramref name="action"/> with the specified <paramref name="histogram"/>.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="histogram"></param>
+ /// <param name="action"></param>
+ /// <returns></returns>
public static T Measure<T>(Histogram histogram, Func<T> action)
{
var sw = new Stopwatch();
@@ -38,6 +85,13 @@ namespace slskd
return result;
}
+ /// <summary>
+ /// Measure the duration of the provided <paramref name="action"/> with the specified <paramref name="histogram"/>.
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="histogram"></param>
+ /// <param name="action"></param>
+ /// <returns></returns>
public static async Task<T> MeasureAsync<T>(Histogram histogram, Func<Task<T>> action)
{
var sw = new Stopwatch();