Socket
Socket
Sign inDemoInstall

prom-nodejs-client

Package Overview
Dependencies
69
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    prom-nodejs-client

## Overview


Version published
Maintainers
1
Created

Readme

Source

Prometheus Node.js Push Library

Overview

This Node.js library facilitates the seamless transmission of Prometheus data to a Prometheus server using prom-client. The primary function, metricsLogError, allows the pushing of error logs to Prometheus, aiding in error monitoring and analysis.

Functionality

metricsLogError
  • metricsLogError(controller, error)
    • controller (string): Specifies the controller or component where the error occurred.
    • error (Error): Represents the error object to be logged.

Getting Started

Installation

npm install prom-nodejs-client

Initialization

To integrate the library with an Express application:

import express from "express";
import promMid from "prom-nodejs-client";

/**
 * Express middleware for handling metrics requests.
 * @module metricsRoute
 */

const metricsRoute = express();

/**
 * Middleware for collecting and exposing Prometheus metrics.
 * @function
 * @param {Object} options - Options for configuring the Prometheus middleware.
 * @param {string} options.metricsPath - The path for exposing the metrics endpoint.
 * @param {boolean} options.collectDefaultMetrics - Whether to collect default metrics.
 * @param {number[]} options.requestDurationBuckets - Buckets for request duration histogram.
 * @param {number[]} options.requestLengthBuckets - Buckets for request length histogram.
 * @param {number[]} options.responseLengthBuckets - Buckets for response length histogram.
 */
metricsRoute.use(
  promMid({
    metricsPath: "/metrics",
    collectDefaultMetrics: true,
    requestDurationBuckets: [0.02, 0.05, 0.1, 0.5, 1, 10],
    requestLengthBuckets: [512, 1024, 5120, 10240, 51200, 102400],
    responseLengthBuckets: [512, 1024, 5120, 10240, 51200, 102400],
  })
);

export default metricsRoute;

Add the route to your app

/**
 * Metrics route for Prometheus
 */
app.use(metricsRoute);

Environment Configuration

Ensure the .env file contains the following configuration:

SERVICE_NAME=service-name

Example: Logging Error Metrics

import { metricsLogError } from "prom-nodejs-client";

const controllerName = "ExampleController";
const error = new Error("Example error message");

metricsLogError(controllerName, error);

Contribution

Contributions are welcome! Feel free to open issues or pull requests.

FAQs

Last updated on 16 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc