feat: add actual metrics using prometheus-net

This commit is contained in:
sam 2024-09-03 17:00:14 +02:00
parent 4a6b5f3b85
commit 54ec469cd9
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
9 changed files with 134 additions and 56 deletions

View file

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;
using Minio;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Prometheus;
using Sentry.Extensibility;
// Read version information from .version in the repository root
@ -18,7 +19,9 @@ var builder = WebApplication.CreateBuilder(args);
var config = builder.AddConfiguration();
builder.AddSerilog().AddMetrics();
builder
.AddSerilog()
.AddMetrics(config);
builder.WebHost
.UseSentry(opts =>
@ -89,7 +92,10 @@ app.MapControllers();
app.Urls.Clear();
app.Urls.Add(config.Address);
if (config.MetricsAddress != null) app.Urls.Add(config.MetricsAddress);
// Make sure metrics are updated whenever Prometheus scrapes them
Metrics.DefaultRegistry.AddBeforeCollectCallback(async ct =>
await app.Services.GetRequiredService<MetricsCollectionService>().CollectMetricsAsync(ct));
// Fire off the periodic tasks loop in the background
_ = new Timer(_ =>