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 🙏

© 2026 – Pkg Stats / Ryan Hefner

express-influx-multilogger

v1.0.12

Published

An express.js middleware for getting detailed views of your API Calls and sending it to an Influx database of choice for Grafana

Downloads

21

Readme

Express-influx-multilogger

An Express middleware for better monitoring of your Node.js apps. Parse important req, res and header objects to Influx and Grafana. Get an easier insight of your API without any costs.

Note: this is in active development, and could contain bugs. Please make an issue if you find some.

Getting started

Installation

  1. Install package

    • Npm
    npm install express-influx-multilogger
    • Yarn
    yarn add express-influx-multilogger
  2. Require

    const multilogger = require('express-influx-multilogger');
  3. (Required if you want to write to influx) Initialize database in your app.js

    multilogger.init({
     database: {
         server: "127.0.0.1",
         name: "myMultilogDb",
         port: 8086
          },
     interval: 10000,
     performance: true,
    });
  4. Add multilogger log function right before your router of choice

    app.use(multilogger.log({ development: false, extended: false }));
  5. Add multierror function before catching 404 and after your router

    app.use(multilogger.error());
  6. In case of using geolocation, make sure your server can make use of req.connection.remoteAddress

  7. You can also add extra custom metrics for monitoring other things, like your database calls

    Add this line in your code (make sure you require multilogger). Name and timing parameters are required. Custom is optional.

     multilogger.insertDatabaseCallSpeed({
       name: "Random name", // name of your metric (like a database call)
       timing: 0.2443, //in ms
       custom: {
         customOption1: "foo",
         foo: foo.bar,
       }
     });

Example

const express = require("express");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");
const multilogger = require('express-influx-multilogger'); // Add this to imports

const indexRouter = require("./routes/index");

//  Add this to write data to influx (not required)
multilogger.init({
    database: {
        server: "127.0.0.1",
        name: "myMultilogDb",
        port: 8086
         },
    interval: 10000,  // Write to Influx every 10 seconds,
    performance: true // Write host performance to Influx (mem, cpu,..)  
});
multilogger.startPerformanceMetrics();

const app = express();

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cookieParser());

// Add this before your router of choice
app.use(multilogger.log({ development: false, extended: false }));
app.use("/", indexRouter); // Your router

// Add this before 404 if you want to capture your errors as well
app.use(multilogger.error());

module.exports = app;

Loggable headers

The data being sent to Influx consists of ...

Fields

...logs of the amount of calls per statuscode per given interval

    amountOf1xx: Influx.FieldType.INTEGER,
    amountOf2xx: Influx.FieldType.INTEGER,
    amountOf3xx: Influx.FieldType.INTEGER,
    amountOf4xx: Influx.FieldType.INTEGER,
    amountOf5xx: Influx.FieldType.INTEGER

...logs of Response Time, CPU and memory Usage of the OS, host and ip;

    responseTime: Influx.FieldType.FLOAT,
    cpuUsage: Influx.FieldType.FLOAT,
    memoryUsage: Influx.FieldType.FLOAT,
    requests: Influx.FieldType.INTEGER,
    host: Influx.FieldType.STRING,
    ip: Influx.FieldType.STRING

Tags

...logs of basic headers to Influx

    "statusCode",
    "statusMessage",
    "method",
    "path",
    "url",
    "ip",
    "country",
    "geohash", // Used to get the geolocation of your api call from a given IP
    "client",
    "body",
    "query",
    "params",
    "auth", // In case you wanna know wich user that triggered the api call
    "errorMessage", // In case of an error: sends message and stack
    "errorStack"

Parameters

  1. Extended: Logs a pretty view of req, res and headers (defaults false)
  2. Development: Logs the object that Influx will recieve
  3. Database:
    • server: The address of your Influx database. (defaults: 127.0.0.1)
    • name: Name of your Influx database. (defaults: myMultilogDb)
    • port: Port of your Influx database. (defaults: 3000)
    • username: Login credentials of your Influx database. (defaults: '')
    • password: Password of your Influx database. (defaults: '')
  4. Interval: Defines the rate in ms of the interval you want to write your data to your Influx database

Reset Table

What if you have sent wrong info to Influx? You can make use of the Influx-cli to drop your database or a certain metric or series (table)

> DROP DATABASE <db_name>
> DROP MEASUREMENT <measurement_name>
> DROP SERIES FROM <db_series>

For more info, you can check the docs.

Grafana

If you want to use Grafana and don't want to write your dashboard, you can import the dashboard JSON. You can certainly write your own dashboard, as I'm not that skilled with Grafana.

By using this dashboard, make sure you install the worldmap plugin.

License

Distributed under the MIT License. See LICENSE for more information.

Dependencies

Contributors