npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

metricboard

v1.9.0

Published

MetricBoard is a performance monitoring tool that logs and visualizes microservice metrics with detailed charts for response times, status codes, and API performance

Downloads

26

Readme

MetricBoard: API Metrics Logging and Chart Visualization Middleware

Overview

MetricBoard is a middleware designed for Express.js applications to automatically log, analyze, and generate visual reports of HTTP request and response metrics. It provides detailed logging of critical performance indicators, such as response times, payload sizes, and status codes for every API call, saving them into JSON files and producing an HTML-based visual report with charts. MetricBoard is particularly useful for developers looking to monitor, analyze, and improve their microservices' performance through structured data and easily interpretable visualizations.

Overall

Timeline

Logs


Key Features

  1. Request and Response Logging:

    • Logs every HTTP request's method, URL, status code, request size, response size, and response time.
    • Organizes logs by microservice, creating a separate log for each service.
  2. Auto-Generated HTML Reports:

    • Generates detailed reports for each microservice using EJS templates.
    • Provides clear visualizations with pie charts for request method distribution and status code distribution.
    • Displays response time metrics and allows easy filtering of logs based on HTTP methods and status codes.
  3. Endpoint-Specific Reports:

    • Automatically generates specific reports for individual API endpoints, helping you pinpoint performance issues.
  4. Visual Charts:

    • Pie Charts for API request method distribution and status code distribution.
    • Line Charts for requests over time to monitor traffic patterns across hours of the day.
  5. Easy Integration:

    • Works seamlessly with Express applications.
    • Configurable to work with monitoring tools like nodemon and pm2 to avoid unnecessary restarts due to log file updates.

Installation

To install MetricBoard as a dependency in your project, run:

npm install metricboard

Usage

To use MetricBoard in your Express application, follow these steps:

  1. Require the Middleware:

You can now attach the metricboard middleware to your Express app. When setting up the middleware, you need to specify two parameters:

a) baseUrl: The base URL for the routes you want the middleware to monitor.

b) microservices: An array of microservice names or resource paths you want to log metrics for

const express = require('express');
const { metricboard } = require('metricboard');
const app = express();

// Middleware for /app with microservices 'appuse' and 'contracts'
app.use(metricboard('/app', ['appuse', 'contracts']));

// Your application routes
app.get('/', (req, res) => res.send('Hello World!'));

app.listen(3000, () => console.log('Server running on port 3000'));
  1. Nodemon Configuration:

    Since MetricBoard generates files like metrics.json and report.html, you should configure nodemon to ignore these files to avoid unnecessary restarts:

    Add this section to your package.json:

    "nodemonConfig": {
      "ignore": ["metrics/**/*.json", "metrics/**/*.html"],
      "verbose": true
    }
  2. PM2 Configuration:

    For pm2, add the following to your ecosystem.config.js or a similar configuration file:

    {
      "apps": [
        {
          "name": "my-app",
          "script": "index.js",
          "ignore_watch": ["metrics"]
        }
      ]
    }

Generated Files and Structure

MetricBoard automatically creates a metrics directory in the root of your project where it stores logs and reports for each microservice.

File Structure

project-root/
│
├── metrics/
│   ├── microservice1/
│   │   ├── metrics.json    # Logs each API request in JSON format
│   │   └── report.html     # Visual HTML report with charts and metrics
│   ├── microservice2/
│   │   ├── metrics.json
│   │   └── report.html

JSON Metrics File

For each microservice, a metrics.json file is generated and updated for every API request. This file includes detailed logs of each request such as:

{
  "timestamp": "2024-09-15T12:45:30.123Z",
  "method": "GET",
  "url": "/api/users",
  "statusCode": 200,
  "reqSize": 256,
  "resSize": 1024,
  "responseTime": 134,
  "queryParams": {},
  "urlParams": {},
  "payload": {}
}

HTML Report

An HTML report is automatically generated for each microservice. This report includes:

  1. Request Method Distribution (Pie Chart): A chart displaying the proportion of requests made with each HTTP method (GET, POST, etc).

  2. Status Code Distribution (Pie Chart): A breakdown of response status codes (e.g., 200, 401, 404, 500, etc) in a pie chart format.

  3. Response Time Metrics: Key response time metrics such as:

    • Slowest response
    • Fastest response
    • Median response time
    • Average payload size
  4. Requests Over Time (Line Chart): A line chart showing the number of requests made at each hour of the day.

  5. Paginated Logs: A paginated table displaying individual API call logs with filters for HTTP method and status code.


Endpoint-Specific Reports

MetricBoard also generates detailed reports for individual API endpoints within each microservice. These reports include the same metrics as the overall report but are focused on a particular endpoint.

For instance, a report for /api/users would be saved as:

metrics/microservice1/api_users_report.html

Benefits

  1. Improved Performance Monitoring:
    • Gain insights into microservice performance with response times and API call distributions.
    • Identify slow endpoints and optimize them.
  2. Easily Accessible Visual Reports:
    • HTML reports with embedded charts make it easy to analyze service health without diving into raw logs.
  3. Microservice-Specific Metrics:
    • Each microservice has its own dedicated logs and reports, allowing you to focus on performance metrics per service.

License

MetricBoard is licensed under the Apache-2.0 License.


Contributions

We welcome contributions from the open-source community. Please submit issues or pull requests on the official GitHub repository.

Connect Here.