UNPKG

@j03fr0st/pubg-ts

Version:

A comprehensive TypeScript wrapper for the PUBG API

143 lines 3.63 kB
export interface MonitoringConfig { enabled: boolean; metricsEnabled: boolean; tracingEnabled: boolean; healthCheckEnabled: boolean; collectDefaultMetrics: boolean; prefix: string; } export interface RequestMetrics { duration: number; statusCode?: number; endpoint?: string; method?: string; error?: boolean; } export interface SystemHealth { status: 'healthy' | 'degraded' | 'unhealthy'; timestamp: number; uptime: number; memory: { used: number; total: number; percentage: number; }; api: { status: 'healthy' | 'degraded' | 'unhealthy'; responseTime: number; errorRate: number; }; cache: { hitRate: number; size: number; maxSize: number; }; rateLimit: { remaining: number; limit: number; resetTime: number; }; } /** * Production-ready monitoring and observability system * * Provides comprehensive monitoring capabilities including: * - Prometheus metrics collection * - OpenTelemetry distributed tracing * - Health checks and system monitoring * - Performance tracking and alerting * * @example * ```typescript * const monitor = new MonitoringSystem({ * enabled: true, * metricsEnabled: true, * tracingEnabled: true, * prefix: 'pubg_sdk' * }); * * // Track API requests * const span = monitor.startSpan('api_request', { endpoint: '/players' }); * try { * const result = await apiCall(); * monitor.recordRequestMetrics({ * duration: 150, * statusCode: 200, * endpoint: '/players' * }); * span.setStatus({ code: SpanStatusCode.OK }); * } catch (error) { * monitor.recordError(error); * span.recordException(error as Error); * span.setStatus({ code: SpanStatusCode.ERROR }); * } finally { * span.end(); * } * ``` */ export declare class MonitoringSystem { private config; private registry; private tracer; private requestCounter; private requestDuration; private errorCounter; private cacheHitRate; private activeConnections; private rateLimitRemaining; private memoryUsage; private healthStatus; private startTime; private lastHealthCheck; constructor(config?: Partial<MonitoringConfig>); private initializeMetrics; private initializeTracing; private startHealthChecking; /** * Start a new tracing span */ startSpan(name: string, attributes?: Record<string, any>): any; /** * Record request metrics */ recordRequestMetrics(metrics: RequestMetrics): void; /** * Record error occurrences */ recordError(error: Error, context?: Record<string, any>): void; /** * Update cache metrics */ updateCacheMetrics(hitRate: number): void; /** * Update rate limit metrics */ updateRateLimitMetrics(remaining: number): void; /** * Update connection metrics */ updateConnectionMetrics(active: number): void; /** * Get current system health */ getHealth(): Promise<SystemHealth>; /** * Get Prometheus metrics */ getMetrics(): Promise<string>; /** * Perform comprehensive health check */ private performHealthCheck; private measureApiResponseTime; private calculateErrorRate; private getCacheHitRate; private getRateLimitRemaining; private getStatusClass; /** * Shutdown monitoring system gracefully */ shutdown(): void; } export declare const monitoringSystem: MonitoringSystem; //# sourceMappingURL=monitoring.d.ts.map