@mts-pjsc/bretrics
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Codacy Badge npm version Contributor Covenant GitHub license

Bretrics - Realtime user Browser Monitoring

Monitor the performance of the user's browser and code for real users. Allows you to collect WebVitals metrics, performance and business metrics through the Prometheuse monitoring system.

Features

  • WebVitals - allows you to collect the main performance metrics of the WebVitals initiative,
  • Custom Metrics - allows you to collect the custom performance metrics,
  • Business Metrics - allows you to collect any business metrics and sales funnels,
  • Network Metrics - allows you to evaluate the quality of the connection from clients to your servers,
  • Leaks Detection - allows you to detect leaks in DOM elements, listeners, js and others.

Instalation

npm:

npm install @mts-pjsc/bretrics

yarn

yarn add @mts-pjsc/bretrics

Examples

Example Default Monitoring

The package has a pre-configured monitoring mode that includes the necessary webvitals metrics.

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

bretrics
    .setup({apiPath: "/bretrics"}) // <-- microservice deploy location
    .useDefaultMonitoring()
    .sendMetrics({my_metric: 5}); // <-- custom metrics

If you need to send custom metric, you must use the sendMetrics method.

Example Metrics with labels

Prometheus labels can be set as default for all metrics, or individually for each value.

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

bretrics
    .setup({apiPath: "/bretrics"})
    .useDefaultMonitoring()
    .setLabels({stage: "beta", path: location.pathname})
    .sendMetrics({
        my_metric: {
            value: 5,
            labels: {path: "/blog"}
        }
    });

The default labels will be added to the metrics if you didn't pass them in the sendMetrics method.

Example Bretrics customization

The library exports the web monitoring constructor class, so you can inherit from it and implement logic according to OOP principles.

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

export class BretricsService extends Bretrics {

    public override sendMetrics (metric: Record<string, number>): this {
        super.sendMetrics(metric);

        // ... your code here ...

        return this;
    }

}

License

WebMon is MIT licensed.

Readme

Keywords

Package Sidebar

Install

npm i @mts-pjsc/bretrics

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

14 kB

Total Files

9

Last publish

Collaborators

  • elabutin
  • mtsrus