aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Core/Metrics.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-08-29 16:53:23 -0500
committerGitHub <noreply@github.com>2022-08-29 16:53:23 -0500
commit3b84bc0fb84069491aa6a801c710b3c264563a97 (patch)
treec18afa5445065a99e4a5c1d990189e5f39a88dfb /src/slskd/Core/Metrics.cs
parent0085fa79cbe0b2589abc9ca6a99c367ff5ff0fd5 (diff)
parentd7520caa80629ea0821d936ebf2f236e14f89abe (diff)
downloadslskd-3b84bc0fb84069491aa6a801c710b3c264563a97.tar.gz
Merge pull request #619 from slskd/metrics-auth
Refactor Prometheus implementation and add basic authentication for the /metrics endpoint
Diffstat (limited to 'src/slskd/Core/Metrics.cs')
-rw-r--r--src/slskd/Core/Metrics.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/slskd/Core/Metrics.cs b/src/slskd/Core/Metrics.cs
index 83877500..3fc9a9b1 100644
--- a/src/slskd/Core/Metrics.cs
+++ b/src/slskd/Core/Metrics.cs
@@ -17,10 +17,27 @@
namespace slskd
{
+ using System.IO;
+ using System.Threading.Tasks;
using Prometheus;
public static class Metrics
{
+ /// <summary>
+ /// Builds metrics into a Prometheus-formatted string.
+ /// </summary>
+ /// <returns>A Prometheus-formatted string.</returns>
+ public static async Task<string> BuildAsync()
+ {
+ using var stream = new MemoryStream();
+ using var reader = new StreamReader(stream);
+
+ await Prometheus.Metrics.DefaultRegistry.CollectAndExportAsTextAsync(stream);
+ stream.Position = 0;
+
+ return await reader.ReadToEndAsync();
+ }
+
public static class Search
{
/// <summary>