Socket
Book a DemoInstallSign in
Socket

measured-node-metrics

Package Overview
Dependencies
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

measured-node-metrics

Various metrics generators and http framework middlewares that can be used with a self reporting metrics registry to easily instrument metrics for a node app.

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
540
-22.08%
Maintainers
1
Weekly downloads
 
Created
Source

Measured Node Metrics

Various metrics generators and http framework middlewares that can be used with a self reporting metrics registry to easily instrument metrics for a node app.

npm

Install

npm install measured-node-metrics

What is in this package

Measured Node Metrics Module

See the docs for the main module to see the exported helper functions and maps of metric generators for various system and os metrics.

Example usage

const express = require('express');
const { createProcessMetrics, createOSMetrics, createExpressMiddleware } = require('measured-node-metrics');

const registry = new SelfReportingMetricsRegistry(new SomeReporterImple());

// Create and register default OS metrics
createOSMetrics(registry);
// Create and register default process metrics
createProcessMetrics(registry);
// Use the express middleware
const app = express();
app.use(createExpressMiddleware(registry));

// Implement the rest of app

You can also create your own middleware if your not using express, (please contribute it)

  const { onRequestStart, onRequestEnd } = require('measured-node-metrics');

  /**
   * Creates an Express middleware that reports a timer on request data.
   * With this middleware you will get requests counts and latency percentiles all filterable by status codes, http method, and uri paths.
   *
   * @param {SelfReportingMetricsRegistry} metricsRegistry
   * @param {number} [reportingIntervalInSeconds]
   * @return {Function}
   */
  createExpressMiddleware: (metricsRegistry, reportingIntervalInSeconds) => {
    return (req, res, next) => {
      const stopwatch = onRequestStart();

      req.on('end', () => {
        const { method } = req;
        const { statusCode } = res;
        // path variables should be stripped in order to avoid runaway time series creation, 
        // /v1/cars/:id should be one dimension rather than n, one for each id.
        const uri = req.route ? req.route.path : '_unknown';
        onRequestEnd(metricsRegistry, stopwatch, method, statusCode, uri, reportingIntervalInSeconds);
      });

      next();
    };
  }

FAQs

Package last updated on 10 Jul 2020

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.