perfor-monitor
Version:
性能监控工具库
102 lines (101 loc) • 2.79 kB
TypeScript
/**
* RadarReport - Enhanced frontend monitoring data reporting class
* Handles reliable data transmission with queue management, batching, and retry mechanisms
*/
export declare class RadarReport<T extends unknown = {}> {
private queue;
private sending;
private retryQueue;
private retryAttempts;
private maxRetries;
private maxQueueSize;
private maxRetryQueueSize;
private batchSize;
private processingTimeout;
private readonly STORAGE_KEY;
reportUrl: string;
constructor(config?: {
reportUrl?: string;
maxRetries?: number;
maxQueueSize?: number;
maxRetryQueueSize?: number;
batchSize?: number;
});
/**
* Public method to report monitoring data
* @param data The data to report
* @param priority Optional priority level (higher = more important)
*/
report(data: T, priority?: number): void;
/**
* Schedule queue processing with debounce to avoid frequent processing
*/
private scheduleQueueProcessing;
/**
* Process the queue in chunks to avoid blocking the main thread
*/
private processQueue;
/**
* Process a chunk of the queue to avoid long-running operations
*/
private processQueueChunk;
/**
* Send a batch of data with error handling
*/
private sendBatch;
/**
* Handle send errors with progressive retry and fallback strategies
*/
private handleSendError;
/**
* Store data offline when network requests fail permanently
*/
private storeOfflineData;
/**
* Get offline data from localStorage
*/
private getOfflineData;
/**
* Recover offline data on initialization
*/
private recoverOfflineData;
/**
* Persist any pending data when page unloads
*/
private persistOfflineData;
/**
* Find the index of the lowest priority item in the queue
*/
private findLowestPriorityItemIndex;
/**
* Generate a truly unique ID for batch tracking
*/
private generateUniqueId;
/**
* Get current queue statistics for monitoring
*/
getQueueStats(): {
mainQueue: number;
retryQueue: number;
activeSending: boolean;
offlineData: number;
configuration: {
batchSize: number;
maxQueueSize: number;
maxRetryQueueSize: number;
maxRetries: number;
};
};
/**
* Get count of offline data items
*/
private getOfflineDataCount;
/**
* Manually flush all queues (useful for testing or before page unload)
*/
flush(): Promise<void>;
/**
* Clear all queues and offline data (useful for testing or user opt-out)
*/
clear(): void;
}