From 5f6ac691a50deab1a3cf76cc16ac5e941f86580f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 25 Aug 2022 22:16:14 -0500 Subject: clean up --- src/slskd/Core/Metrics.cs | 76 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 11 deletions(-) (limited to 'src') 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 (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/. +// namespace slskd { + using System; + using System.Diagnostics; + using System.Threading.Tasks; + using Prometheus; + + /// + /// Application metrics. + /// 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), - }); + /// + /// Gets a histogram representing the time taken to resolve a response to an incoming search request, in milliseconds. + /// + 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), + }); + /// + /// Gets a counter representing the total number of search requests received. + /// public static Counter SearchRequestsReceived { get; } = Prometheus.Metrics.CreateCounter("slskd_search_requests_received", "Total number of search requests received"); + + /// + /// Gets a counter representing the total number of search responses sent. + /// public static Counter SearchResponsesSent { get; } = Prometheus.Metrics.CreateCounter("slskd_search_responses_sent", "Total number of search responses sent"); + /// + /// Gets a counter representing the total number of browse responses sent. + /// 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", + + /// + /// Gets a histogram representing the the time taken to resolve a response to an incoming browse request, in milliseconds. + /// + 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), }); + /// + /// Measure the duration of the provided with the specified . + /// + /// + /// + /// + /// public static T Measure(Histogram histogram, Func action) { var sw = new Stopwatch(); @@ -38,6 +85,13 @@ namespace slskd return result; } + /// + /// Measure the duration of the provided with the specified . + /// + /// + /// + /// + /// public static async Task MeasureAsync(Histogram histogram, Func> action) { var sw = new Stopwatch(); -- cgit v1.2.3