fix: track HTTP request stats for all monitoring endpoints
This commit is contained in:
@@ -14,7 +14,7 @@ public sealed class MonitorServer : IAsyncDisposable
|
||||
private readonly WebApplication _app;
|
||||
private readonly ILogger<MonitorServer> _logger;
|
||||
|
||||
public MonitorServer(NatsServer server, NatsOptions options, ILoggerFactory loggerFactory)
|
||||
public MonitorServer(NatsServer server, NatsOptions options, ServerStats stats, ILoggerFactory loggerFactory)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<MonitorServer>();
|
||||
|
||||
@@ -27,26 +27,75 @@ public sealed class MonitorServer : IAsyncDisposable
|
||||
|
||||
var varzHandler = new VarzHandler(server, options);
|
||||
|
||||
_app.MapGet(basePath + "/", () => Results.Ok(new
|
||||
_app.MapGet(basePath + "/", () =>
|
||||
{
|
||||
endpoints = new[]
|
||||
stats.HttpReqStats.AddOrUpdate("/", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new
|
||||
{
|
||||
"/varz", "/connz", "/healthz", "/routez",
|
||||
"/gatewayz", "/leafz", "/subz", "/accountz", "/jsz",
|
||||
},
|
||||
}));
|
||||
_app.MapGet(basePath + "/healthz", () => Results.Ok("ok"));
|
||||
_app.MapGet(basePath + "/varz", async () => Results.Ok(await varzHandler.HandleVarzAsync()));
|
||||
endpoints = new[]
|
||||
{
|
||||
"/varz", "/connz", "/healthz", "/routez",
|
||||
"/gatewayz", "/leafz", "/subz", "/accountz", "/jsz",
|
||||
},
|
||||
});
|
||||
});
|
||||
_app.MapGet(basePath + "/healthz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/healthz", 1, (_, v) => v + 1);
|
||||
return Results.Ok("ok");
|
||||
});
|
||||
_app.MapGet(basePath + "/varz", async () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/varz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(await varzHandler.HandleVarzAsync());
|
||||
});
|
||||
|
||||
// Stubs for unimplemented endpoints
|
||||
_app.MapGet(basePath + "/routez", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/gatewayz", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/leafz", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/subz", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/subscriptionsz", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/accountz", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/accstatz", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/jsz", () => Results.Ok(new { }));
|
||||
_app.MapGet(basePath + "/connz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/connz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/routez", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/routez", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/gatewayz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/gatewayz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/leafz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/leafz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/subz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/subz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/subscriptionsz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/subscriptionsz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/accountz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/accountz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/accstatz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/accstatz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
_app.MapGet(basePath + "/jsz", () =>
|
||||
{
|
||||
stats.HttpReqStats.AddOrUpdate("/jsz", 1, (_, v) => v + 1);
|
||||
return Results.Ok(new { });
|
||||
});
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken ct)
|
||||
|
||||
Reference in New Issue
Block a user