1.0.2 • Published 5 years ago

sre-domain-node-metrics v1.0.2

Weekly downloads
7
License
ISC
Repository
github
Last release
5 years ago

Domain Node Influxdb metrics reporter

This is a node metrics library to push application metrics to influxdb. This library exports two module. One provides a express middleware to calculate response times metrics and other provides a reporter registry to push metrics to influxdb

Installation

yarn add @domain-group/sre-domain-node-metrics

Usage

  const express = require('express');
  const { getMetricsMiddleware, getMetricsReporter } = require('@domain-group/sre-domain-node-metrics');

  const options = {
    host: 'localhost',
    port: 8086,
    protocol: 'http',
    username: 'username',
    password: 'password',
    database: 'database',
    application: process.env.APPLICATION_PREFIX,
    metrics: 'response_times',
  };

  const reporter = getMetricsReporter(options);

/**

   * Creates an Express middleware that reports a http metric responsetime on request data.
   * With this middleware you will get response time all filterable by status codes, http method, and uri paths.
   *
   * @param {getMetricsReporter} reporter
   * @param {winston} logger
   
*/

  const middleware = getMetricsMiddleware(reporter, logger);

  const app = express();
  app.use(middleware);

  // Implement the rest of app

Configuration

The options object accepts the following fields:

A complete example with logger

  const winston = require('winston');
  const express = require('express');
  const { getMetricsMiddleware, getMetricsReporter } = require('@domain-group/sre-domain-node-metrics');

  const logger = winston.createLogger({
  transports: [
    new winston.transports.Console({
      level: process.env.LOG_LEVEL,
      handleExceptions: true,
      json: true,
      colorize: process.env.NODE_ENV !== 'production',
      timestamp: true,
      humanReadableUnhandledException: true,
    })
  ],
  exitOnError: false,
});

  const options = {
    host: 'localhost',
    port: 8086,
    protocol: 'http',
    username: 'username',
    password: 'password',
    database: 'database',
    application: process.env.APPLICATION_PREFIX,
    metrics: 'response_times',
    interval: 5000
  };

  const reporter = getMetricsReporter(options);

  const middleware = getMetricsMiddleware(reporter, logger);

  const app = express();
  app.use(middleware);

  // Implement the rest of app
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago