@classapp-tech/prometheus-integration
v1.4.0
Published
A class to make integration with Prometheus Aggregator
Downloads
2,462
Keywords
Readme
@classapp-tech/prometheus-integration
✅ 100% test coverage
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