2.2.0 • Published 6 months ago
@jerome778/perf-monitor-sdk v2.2.0
Performance Monitor SDK
A lightweight SDK for monitoring HTTP request performance in web applications.
Features
- Monitor fetch and XMLHttpRequest performance
- Detect blocked requests
- Batch reporting
- TypeScript support
- Zero dependencies
- Easy integration
Installation
npm install jerome778-perf-monitor-sdk
# or
yarn add jerome778-perf-monitor-sdk
# or
pnpm add jerome778-perf-monitor-sdk
Usage
import PerfMonitor from 'jerome778-perf-monitor-sdk';
const monitor = new PerfMonitor({
serverUrl: 'http://your-server-url',
appId: 'your-app-id',
// Optional configuration
batchSize: 10, // Number of records to batch before sending
flushInterval: 5000 // Flush interval in milliseconds
});
Configuration
Option | Type | Required | Default | Description |
---|---|---|---|---|
serverUrl | string | Yes | - | The URL of your performance monitoring server |
appId | string | Yes | - | Your application ID |
batchSize | number | No | 10 | Number of records to batch before sending |
flushInterval | number | No | 5000 | Flush interval in milliseconds |
Data Format
The SDK collects the following data for each request:
interface PerformanceData {
appId: string; // Your application ID
url: string; // Request URL
method: string; // HTTP method
startTime: number; // Request start timestamp
duration: number; // Request duration in milliseconds
status: number; // HTTP status code
isBlocked: boolean; // Whether the request was blocked
blockDuration?: number; // Duration of blocking if blocked
timestamp: number; // Record timestamp
}
API
Constructor
new PerfMonitor(config: PerfMonitorConfig)
Methods
destroy()
Cleans up the monitor and sends any remaining data.
monitor.destroy();
Browser Support
- Chrome
- Firefox
- Safari
- Edge
- IE11+ (with appropriate polyfills)
License
MIT