feat: Implement network metrics integration and UI updates for real-time data display
This commit is contained in:
@ -285,4 +285,61 @@ export class MetricsManager {
|
||||
public trackPhishingDetected(): void {
|
||||
this.securityMetrics.phishingDetected++;
|
||||
}
|
||||
|
||||
// Get network metrics from SmartProxy
|
||||
public async getNetworkStats() {
|
||||
const proxyStats = this.dcRouter.smartProxy ? this.dcRouter.smartProxy.getStats() : null;
|
||||
|
||||
if (!proxyStats) {
|
||||
return {
|
||||
connectionsByIP: new Map<string, number>(),
|
||||
throughputRate: { bytesInPerSecond: 0, bytesOutPerSecond: 0 },
|
||||
topIPs: [],
|
||||
totalDataTransferred: { bytesIn: 0, bytesOut: 0 },
|
||||
};
|
||||
}
|
||||
|
||||
// Get unused SmartProxy metrics
|
||||
const connectionsByIP = proxyStats.getConnectionsByIP();
|
||||
const throughput = proxyStats.getThroughput();
|
||||
|
||||
// Check if extended methods exist and call them
|
||||
const throughputRate = ('getThroughputRate' in proxyStats && typeof proxyStats.getThroughputRate === 'function')
|
||||
? (() => {
|
||||
const rate = (proxyStats as any).getThroughputRate();
|
||||
return {
|
||||
bytesInPerSecond: rate.bytesInPerSec || 0,
|
||||
bytesOutPerSecond: rate.bytesOutPerSec || 0
|
||||
};
|
||||
})()
|
||||
: { bytesInPerSecond: 0, bytesOutPerSecond: 0 };
|
||||
|
||||
const topIPs: Array<{ ip: string; count: number }> = [];
|
||||
|
||||
// Check if getTopIPs method exists
|
||||
if ('getTopIPs' in proxyStats && typeof proxyStats.getTopIPs === 'function') {
|
||||
const ips = (proxyStats as any).getTopIPs(10);
|
||||
if (Array.isArray(ips)) {
|
||||
ips.forEach(ipData => {
|
||||
topIPs.push({ ip: ipData.ip, count: ipData.connections || ipData.count || 0 });
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Fallback: Convert connectionsByIP to topIPs manually
|
||||
if (connectionsByIP && connectionsByIP.size > 0) {
|
||||
const ipArray = Array.from(connectionsByIP.entries())
|
||||
.map(([ip, count]) => ({ ip, count }))
|
||||
.sort((a, b) => b.count - a.count)
|
||||
.slice(0, 10);
|
||||
topIPs.push(...ipArray);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
connectionsByIP,
|
||||
throughputRate,
|
||||
topIPs,
|
||||
totalDataTransferred: throughput,
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user