fix(metrics): improve metrics
This commit is contained in:
@ -1,54 +1,106 @@
|
||||
/**
|
||||
* Interface for proxy statistics and metrics
|
||||
* Interface for throughput sample data
|
||||
*/
|
||||
export interface IProxyStats {
|
||||
/**
|
||||
* Get the current number of active connections
|
||||
*/
|
||||
getActiveConnections(): number;
|
||||
|
||||
/**
|
||||
* Get connection counts grouped by route name
|
||||
*/
|
||||
getConnectionsByRoute(): Map<string, number>;
|
||||
|
||||
/**
|
||||
* Get connection counts grouped by IP address
|
||||
*/
|
||||
getConnectionsByIP(): Map<string, number>;
|
||||
|
||||
/**
|
||||
* Get the total number of connections since proxy start
|
||||
*/
|
||||
getTotalConnections(): number;
|
||||
|
||||
/**
|
||||
* Get the current requests per second rate
|
||||
*/
|
||||
getRequestsPerSecond(): number;
|
||||
|
||||
/**
|
||||
* Get total throughput (bytes transferred)
|
||||
*/
|
||||
getThroughput(): { bytesIn: number; bytesOut: number };
|
||||
export interface IThroughputSample {
|
||||
timestamp: number;
|
||||
bytesIn: number;
|
||||
bytesOut: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extended interface for additional metrics helpers
|
||||
* Interface for throughput data
|
||||
*/
|
||||
export interface IProxyStatsExtended extends IProxyStats {
|
||||
/**
|
||||
* Get throughput rate (bytes per second) for last minute
|
||||
*/
|
||||
getThroughputRate(): { bytesInPerSec: number; bytesOutPerSec: number };
|
||||
export interface IThroughputData {
|
||||
in: number;
|
||||
out: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface for time-series throughput data
|
||||
*/
|
||||
export interface IThroughputHistoryPoint {
|
||||
timestamp: number;
|
||||
in: number;
|
||||
out: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main metrics interface with clean, grouped API
|
||||
*/
|
||||
export interface IMetrics {
|
||||
// Connection metrics
|
||||
connections: {
|
||||
active(): number;
|
||||
total(): number;
|
||||
byRoute(): Map<string, number>;
|
||||
byIP(): Map<string, number>;
|
||||
topIPs(limit?: number): Array<{ ip: string; count: number }>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get top IPs by connection count
|
||||
*/
|
||||
getTopIPs(limit?: number): Array<{ ip: string; connections: number }>;
|
||||
// Throughput metrics (bytes per second)
|
||||
throughput: {
|
||||
instant(): IThroughputData; // Last 1 second
|
||||
recent(): IThroughputData; // Last 10 seconds
|
||||
average(): IThroughputData; // Last 60 seconds
|
||||
custom(seconds: number): IThroughputData;
|
||||
history(seconds: number): Array<IThroughputHistoryPoint>;
|
||||
byRoute(windowSeconds?: number): Map<string, IThroughputData>;
|
||||
byIP(windowSeconds?: number): Map<string, IThroughputData>;
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if an IP has reached the connection limit
|
||||
*/
|
||||
isIPBlocked(ip: string, maxConnectionsPerIP: number): boolean;
|
||||
// Request metrics
|
||||
requests: {
|
||||
perSecond(): number;
|
||||
perMinute(): number;
|
||||
total(): number;
|
||||
};
|
||||
|
||||
// Cumulative totals
|
||||
totals: {
|
||||
bytesIn(): number;
|
||||
bytesOut(): number;
|
||||
connections(): number;
|
||||
};
|
||||
|
||||
// Performance metrics
|
||||
percentiles: {
|
||||
connectionDuration(): { p50: number; p95: number; p99: number };
|
||||
bytesTransferred(): {
|
||||
in: { p50: number; p95: number; p99: number };
|
||||
out: { p50: number; p95: number; p99: number };
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for metrics collection
|
||||
*/
|
||||
export interface IMetricsConfig {
|
||||
enabled: boolean;
|
||||
|
||||
// Sampling configuration
|
||||
sampleIntervalMs: number; // Default: 1000 (1 second)
|
||||
retentionSeconds: number; // Default: 3600 (1 hour)
|
||||
|
||||
// Performance tuning
|
||||
enableDetailedTracking: boolean; // Per-connection byte history
|
||||
enablePercentiles: boolean; // Calculate percentiles
|
||||
cacheResultsMs: number; // Cache expensive calculations
|
||||
|
||||
// Export configuration
|
||||
prometheusEnabled: boolean;
|
||||
prometheusPath: string; // Default: /metrics
|
||||
prometheusPrefix: string; // Default: smartproxy_
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal interface for connection byte tracking
|
||||
*/
|
||||
export interface IByteTracker {
|
||||
connectionId: string;
|
||||
routeName: string;
|
||||
remoteIP: string;
|
||||
bytesIn: number;
|
||||
bytesOut: number;
|
||||
lastUpdate: number;
|
||||
}
|
Reference in New Issue
Block a user