feat: add vendor tenant metrics dashboard
Fleet overview page at /vendor/metrics showing per-tenant operational metrics (agents, CPU, heap, HTTP requests, ingestion drops, uptime). Queries each tenant's server via the new POST /api/v1/admin/server-metrics/query REST API instead of direct ClickHouse access, supporting future per-tenant CH instances. Backend: TenantMetricsService fires 11 metric queries per tenant concurrently over a 5-minute window, assembles into a summary snapshot. ServerApiClient.queryServerMetrics() handles the M2M authenticated POST. Frontend: VendorMetricsPage with KPI strip (fleet totals) and per-tenant table with color-coded badges and heap usage bars. Auto-refreshes every 60s. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.web.client.RestClient;
|
import org.springframework.web.client.RestClient;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,6 +172,38 @@ public class ServerApiClient {
|
|||||||
|
|
||||||
public record ServerHealthResponse(boolean healthy, String status) {}
|
public record ServerHealthResponse(boolean healthy, String status) {}
|
||||||
|
|
||||||
|
// --- Server metrics query (POST /api/v1/admin/server-metrics/query) ---
|
||||||
|
|
||||||
|
public record MetricsQueryResponse(
|
||||||
|
String metric,
|
||||||
|
String statistic,
|
||||||
|
String aggregation,
|
||||||
|
String mode,
|
||||||
|
int stepSeconds,
|
||||||
|
List<MetricsSeries> series
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public record MetricsSeries(Map<String, String> tags, List<MetricsPoint> points) {}
|
||||||
|
|
||||||
|
public record MetricsPoint(String t, double v) {}
|
||||||
|
|
||||||
|
/** Execute a server-metrics query against a tenant's server. */
|
||||||
|
public MetricsQueryResponse queryServerMetrics(String serverEndpoint, Map<String, Object> body) {
|
||||||
|
try {
|
||||||
|
return RestClient.create().post()
|
||||||
|
.uri(serverEndpoint + "/api/v1/admin/server-metrics/query")
|
||||||
|
.header("Authorization", "Bearer " + getAccessToken())
|
||||||
|
.header("X-Cameleer-Protocol-Version", "1")
|
||||||
|
.contentType(MediaType.APPLICATION_JSON)
|
||||||
|
.body(body)
|
||||||
|
.retrieve()
|
||||||
|
.body(MetricsQueryResponse.class);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Metrics query failed for {}: {}", serverEndpoint, e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized String getAccessToken() {
|
private synchronized String getAccessToken() {
|
||||||
if (cachedToken != null && Instant.now().isBefore(tokenExpiry.minusSeconds(60))) {
|
if (cachedToken != null && Instant.now().isBefore(tokenExpiry.minusSeconds(60))) {
|
||||||
return cachedToken;
|
return cachedToken;
|
||||||
|
|||||||
74
src/main/java/net/siegeln/cameleer/saas/vendor/TenantMetricsController.java
vendored
Normal file
74
src/main/java/net/siegeln/cameleer/saas/vendor/TenantMetricsController.java
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
package net.siegeln.cameleer.saas.vendor;
|
||||||
|
|
||||||
|
import net.siegeln.cameleer.saas.provisioning.ServerStatus;
|
||||||
|
import net.siegeln.cameleer.saas.tenant.TenantEntity;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/vendor/metrics")
|
||||||
|
@PreAuthorize("hasAuthority('SCOPE_platform:admin')")
|
||||||
|
public class TenantMetricsController {
|
||||||
|
|
||||||
|
private final VendorTenantService vendorTenantService;
|
||||||
|
private final TenantMetricsService metricsService;
|
||||||
|
|
||||||
|
public TenantMetricsController(VendorTenantService vendorTenantService,
|
||||||
|
TenantMetricsService metricsService) {
|
||||||
|
this.vendorTenantService = vendorTenantService;
|
||||||
|
this.metricsService = metricsService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public record TenantMetricsEntry(
|
||||||
|
String tenantId,
|
||||||
|
String tenantName,
|
||||||
|
String slug,
|
||||||
|
String tier,
|
||||||
|
String status,
|
||||||
|
String serverState,
|
||||||
|
TenantMetricsService.MetricsSummary metrics
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<TenantMetricsEntry>> all() {
|
||||||
|
List<TenantEntity> tenants = vendorTenantService.listAll();
|
||||||
|
|
||||||
|
List<CompletableFuture<TenantMetricsEntry>> futures = tenants.stream()
|
||||||
|
.map(tenant -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
ServerStatus serverStatus = vendorTenantService.getServerStatus(tenant);
|
||||||
|
String state = serverStatus.state().name();
|
||||||
|
|
||||||
|
TenantMetricsService.MetricsSummary metrics = null;
|
||||||
|
String endpoint = tenant.getServerEndpoint();
|
||||||
|
boolean isRunning = "ACTIVE".equals(tenant.getStatus().name())
|
||||||
|
&& endpoint != null && !endpoint.isBlank()
|
||||||
|
&& "RUNNING".equals(state);
|
||||||
|
if (isRunning) {
|
||||||
|
metrics = metricsService.getMetricsSummary(endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new TenantMetricsEntry(
|
||||||
|
tenant.getId().toString(),
|
||||||
|
tenant.getName(),
|
||||||
|
tenant.getSlug(),
|
||||||
|
tenant.getTier().name(),
|
||||||
|
tenant.getStatus().name(),
|
||||||
|
state,
|
||||||
|
metrics
|
||||||
|
);
|
||||||
|
}))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
List<TenantMetricsEntry> entries = futures.stream()
|
||||||
|
.map(CompletableFuture::join)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return ResponseEntity.ok(entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
176
src/main/java/net/siegeln/cameleer/saas/vendor/TenantMetricsService.java
vendored
Normal file
176
src/main/java/net/siegeln/cameleer/saas/vendor/TenantMetricsService.java
vendored
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
package net.siegeln.cameleer.saas.vendor;
|
||||||
|
|
||||||
|
import net.siegeln.cameleer.saas.identity.ServerApiClient;
|
||||||
|
import net.siegeln.cameleer.saas.identity.ServerApiClient.MetricsQueryResponse;
|
||||||
|
import net.siegeln.cameleer.saas.identity.ServerApiClient.MetricsPoint;
|
||||||
|
import net.siegeln.cameleer.saas.identity.ServerApiClient.MetricsSeries;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TenantMetricsService {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(TenantMetricsService.class);
|
||||||
|
|
||||||
|
private final ServerApiClient serverApiClient;
|
||||||
|
|
||||||
|
public TenantMetricsService(ServerApiClient serverApiClient) {
|
||||||
|
this.serverApiClient = serverApiClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Response records ---
|
||||||
|
|
||||||
|
public record MetricsSummary(
|
||||||
|
String collectedAt,
|
||||||
|
AgentMetrics agents,
|
||||||
|
IngestionMetrics ingestion,
|
||||||
|
ServerJvmMetrics server,
|
||||||
|
HttpMetrics http,
|
||||||
|
double authFailuresPerMinute
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public record AgentMetrics(int live, int stale, int dead, int shutdown) {}
|
||||||
|
|
||||||
|
public record IngestionMetrics(long bufferDepth, double dropsPerMinute) {}
|
||||||
|
|
||||||
|
public record ServerJvmMetrics(
|
||||||
|
double cpuUsage,
|
||||||
|
long heapUsedBytes,
|
||||||
|
long heapMaxBytes,
|
||||||
|
long uptimeSeconds,
|
||||||
|
int threadCount
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public record HttpMetrics(double requestsPerMinute, double errorRate) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query a tenant's server for key metrics and assemble a summary snapshot.
|
||||||
|
* Fires multiple queries concurrently (one per metric group) over the last 5 minutes.
|
||||||
|
*/
|
||||||
|
public MetricsSummary getMetricsSummary(String serverEndpoint) {
|
||||||
|
Instant to = Instant.now();
|
||||||
|
Instant from = to.minus(5, ChronoUnit.MINUTES);
|
||||||
|
String fromStr = from.toString();
|
||||||
|
String toStr = to.toString();
|
||||||
|
|
||||||
|
// Fire all queries concurrently
|
||||||
|
var agentsFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "cameleer.agents.connected", "value", fromStr, toStr, "avg", "raw", List.of("state"), null));
|
||||||
|
var cpuFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "process.cpu.usage", "value", fromStr, toStr, "avg", "raw", null, null));
|
||||||
|
var heapUsedFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "jvm.memory.used", "value", fromStr, toStr, "sum", "raw", null, Map.of("area", "heap")));
|
||||||
|
var heapMaxFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "jvm.memory.max", "value", fromStr, toStr, "sum", "raw", null, Map.of("area", "heap")));
|
||||||
|
var uptimeFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "process.uptime", "value", fromStr, toStr, "latest", "raw", null, null));
|
||||||
|
var threadsFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "jvm.threads.live", "value", fromStr, toStr, "avg", "raw", null, null));
|
||||||
|
var dropsFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "cameleer.ingestion.drops", "count", fromStr, toStr, "sum", "delta", null, null));
|
||||||
|
var bufferFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "cameleer.ingestion.buffer.size", "value", fromStr, toStr, "sum", "raw", null, null));
|
||||||
|
var httpTotalFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "http.server.requests", "count", fromStr, toStr, "sum", "delta", null, null));
|
||||||
|
var http5xxFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "http.server.requests", "count", fromStr, toStr, "sum", "delta", null, Map.of("outcome", "SERVER_ERROR")));
|
||||||
|
var authFuture = CompletableFuture.supplyAsync(() ->
|
||||||
|
query(serverEndpoint, "cameleer.auth.failures", "count", fromStr, toStr, "sum", "delta", null, null));
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Extract latest values from each response
|
||||||
|
var agentsResp = agentsFuture.join();
|
||||||
|
int live = agentStateValue(agentsResp, "live");
|
||||||
|
int stale = agentStateValue(agentsResp, "stale");
|
||||||
|
int dead = agentStateValue(agentsResp, "dead");
|
||||||
|
int shutdown = agentStateValue(agentsResp, "shutdown");
|
||||||
|
|
||||||
|
double cpu = latestValue(cpuFuture.join());
|
||||||
|
long heapUsed = (long) latestValue(heapUsedFuture.join());
|
||||||
|
long heapMax = (long) latestValue(heapMaxFuture.join());
|
||||||
|
long uptimeMs = (long) latestValue(uptimeFuture.join());
|
||||||
|
int threads = (int) latestValue(threadsFuture.join());
|
||||||
|
|
||||||
|
double dropsTotal = sumLatestValues(dropsFuture.join());
|
||||||
|
long bufferDepth = (long) latestValue(bufferFuture.join());
|
||||||
|
|
||||||
|
double httpTotal = sumLatestValues(httpTotalFuture.join());
|
||||||
|
double http5xx = sumLatestValues(http5xxFuture.join());
|
||||||
|
double errorRate = httpTotal > 0 ? http5xx / httpTotal : 0.0;
|
||||||
|
// stepSeconds=300 (5min window), so total is per-5-min; convert to per-minute
|
||||||
|
double httpPerMin = httpTotal / 5.0;
|
||||||
|
|
||||||
|
double authTotal = sumLatestValues(authFuture.join());
|
||||||
|
double authPerMin = authTotal / 5.0;
|
||||||
|
|
||||||
|
return new MetricsSummary(
|
||||||
|
toStr,
|
||||||
|
new AgentMetrics(live, stale, dead, shutdown),
|
||||||
|
new IngestionMetrics(bufferDepth, dropsTotal / 5.0),
|
||||||
|
new ServerJvmMetrics(cpu, heapUsed, heapMax, uptimeMs / 1000, threads),
|
||||||
|
new HttpMetrics(httpPerMin, errorRate),
|
||||||
|
authPerMin
|
||||||
|
);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("Failed to assemble metrics summary for {}: {}", serverEndpoint, e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MetricsQueryResponse query(String endpoint, String metric, String statistic,
|
||||||
|
String from, String to, String aggregation, String mode,
|
||||||
|
List<String> groupByTags, Map<String, String> filterTags) {
|
||||||
|
Map<String, Object> body = new HashMap<>();
|
||||||
|
body.put("metric", metric);
|
||||||
|
body.put("statistic", statistic);
|
||||||
|
body.put("from", from);
|
||||||
|
body.put("to", to);
|
||||||
|
body.put("stepSeconds", 300);
|
||||||
|
body.put("aggregation", aggregation);
|
||||||
|
body.put("mode", mode);
|
||||||
|
if (groupByTags != null) body.put("groupByTags", groupByTags);
|
||||||
|
if (filterTags != null) body.put("filterTags", filterTags);
|
||||||
|
return serverApiClient.queryServerMetrics(endpoint, body);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extract the latest value from the first (or only) series. */
|
||||||
|
private double latestValue(MetricsQueryResponse resp) {
|
||||||
|
if (resp == null || resp.series() == null || resp.series().isEmpty()) return 0.0;
|
||||||
|
List<MetricsPoint> points = resp.series().getFirst().points();
|
||||||
|
if (points == null || points.isEmpty()) return 0.0;
|
||||||
|
return points.getLast().v();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sum the latest value across all series (for metrics with groupByTags or multiple series). */
|
||||||
|
private double sumLatestValues(MetricsQueryResponse resp) {
|
||||||
|
if (resp == null || resp.series() == null || resp.series().isEmpty()) return 0.0;
|
||||||
|
double sum = 0.0;
|
||||||
|
for (MetricsSeries series : resp.series()) {
|
||||||
|
if (series.points() != null && !series.points().isEmpty()) {
|
||||||
|
sum += series.points().getLast().v();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extract the latest value for a specific agent state tag. */
|
||||||
|
private int agentStateValue(MetricsQueryResponse resp, String state) {
|
||||||
|
if (resp == null || resp.series() == null) return 0;
|
||||||
|
for (MetricsSeries series : resp.series()) {
|
||||||
|
if (series.tags() != null && state.equals(series.tags().get("state"))) {
|
||||||
|
if (series.points() != null && !series.points().isEmpty()) {
|
||||||
|
return (int) series.points().getLast().v();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { api } from './client';
|
import { api } from './client';
|
||||||
import type { VendorTenantSummary, VendorTenantDetail, CreateTenantRequest, TenantResponse, LicenseResponse, AuditLogPage, AuditLogFilters } from '../types/api';
|
import type { VendorTenantSummary, VendorTenantDetail, CreateTenantRequest, TenantResponse, LicenseResponse, AuditLogPage, AuditLogFilters, TenantMetricsEntry } from '../types/api';
|
||||||
|
|
||||||
export function useVendorTenants() {
|
export function useVendorTenants() {
|
||||||
return useQuery<VendorTenantSummary[]>({
|
return useQuery<VendorTenantSummary[]>({
|
||||||
@@ -179,3 +179,13 @@ export function useInfraChDetail(tenantId: string) {
|
|||||||
enabled: !!tenantId,
|
enabled: !!tenantId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Tenant Metrics ---
|
||||||
|
|
||||||
|
export function useTenantMetrics() {
|
||||||
|
return useQuery<TenantMetricsEntry[]>({
|
||||||
|
queryKey: ['vendor', 'metrics'],
|
||||||
|
queryFn: () => api.get('/vendor/metrics'),
|
||||||
|
refetchInterval: 60_000,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -109,6 +109,14 @@ export function Layout() {
|
|||||||
>
|
>
|
||||||
Certificates
|
Certificates
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
style={{ padding: '6px 12px 6px 36px', fontSize: 13, cursor: 'pointer',
|
||||||
|
fontWeight: isActive(location, '/vendor/metrics') ? 600 : 400,
|
||||||
|
color: isActive(location, '/vendor/metrics') ? 'var(--amber)' : 'var(--text-muted)' }}
|
||||||
|
onClick={() => navigate('/vendor/metrics')}
|
||||||
|
>
|
||||||
|
Metrics
|
||||||
|
</div>
|
||||||
<div
|
<div
|
||||||
style={{ padding: '6px 12px 6px 36px', fontSize: 13, cursor: 'pointer',
|
style={{ padding: '6px 12px 6px 36px', fontSize: 13, cursor: 'pointer',
|
||||||
fontWeight: isActive(location, '/vendor/infrastructure') ? 600 : 400,
|
fontWeight: isActive(location, '/vendor/infrastructure') ? 600 : 400,
|
||||||
|
|||||||
194
ui/src/pages/vendor/VendorMetricsPage.tsx
vendored
Normal file
194
ui/src/pages/vendor/VendorMetricsPage.tsx
vendored
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
import { Card, KpiStrip, Spinner, Badge } from '@cameleer/design-system';
|
||||||
|
import { Activity } from 'lucide-react';
|
||||||
|
import { useTenantMetrics } from '../../api/vendor-hooks';
|
||||||
|
import { useNavigate } from 'react-router';
|
||||||
|
import type { TenantMetricsEntry, MetricsSummary } from '../../types/api';
|
||||||
|
import { tierColor } from '../../utils/tier';
|
||||||
|
|
||||||
|
function formatBytes(n: number): string {
|
||||||
|
if (n < 1024) return `${n} B`;
|
||||||
|
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`;
|
||||||
|
if (n < 1024 * 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)} MB`;
|
||||||
|
return `${(n / 1024 / 1024 / 1024).toFixed(2)} GB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatUptime(seconds: number): string {
|
||||||
|
const d = Math.floor(seconds / 86400);
|
||||||
|
const h = Math.floor((seconds % 86400) / 3600);
|
||||||
|
const m = Math.floor((seconds % 3600) / 60);
|
||||||
|
if (d > 0) return `${d}d ${h}h`;
|
||||||
|
if (h > 0) return `${h}h ${m}m`;
|
||||||
|
return `${m}m`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatPct(v: number): string {
|
||||||
|
return `${(v * 100).toFixed(1)}%`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatRate(v: number): string {
|
||||||
|
if (v === 0) return '0';
|
||||||
|
if (v < 0.1) return v.toFixed(3);
|
||||||
|
if (v < 10) return v.toFixed(1);
|
||||||
|
return Math.round(v).toLocaleString();
|
||||||
|
}
|
||||||
|
|
||||||
|
const thStyle: React.CSSProperties = {
|
||||||
|
textAlign: 'left',
|
||||||
|
padding: '8px 16px',
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: 600,
|
||||||
|
color: 'var(--text-muted)',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
letterSpacing: '0.05em',
|
||||||
|
borderBottom: '1px solid var(--border)',
|
||||||
|
};
|
||||||
|
|
||||||
|
const tdStyle: React.CSSProperties = {
|
||||||
|
padding: '10px 16px',
|
||||||
|
fontSize: 13,
|
||||||
|
borderBottom: '1px solid var(--border)',
|
||||||
|
fontVariantNumeric: 'tabular-nums',
|
||||||
|
};
|
||||||
|
|
||||||
|
function AgentsBadges({ m }: { m: MetricsSummary }) {
|
||||||
|
const { live, stale, dead } = m.agents;
|
||||||
|
return (
|
||||||
|
<span style={{ display: 'inline-flex', gap: 6 }}>
|
||||||
|
<Badge label={`${live} live`} color="success" />
|
||||||
|
{stale > 0 && <Badge label={`${stale} stale`} color="warning" />}
|
||||||
|
{dead > 0 && <Badge label={`${dead} dead`} color="error" />}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function HeapBar({ used, max }: { used: number; max: number }) {
|
||||||
|
const pct = max > 0 ? (used / max) * 100 : 0;
|
||||||
|
const color = pct > 85 ? 'var(--error, #ef4444)' : pct > 70 ? 'var(--warning, #f59e0b)' : 'var(--success, #22c55e)';
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||||
|
<div style={{ width: 60, height: 6, borderRadius: 3, background: 'var(--border)', overflow: 'hidden' }}>
|
||||||
|
<div style={{ width: `${pct}%`, height: '100%', borderRadius: 3, background: color }} />
|
||||||
|
</div>
|
||||||
|
<span style={{ fontSize: 12, color: 'var(--text-muted)' }}>
|
||||||
|
{formatBytes(used)} / {formatBytes(max)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropsBadge({ rate }: { rate: number }) {
|
||||||
|
if (rate === 0) return <span style={{ color: 'var(--text-muted)' }}>0</span>;
|
||||||
|
return <Badge label={`${formatRate(rate)}/min`} color="error" />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function TenantRow({ entry, onClick }: { entry: TenantMetricsEntry; onClick: () => void }) {
|
||||||
|
const m = entry.metrics;
|
||||||
|
const notRunning = entry.serverState !== 'RUNNING';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<tr style={{ cursor: 'pointer' }} onClick={onClick}>
|
||||||
|
<td style={tdStyle}>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||||
|
<span style={{ fontWeight: 500 }}>{entry.tenantName}</span>
|
||||||
|
<Badge label={entry.tier} color={tierColor(entry.tier)} />
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
{notRunning || !m ? (
|
||||||
|
<td colSpan={6} style={{ ...tdStyle, color: 'var(--text-muted)', textAlign: 'center' }}>
|
||||||
|
{notRunning ? `Server ${entry.serverState.toLowerCase()}` : 'No metrics available'}
|
||||||
|
</td>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<td style={tdStyle}><AgentsBadges m={m} /></td>
|
||||||
|
<td style={{ ...tdStyle, textAlign: 'right' }}>{formatPct(m.server.cpuUsage)}</td>
|
||||||
|
<td style={tdStyle}><HeapBar used={m.server.heapUsedBytes} max={m.server.heapMaxBytes} /></td>
|
||||||
|
<td style={{ ...tdStyle, textAlign: 'right' }}>{formatRate(m.http.requestsPerMinute)}/min</td>
|
||||||
|
<td style={{ ...tdStyle, textAlign: 'center' }}><DropsBadge rate={m.ingestion.dropsPerMinute} /></td>
|
||||||
|
<td style={{ ...tdStyle, textAlign: 'right', color: 'var(--text-muted)' }}>{formatUptime(m.server.uptimeSeconds)}</td>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function FleetKpis({ entries }: { entries: TenantMetricsEntry[] }) {
|
||||||
|
const withMetrics = entries.filter((e) => e.metrics != null);
|
||||||
|
const totalAgentsLive = withMetrics.reduce((s, e) => s + (e.metrics!.agents.live), 0);
|
||||||
|
const totalAgentsDead = withMetrics.reduce((s, e) => s + (e.metrics!.agents.dead), 0);
|
||||||
|
const totalDrops = withMetrics.reduce((s, e) => s + (e.metrics!.ingestion.dropsPerMinute), 0);
|
||||||
|
const running = entries.filter((e) => e.serverState === 'RUNNING').length;
|
||||||
|
const avgCpu = withMetrics.length > 0
|
||||||
|
? withMetrics.reduce((s, e) => s + e.metrics!.server.cpuUsage, 0) / withMetrics.length
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<KpiStrip
|
||||||
|
items={[
|
||||||
|
{ label: 'Tenants Running', value: `${running} / ${entries.length}` },
|
||||||
|
{ label: 'Total Agents Live', value: String(totalAgentsLive) },
|
||||||
|
{ label: 'Dead Agents', value: String(totalAgentsDead) },
|
||||||
|
{ label: 'Avg CPU', value: formatPct(avgCpu) },
|
||||||
|
{ label: 'Ingestion Drops', value: totalDrops === 0 ? '0' : `${formatRate(totalDrops)}/min` },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function VendorMetricsPage() {
|
||||||
|
const { data, isLoading, isError } = useTenantMetrics();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 24, display: 'flex', flexDirection: 'column', gap: 24, maxWidth: 1200 }}>
|
||||||
|
<h1 style={{ margin: 0, fontSize: '1.25rem', fontWeight: 600 }}>Tenant Metrics</h1>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 10, padding: '16px 20px', borderBottom: '1px solid var(--border)' }}>
|
||||||
|
<Activity size={18} style={{ color: 'var(--amber)' }} />
|
||||||
|
<h2 style={{ margin: 0, fontSize: '1rem', fontWeight: 600 }}>Fleet Overview</h2>
|
||||||
|
{isLoading && <Spinner size="sm" />}
|
||||||
|
{isError && <span style={{ fontSize: 13, color: 'var(--error, #ef4444)' }}>Failed to load</span>}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{data && (
|
||||||
|
<>
|
||||||
|
<div style={{ padding: '4px 20px' }}>
|
||||||
|
<FleetKpis entries={data} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style={thStyle}>Tenant</th>
|
||||||
|
<th style={thStyle}>Agents</th>
|
||||||
|
<th style={{ ...thStyle, textAlign: 'right' }}>CPU</th>
|
||||||
|
<th style={thStyle}>Heap</th>
|
||||||
|
<th style={{ ...thStyle, textAlign: 'right' }}>HTTP Req</th>
|
||||||
|
<th style={{ ...thStyle, textAlign: 'center' }}>Drops</th>
|
||||||
|
<th style={{ ...thStyle, textAlign: 'right' }}>Uptime</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{data.length === 0 ? (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={7} style={{ ...tdStyle, color: 'var(--text-muted)', textAlign: 'center' }}>
|
||||||
|
No tenants found
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
) : (
|
||||||
|
data.map((entry) => (
|
||||||
|
<TenantRow
|
||||||
|
key={entry.tenantId}
|
||||||
|
entry={entry}
|
||||||
|
onClick={() => navigate(`/vendor/tenants/${entry.tenantId}`)}
|
||||||
|
/>
|
||||||
|
))
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import { TenantDetailPage } from './pages/vendor/TenantDetailPage';
|
|||||||
import { VendorAuditPage } from './pages/vendor/VendorAuditPage';
|
import { VendorAuditPage } from './pages/vendor/VendorAuditPage';
|
||||||
import { CertificatesPage } from './pages/vendor/CertificatesPage';
|
import { CertificatesPage } from './pages/vendor/CertificatesPage';
|
||||||
import { InfrastructurePage } from './pages/vendor/InfrastructurePage';
|
import { InfrastructurePage } from './pages/vendor/InfrastructurePage';
|
||||||
|
import { VendorMetricsPage } from './pages/vendor/VendorMetricsPage';
|
||||||
import { TenantDashboardPage } from './pages/tenant/TenantDashboardPage';
|
import { TenantDashboardPage } from './pages/tenant/TenantDashboardPage';
|
||||||
import { TenantLicensePage } from './pages/tenant/TenantLicensePage';
|
import { TenantLicensePage } from './pages/tenant/TenantLicensePage';
|
||||||
import { SsoPage } from './pages/tenant/SsoPage';
|
import { SsoPage } from './pages/tenant/SsoPage';
|
||||||
@@ -82,6 +83,11 @@ export function AppRouter() {
|
|||||||
<CertificatesPage />
|
<CertificatesPage />
|
||||||
</RequireScope>
|
</RequireScope>
|
||||||
} />
|
} />
|
||||||
|
<Route path="/vendor/metrics" element={
|
||||||
|
<RequireScope scope="platform:admin" fallback={<Navigate to="/tenant" replace />}>
|
||||||
|
<VendorMetricsPage />
|
||||||
|
</RequireScope>
|
||||||
|
} />
|
||||||
<Route path="/vendor/infrastructure" element={
|
<Route path="/vendor/infrastructure" element={
|
||||||
<RequireScope scope="platform:admin" fallback={<Navigate to="/tenant" replace />}>
|
<RequireScope scope="platform:admin" fallback={<Navigate to="/tenant" replace />}>
|
||||||
<InfrastructurePage />
|
<InfrastructurePage />
|
||||||
|
|||||||
@@ -155,3 +155,48 @@ export interface AuditLogFilters {
|
|||||||
page?: number;
|
page?: number;
|
||||||
size?: number;
|
size?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tenant metrics (from server /api/v1/admin/metrics/summary)
|
||||||
|
export interface AgentMetrics {
|
||||||
|
live: number;
|
||||||
|
stale: number;
|
||||||
|
dead: number;
|
||||||
|
shutdown: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IngestionMetrics {
|
||||||
|
bufferDepth: number;
|
||||||
|
dropsPerMinute: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServerMetrics {
|
||||||
|
cpuUsage: number;
|
||||||
|
heapUsedBytes: number;
|
||||||
|
heapMaxBytes: number;
|
||||||
|
uptimeSeconds: number;
|
||||||
|
threadCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface HttpMetrics {
|
||||||
|
requestsPerMinute: number;
|
||||||
|
errorRate: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MetricsSummary {
|
||||||
|
collectedAt: string;
|
||||||
|
agents: AgentMetrics;
|
||||||
|
ingestion: IngestionMetrics;
|
||||||
|
server: ServerMetrics;
|
||||||
|
http: HttpMetrics;
|
||||||
|
authFailuresPerMinute: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TenantMetricsEntry {
|
||||||
|
tenantId: string;
|
||||||
|
tenantName: string;
|
||||||
|
slug: string;
|
||||||
|
tier: string;
|
||||||
|
status: string;
|
||||||
|
serverState: string;
|
||||||
|
metrics: MetricsSummary | null;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user