@classapp-tech/prometheus-integration
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

@classapp-tech/prometheus-integration

100% test coverage

Unit Test

Installation

Use the package manager node to install.

npm install @classapp-tech/prometheus-integration

Usage

To send metrics to the Prometheus Aggregation Gateway it is necessary to be in the same network (VPC), that is, from a Lambda or EC2 machine.

Example code to send metrics from a Lambda:

import { PrometheusAggregator } from '../index';

exports.handler = async (event) => {
  const prometheusAggregator = new PrometheusAggregator({
    endpoint: "your-endpoint-here.co",
    logger: {
      info: (message: string) => {
        // you can handle info messages from prometheus-integration here
      },
      warn: (message: string) => {
        // you can handle warnings from prometheus-integration here
      },
      error: (message: string) => {
        // you can handle errors from prometheus-integration here
      },
    }
  });

  // ... perform any action, for example notify a email message

  prometheusAggregator.incrementCounter({
    name: 'example_message_email_notification',
    description: 'Notification sent by email about example message',
  });

  // ... perform another action, for example notify by sms

  prometheusAggregator.incrementCounter({
    name: 'example_message_sms_notification',
    description: 'Notification sent by SMS about example message',
  });

  // ...

  // before leaving lambda, send metrics to Prometheus Aggregation Gateway

  await prometheusAggregator.pushMetrics();

  return {
    statusCode: 200,
    body: 'OK',
  };
};

Supported metrics are:

Type of Metrics Operations
Counters increment
Gauges increment, decrement
Histograms observation, startTimer, stopTimer

Attention

  • await should only be used when the metrics are ready to be sent
  • The instance must be created within the handler so that no cache is maintained and duplicate metrics are not sent

Readme

Keywords

none

Package Sidebar

Install

npm i @classapp-tech/prometheus-integration

Weekly Downloads

591

Version

1.4.0

License

MIT

Unpacked Size

32.5 kB

Total Files

8

Last publish

Collaborators

  • jaovito
  • mrspaiva
  • gbferreira
  • sergiodeveloper
  • arturcrs
  • benicio.samuel
  • silvasmvs
  • classapp_edna