datapilot-cli
Version:
Enterprise-grade streaming multi-format data analysis with comprehensive statistical insights and intelligent relationship detection - supports CSV, JSON, Excel, TSV, Parquet - memory-efficient, cross-platform
236 lines • 6.53 kB
TypeScript
/**
* Advanced Metrics Collection and Aggregation System for DataPilot
* Collects, processes, and aggregates performance metrics for production monitoring
*/
import { EventEmitter } from 'events';
import type { LogContext } from '../utils/logger';
export interface MetricValue {
value: number;
timestamp: number;
labels?: Record<string, string>;
}
export interface MetricSummary {
name: string;
type: MetricType;
description: string;
unit: string;
currentValue: number;
aggregations: {
min: number;
max: number;
avg: number;
p50: number;
p95: number;
p99: number;
sum: number;
count: number;
};
labels?: Record<string, string>;
lastUpdated: number;
}
export interface TimeSeries {
metric: string;
values: MetricValue[];
retention: number;
}
export declare enum MetricType {
COUNTER = "counter",
GAUGE = "gauge",
HISTOGRAM = "histogram",
SUMMARY = "summary"
}
export interface MetricConfig {
name: string;
type: MetricType;
description: string;
unit: string;
labels?: string[];
buckets?: number[];
retention?: number;
aggregationWindow?: number;
}
export interface SystemMetrics {
timestamp: number;
system: {
uptime: number;
memory: {
total: number;
used: number;
free: number;
heapTotal: number;
heapUsed: number;
external: number;
rss: number;
};
cpu: {
usage: number;
loadAverage: number[];
};
process: {
pid: number;
ppid: number;
platform: string;
arch: string;
version: string;
};
};
application: {
requestsTotal: number;
requestsPerSecond: number;
responseTimeMs: {
avg: number;
p95: number;
p99: number;
};
errorsTotal: number;
errorRate: number;
dataProcessing: {
rowsProcessed: number;
filesProcessed: number;
bytesProcessed: number;
processingRate: number;
};
sections: {
section1: SectionMetrics;
section2: SectionMetrics;
section3: SectionMetrics;
section4: SectionMetrics;
section5: SectionMetrics;
section6: SectionMetrics;
};
};
}
export interface SectionMetrics {
executionCount: number;
totalDuration: number;
avgDuration: number;
maxDuration: number;
errorCount: number;
successRate: number;
lastExecution: number;
}
/**
* Production metrics collection and aggregation system
*/
export declare class MetricsCollector extends EventEmitter {
private static instance;
private metrics;
private configs;
private aggregations;
private isCollecting;
private collectionInterval?;
private aggregationInterval?;
private startTime;
private sectionMetrics;
private requestCount;
private errorCount;
private responseTimes;
private dataProcessingStats;
private constructor();
static getInstance(): MetricsCollector;
/**
* Register a new metric
*/
registerMetric(config: MetricConfig): void;
/**
* Record a metric value
*/
recordMetric(name: string, value: number, labels?: Record<string, string>, timestamp?: number): void;
/**
* Increment a counter metric
*/
incrementCounter(name: string, amount?: number, labels?: Record<string, string>): void;
/**
* Set a gauge metric
*/
setGauge(name: string, value: number, labels?: Record<string, string>): void;
/**
* Record a histogram value
*/
recordHistogram(name: string, value: number, labels?: Record<string, string>): void;
/**
* Record timing information
*/
recordTiming(name: string, startTime: number, labels?: Record<string, string>): void;
/**
* Start timing operation
*/
startTimer(name: string): () => void;
/**
* Record section execution metrics
*/
recordSectionExecution(sectionName: string, duration: number, success: boolean, context?: LogContext): void;
/**
* Record data processing metrics
*/
recordDataProcessing(rowsProcessed: number, bytesProcessed: number, fileProcessed?: boolean): void;
/**
* Record request metrics
*/
recordRequest(responseTime: number, success: boolean): void;
/**
* Get current system metrics
*/
getSystemMetrics(): Promise<SystemMetrics>;
/**
* Get metric summary with aggregations
*/
getMetricSummary(name: string): MetricSummary | undefined;
/**
* Get all metric summaries
*/
getAllMetricSummaries(): MetricSummary[];
/**
* Export metrics in Prometheus format
*/
exportPrometheusMetrics(): string;
/**
* Export metrics in JSON format
*/
exportJSONMetrics(): any;
/**
* Start automatic metrics collection
*/
startCollection(intervalMs?: number): void;
/**
* Stop metrics collection
*/
stopCollection(): void;
/**
* Reset all metrics
*/
reset(): void;
/**
* Dispose of the metrics collector
*/
dispose(): void;
private collectSystemMetrics;
private aggregateMetrics;
private cleanupTimeSeries;
private calculatePercentile;
private getDefaultSectionMetrics;
private initializeDefaultMetrics;
private initializeSectionMetrics;
}
/**
* Global metrics collector instance
*/
export declare const globalMetricsCollector: MetricsCollector;
/**
* Metrics collection utilities
*/
export declare class MetricsUtils {
/**
* Create a timing decorator for automatic duration tracking
*/
static timing(metricName: string, labels?: Record<string, string>): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
/**
* Create a counter decorator for automatic counting
*/
static counter(metricName: string, labels?: Record<string, string>): (target: any, propertyName: string, descriptor: PropertyDescriptor) => void;
/**
* Create metrics for data processing operations
*/
static recordDataOperation(operationType: string, rowCount: number, byteCount: number, duration: number, success: boolean): void;
}
//# sourceMappingURL=metrics-collector.d.ts.map