npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mts-pjsc/bretrics

v1.0.14

Published

Web Monitoring

Readme

Bretrics

Codacy Badge npm version License: MIT Contributor Covenant

A lightweight TypeScript library for Real User Monitoring (RUM) that collects browser performance metrics and sends them to a Prometheus-compatible backend.

Overview

Bretrics enables you to monitor the performance of your web applications from the perspective of real users. It collects Core Web Vitals, custom performance metrics, and business metrics, then transmits them to your metrics collection endpoint using the efficient navigator.sendBeacon API.

Features

  • Core Web Vitals: Collects LCP, CLS, FCP, INP, and TTFB metrics from the Web Vitals initiative
  • Custom Metrics: Track application-specific performance indicators
  • Business Metrics: Monitor conversion funnels and user behavior
  • Prometheus Labels: Attach metadata to metrics for detailed analysis
  • Device Detection: Automatic classification of desktop, mobile, and tablet devices
  • Lightweight: Minimal bundle size with zero runtime dependencies beyond web-vitals
  • TypeScript: Full type safety and IntelliSense support
  • Extensible: OOP-based architecture allows custom implementations

Installation

npm install @mts-pjsc/bretrics
yarn add @mts-pjsc/bretrics
pnpm add @mts-pjsc/bretrics

Quick Start

import { bretrics } from "@mts-pjsc/bretrics";

bretrics
    .setup({ apiPath: "/bretrics" })
    .useDefaultMonitoring();

This configuration enables automatic collection of:

  • Core Web Vitals (LCP, CLS, FCP, INP, TTFB)
  • DOM element count
  • Device type detection
  • Current page path

Usage

Basic Configuration

import { bretrics } from "@mts-pjsc/bretrics";

bretrics
    .setup({ apiPath: "/api/metrics" })
    .useDefaultMonitoring()
    .sendMetrics({ custom_metric: 42 });

Adding Labels

Labels provide additional context for metric aggregation and filtering in Prometheus.

import { bretrics } from "@mts-pjsc/bretrics";

bretrics
    .setup({ apiPath: "/bretrics" })
    .useDefaultMonitoring()
    .setLabels({
        environment: "production",
        version: "2.1.0"
    })
    .sendMetrics({
        page_load_time: 1250,
        api_response_time: {
            value: 340,
            labels: { endpoint: "/api/users" }
        }
    });

Extending the Library

For advanced use cases, extend the Bretrics class to implement custom behavior.

import { Bretrics } from "@mts-pjsc/bretrics";

export class CustomMetricsService extends Bretrics {

    public override sendMetrics(metrics: Record<string, number>): this {
        // Add preprocessing logic
        const enrichedMetrics = this.enrichMetrics(metrics);

        super.sendMetrics(enrichedMetrics);

        return this;
    }

    private enrichMetrics(metrics: Record<string, number>): Record<string, number> {
        return {
            ...metrics,
            timestamp: Date.now()
        };
    }
}

export const metricsService = new CustomMetricsService();

API Reference

Class: Bretrics

Properties

| Property | Type | Default | Description | |----------|------|---------|-------------| | apiPath | string | "/bretrics" | Endpoint path for metrics submission | | labels | Record<string, number \| string> | {} | Default labels applied to all metrics |

Methods

| Method | Returns | Description | |--------|---------|-------------| | setup(config) | this | Configure the instance with custom settings | | useDefaultMonitoring() | this | Enable automatic Web Vitals and DOM metrics collection | | useDefaultLabels() | this | Set default labels (device_type, path) | | sendWebVitalsMetrics() | this | Subscribe to Web Vitals events | | sendMetrics(metrics) | this | Send custom metrics to the backend | | setLabels(labels) | this | Add or update metric labels |

Interface: IMetric

interface IMetric {
    value: number;
    labels: Record<string, number | string>;
}

Collected Metrics

Core Web Vitals

| Metric | Description | |--------|-------------| | lcp | Largest Contentful Paint (ms) | | cls | Cumulative Layout Shift (score) | | fcp | First Contentful Paint (ms) | | inp | Interaction to Next Paint (ms) | | ttfb | Time to First Byte (ms) |

Default Metrics

| Metric | Description | |--------|-------------| | elements_count | Total DOM elements on page load |

Default Labels

| Label | Description | |-------|-------------| | device_type | Device category: desktop, mobile, or tablet | | path | Current page pathname |

Backend Integration

Bretrics sends metrics via HTTP POST to {apiPath}/send-metrics/metrics. The request body contains a JSON object with metric names as keys and values or IMetric objects.

A ready-to-use backend microservice for collecting and exposing metrics to Prometheus is available at MobileTeleSystems/bretrics.

Example payload:

{
    "lcp": {
        "value": 2500,
        "labels": {
            "device_type": "mobile",
            "path": "/products"
        }
    },
    "custom_metric": 42
}

Browser Support

Bretrics supports all modern browsers. The library uses navigator.sendBeacon when available, with a fetch fallback for older browsers.

Contributing

Contributions are welcome. Please read the Contributing Guide before submitting a pull request.

License

This project is licensed under the MIT License.

Related Projects

  • web-vitals - Library for measuring Web Vitals metrics