feat(monitoring,network-ui,routes): add request-based domain activity metrics and split routes into user and system views
This commit is contained in:
@@ -560,7 +560,7 @@ export class MetricsManager {
|
||||
requestsPerSecond: 0,
|
||||
requestsTotal: 0,
|
||||
backends: [] as Array<any>,
|
||||
domainActivity: [] as Array<{ domain: string; bytesInPerSecond: number; bytesOutPerSecond: number; activeConnections: number; routeCount: number }>,
|
||||
domainActivity: [] as Array<{ domain: string; bytesInPerSecond: number; bytesOutPerSecond: number; activeConnections: number; routeCount: number; requestCount: number }>,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -720,11 +720,20 @@ export class MetricsManager {
|
||||
.slice(0, 10)
|
||||
.map(([ip, data]) => ({ ip, count: data.count, bwIn: data.bwIn, bwOut: data.bwOut }));
|
||||
|
||||
// Build domain activity from per-route metrics
|
||||
// Build domain activity using per-IP domain request counts from Rust engine
|
||||
const connectionsByRoute = proxyMetrics.connections.byRoute();
|
||||
const throughputByRoute = proxyMetrics.throughput.byRoute();
|
||||
|
||||
// Map route name → ALL its domains (not just the first one)
|
||||
// Aggregate per-IP domain request counts into per-domain totals
|
||||
const domainRequestTotals = new Map<string, number>();
|
||||
const domainRequestsByIP = proxyMetrics.connections.domainRequestsByIP();
|
||||
for (const [, domainMap] of domainRequestsByIP) {
|
||||
for (const [domain, count] of domainMap) {
|
||||
domainRequestTotals.set(domain, (domainRequestTotals.get(domain) || 0) + count);
|
||||
}
|
||||
}
|
||||
|
||||
// Map route name → domains from route config
|
||||
const routeDomains = new Map<string, string[]>();
|
||||
if (this.dcRouter.smartProxy) {
|
||||
for (const route of this.dcRouter.smartProxy.routeManager.getRoutes()) {
|
||||
@@ -738,34 +747,26 @@ export class MetricsManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Use protocol cache to discover actual active domains (resolves wildcards)
|
||||
const activeDomains = new Set<string>();
|
||||
const domainToBackend = new Map<string, string>(); // domain → host:port
|
||||
// Resolve wildcards using domains seen in request metrics
|
||||
const allKnownDomains = new Set<string>(domainRequestTotals.keys());
|
||||
for (const entry of protocolCache) {
|
||||
if (entry.domain) {
|
||||
activeDomains.add(entry.domain);
|
||||
domainToBackend.set(entry.domain, `${entry.host}:${entry.port}`);
|
||||
}
|
||||
if (entry.domain) allKnownDomains.add(entry.domain);
|
||||
}
|
||||
|
||||
// Build reverse map: domain → route name(s) that handle it
|
||||
// For concrete domains: direct lookup from route config
|
||||
// For wildcard patterns: match active domains from protocol cache
|
||||
// Build reverse map: concrete domain → route name(s)
|
||||
const domainToRoutes = new Map<string, string[]>();
|
||||
for (const [routeName, domains] of routeDomains) {
|
||||
for (const pattern of domains) {
|
||||
if (pattern.includes('*')) {
|
||||
// Wildcard pattern — match against active domains from protocol cache
|
||||
const regex = new RegExp('^' + pattern.replace(/\./g, '\\.').replace(/\*/g, '[^.]+') + '$');
|
||||
for (const activeDomain of activeDomains) {
|
||||
if (regex.test(activeDomain)) {
|
||||
const existing = domainToRoutes.get(activeDomain);
|
||||
for (const knownDomain of allKnownDomains) {
|
||||
if (regex.test(knownDomain)) {
|
||||
const existing = domainToRoutes.get(knownDomain);
|
||||
if (existing) { existing.push(routeName); }
|
||||
else { domainToRoutes.set(activeDomain, [routeName]); }
|
||||
else { domainToRoutes.set(knownDomain, [routeName]); }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Concrete domain
|
||||
const existing = domainToRoutes.get(pattern);
|
||||
if (existing) { existing.push(routeName); }
|
||||
else { domainToRoutes.set(pattern, [routeName]); }
|
||||
@@ -773,20 +774,28 @@ export class MetricsManager {
|
||||
}
|
||||
}
|
||||
|
||||
// Aggregate metrics per domain
|
||||
// For each domain, sum metrics from all routes that serve it,
|
||||
// divided by the number of domains each route serves
|
||||
// For each route, compute the total request count across all its resolved domains
|
||||
// so we can distribute throughput/connections proportionally
|
||||
const routeTotalRequests = new Map<string, number>();
|
||||
for (const [domain, routeNames] of domainToRoutes) {
|
||||
const reqs = domainRequestTotals.get(domain) || 0;
|
||||
for (const routeName of routeNames) {
|
||||
routeTotalRequests.set(routeName, (routeTotalRequests.get(routeName) || 0) + reqs);
|
||||
}
|
||||
}
|
||||
|
||||
// Aggregate metrics per domain using request-count-proportional splitting
|
||||
const domainAgg = new Map<string, {
|
||||
activeConnections: number;
|
||||
bytesInPerSec: number;
|
||||
bytesOutPerSec: number;
|
||||
routeCount: number;
|
||||
requestCount: number;
|
||||
}>();
|
||||
|
||||
// Track which routes are accounted for
|
||||
const accountedRoutes = new Set<string>();
|
||||
|
||||
for (const [domain, routeNames] of domainToRoutes) {
|
||||
const domainReqs = domainRequestTotals.get(domain) || 0;
|
||||
let totalConns = 0;
|
||||
let totalIn = 0;
|
||||
let totalOut = 0;
|
||||
@@ -795,15 +804,25 @@ export class MetricsManager {
|
||||
accountedRoutes.add(routeName);
|
||||
const conns = connectionsByRoute.get(routeName) || 0;
|
||||
const tp = throughputByRoute.get(routeName) || { in: 0, out: 0 };
|
||||
// Count how many resolved domains share this route
|
||||
let domainsInRoute = 0;
|
||||
for (const [, routes] of domainToRoutes) {
|
||||
if (routes.includes(routeName)) domainsInRoute++;
|
||||
const routeTotal = routeTotalRequests.get(routeName) || 0;
|
||||
|
||||
// Proportional share based on actual request counts
|
||||
// Fall back to equal split only when no request data exists
|
||||
let share: number;
|
||||
if (routeTotal > 0 && domainReqs > 0) {
|
||||
share = domainReqs / routeTotal;
|
||||
} else {
|
||||
// Count how many resolved domains share this route
|
||||
let domainsInRoute = 0;
|
||||
for (const [, routes] of domainToRoutes) {
|
||||
if (routes.includes(routeName)) domainsInRoute++;
|
||||
}
|
||||
share = 1 / Math.max(domainsInRoute, 1);
|
||||
}
|
||||
const share = Math.max(domainsInRoute, 1);
|
||||
totalConns += conns / share;
|
||||
totalIn += tp.in / share;
|
||||
totalOut += tp.out / share;
|
||||
|
||||
totalConns += conns * share;
|
||||
totalIn += tp.in * share;
|
||||
totalOut += tp.out * share;
|
||||
}
|
||||
|
||||
domainAgg.set(domain, {
|
||||
@@ -811,13 +830,14 @@ export class MetricsManager {
|
||||
bytesInPerSec: totalIn,
|
||||
bytesOutPerSec: totalOut,
|
||||
routeCount: routeNames.length,
|
||||
requestCount: domainReqs,
|
||||
});
|
||||
}
|
||||
|
||||
// Include routes with no domain config (fallback: use route name)
|
||||
for (const [routeName, activeConns] of connectionsByRoute) {
|
||||
if (accountedRoutes.has(routeName)) continue;
|
||||
if (routeDomains.has(routeName)) continue; // has domains but no traffic matched
|
||||
if (routeDomains.has(routeName)) continue;
|
||||
const tp = throughputByRoute.get(routeName) || { in: 0, out: 0 };
|
||||
if (activeConns === 0 && tp.in === 0 && tp.out === 0) continue;
|
||||
const existing = domainAgg.get(routeName);
|
||||
@@ -832,6 +852,7 @@ export class MetricsManager {
|
||||
bytesInPerSec: tp.in,
|
||||
bytesOutPerSec: tp.out,
|
||||
routeCount: 1,
|
||||
requestCount: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -843,6 +864,7 @@ export class MetricsManager {
|
||||
bytesOutPerSecond: data.bytesOutPerSec,
|
||||
activeConnections: data.activeConnections,
|
||||
routeCount: data.routeCount,
|
||||
requestCount: data.requestCount,
|
||||
}))
|
||||
.sort((a, b) => (b.bytesInPerSecond + b.bytesOutPerSecond) - (a.bytesInPerSecond + a.bytesOutPerSecond));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user