20 lines
1.2 KiB
C#
20 lines
1.2 KiB
C#
using System.Text.Json;
|
|
using IM.Admin.Services;
|
|
using IM.InitCommon.Management;
|
|
|
|
namespace IM.Admin.Api;
|
|
public static class MonitoringEndpoints
|
|
{
|
|
public static void MapMonitoring(this WebApplication app)
|
|
{
|
|
var api = app.MapGroup("/api/admin").RequireAuthorization("operate");
|
|
api.MapGet("/health", async (HealthSampler sampler, InternalClient client, CancellationToken ct) => {
|
|
var health = await sampler.Read(ct); JsonElement? connections = null;
|
|
try { connections = await client.Send<JsonElement>("connector", "/internal/management/connections", ct: ct); } catch { }
|
|
return ManagementResult.Ok(new { services = health, connections, sampledAt = DateTime.UtcNow });
|
|
});
|
|
api.MapGet("/storage", async (HttpContext c, InternalClient client) => ManagementResult.Ok(await client.Send<JsonElement>("file", "/internal/management/storage/summary" + c.Request.QueryString, ct: c.RequestAborted)));
|
|
app.MapGet("/api/admin/groups/{id:guid}/members", async (Guid id, HttpContext c, InternalClient client) => ManagementResult.Ok(await client.Send<JsonElement>("group", $"/internal/management/members/{id}" + c.Request.QueryString, ct: c.RequestAborted))).RequireAuthorization();
|
|
}
|
|
}
|