From 9f3dfc74d699e946604c2d2d17d57f2b4c30c76c Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 11 Apr 2025 14:58:21 +0200 Subject: [PATCH] fix: make prometheus base url configurable --- Catalogger.Backend/Bot/Commands/MetaCommands.cs | 5 +++-- Catalogger.Backend/Config.cs | 1 + Catalogger.Backend/config.example.ini | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Catalogger.Backend/Bot/Commands/MetaCommands.cs b/Catalogger.Backend/Bot/Commands/MetaCommands.cs index 1887507..8b543af 100644 --- a/Catalogger.Backend/Bot/Commands/MetaCommands.cs +++ b/Catalogger.Backend/Bot/Commands/MetaCommands.cs @@ -218,7 +218,7 @@ public class MetaCommands( await channelApi.EditMessageAsync(msg.ChannelID, msg.ID, content: "", embeds: embeds); } - // TODO: add more checks around response format, configurable prometheus endpoint + // TODO: add more checks around response format private async Task MessagesRate() { if (!config.Logging.EnableMetrics) @@ -227,7 +227,8 @@ public class MetaCommands( try { var query = HttpUtility.UrlEncode("increase(catalogger_received_messages[5m])"); - var resp = await _client.GetAsync($"http://localhost:9090/api/v1/query?query={query}"); + var prometheusUrl = config.Logging.PrometheusUrl ?? "http://localhost:9090"; + var resp = await _client.GetAsync($"{prometheusUrl}/api/v1/query?query={query}"); resp.EnsureSuccessStatusCode(); var data = await resp.Content.ReadFromJsonAsync(); diff --git a/Catalogger.Backend/Config.cs b/Catalogger.Backend/Config.cs index 612b91e..831c439 100644 --- a/Catalogger.Backend/Config.cs +++ b/Catalogger.Backend/Config.cs @@ -33,6 +33,7 @@ public class Config public bool EnableMetrics { get; init; } = true; public string? SeqLogUrl { get; init; } + public string? PrometheusUrl { get; init; } } public class DatabaseConfig diff --git a/Catalogger.Backend/config.example.ini b/Catalogger.Backend/config.example.ini index 9b74c55..3f12c79 100644 --- a/Catalogger.Backend/config.example.ini +++ b/Catalogger.Backend/config.example.ini @@ -7,6 +7,9 @@ LogQueries = false SeqLogUrl = http://localhost:5341 # Whether to enable Prometheus metrics. If disabled, Catalogger will update metrics manually every so often. EnableMetrics = false +# The URL for the Prometheus server. Used for message rate if metrics are enabled. +# Defaults to http://localhost:9090, should be changed if Prometheus is on another server. +PrometheusUrl = http://localhost:9090 [Database] Url = Host=localhost;Database=postgres;Username=postgres;Password=postgres