2.2.0 • Published 6 months ago

@jerome778/perf-monitor-sdk v2.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

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

OptionTypeRequiredDefaultDescription
serverUrlstringYes-The URL of your performance monitoring server
appIdstringYes-Your application ID
batchSizenumberNo10Number of records to batch before sending
flushIntervalnumberNo5000Flush 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

2.2.0

6 months ago

2.1.0

6 months ago

1.0.0

6 months ago