Skip to content

Commit

Permalink
feat(metrics): Add queried-tracks metric
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Feb 24, 2024
1 parent 190ecd8 commit c24a709
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Lavalink4NET.Rest/LavalinkApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Lavalink4NET.Rest;

using System.Collections.Immutable;
using System.Diagnostics.Metrics;
using System.Net;
using System.Net.Http;
using System.Net.Http.Json;
Expand Down Expand Up @@ -242,6 +243,9 @@ private async ValueTask<LoadResultModel> LoadTracksInternalAsync(string identifi
cancellationToken.ThrowIfCancellationRequested();
ArgumentNullException.ThrowIfNull(identifier);

var metricTag = KeyValuePair.Create<string, object?>("Identifier", identifier);
Diagnostics.QueriedTracks.Add(1, metricTag);

var queryParameters = HttpUtility.ParseQueryString(string.Empty);
queryParameters["identifier"] = identifier;

Expand Down Expand Up @@ -500,4 +504,19 @@ private static string PrefixIdentifier(string identifier, TrackSearchMode search
? identifier
: $"{searchMode.Prefix}:{identifier}";
}
}

file static class Diagnostics
{
public static Counter<long> QueriedTracks { get; }

static Diagnostics()
{
var meter = new Meter("Lavalink4NET");

QueriedTracks = meter.CreateCounter<long>(
name: "queried-tracks",
unit: "Tracks",
description: "The number of tracks queried from the node (non-cached only).");
}
}
3 changes: 2 additions & 1 deletion src/Lavalink4NET/Tracks/TrackManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Lavalink4NET.Tracks;

using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
Expand Down Expand Up @@ -145,7 +146,7 @@ static Diagnostics()
ResolvedTracks = meter.CreateCounter<long>(
name: "resolved-tracks",
unit: "Tracks",
description: "The number of resolved tracks.");
description: "The number of resolved tracks (including cached and non-cached).");

FailedQueries = meter.CreateCounter<long>(
name: "failed-queries",
Expand Down

0 comments on commit c24a709

Please sign in to comment.