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

ackee-node-monitor-module

v0.0.16

Published

`Ackee Node Monitor Module` collects request and response data and sends this information using [winston-elasticsearch](https://www.npmjs.com/package/winston-elasticsearch) to collector [Elasticsearch](https://www.elastic.co/) defined in configuration

Downloads

136

Readme

Ackee Node Monitor Module

Ackee Node Monitor Module collects request and response data and sends this information using winston-elasticsearch to collector Elasticsearch defined in configuration file. Ackee Node Monitor Module sends request to collector once per timeout specified in config and only if at least one request is in collection.

Installation

# Install from npm
npm install ackee-node-monitor-module --save

Usage

First add Ackee Node Monitor Module configuration into config.js:

  • disabled: enable or disable logging
  • excludedUrls: urls excluded from logging, e.g. assets, css or js files ...
  • elastic:
    • host: specify url of Elasticsearch
    • log: log level (debug, info, trace, error)
  • winston:
    • level: log level (silly, debug, verbose, info, warn, error)
    • indexPrefix: the prefix used to generate the index name according to the pattern indexPrefix-[YYYY.MM.DD]
    • timeout: flushInterval - distance between bulk writes in ms, default: 2000
  • customHeaders: array of request custom headers logged to Elastic
  • customResponseHeaders: array of response custom headers logged to Elastic
  • customReqData: array of custom request data logged to Elastic
  • customPayload: custom payload logged to Elastic

Events

Ackee Node Monitor Module listens for close event and finish event:

  • close: Indicates that the underlying connection was terminated before response.end().
  • finish: Emitted when the response has been sent.

Example

module.exports = {
    ...
    ackeeNodeMonitor: {
            disabled: false,
            excludedUrls: ['/bower_components/', '/img/', '/js/', '/css/'],
            elastic: {
                host: 'someelastic.com:9200',
                log: 'trace',
            },
            winston: {
                level: 'silly',
                indexPrefix: 'nodetemplate-monitor',
                timeout: 10000
            },
            customHeaders: [
                'User-Agent'
            ],
            customReqData: [
                {
                    path: 'user',
                    name: 'user'
                },
                {
                    path: 'body.user.id',
                    name: 'userId'
                },
            ],
            customPayload: {
                appName: 'appName',
                appEnv: 'appEnv'
            },
        }
    ...
}

then require and init Ackee Node Monitor Module in server.js before calling createServer (app.listen(port);):

...
const express = require('express');
const config = require('config');

// require and init ackee-node-monitor-module
require('ackee-node-monitor-module')(config.ackeeNodeMonitor);

const app = express();
...
const server = app.listen(port);

Console output

...
AckeeNodeMonitor init
...
TRACE: 2016-11-07T09:41:22Z
  -> POST http://localhost:9200/_bulk?consistency=one&timeout=10000ms
  {"index":{"_index":"test-2016.11.07","_type":"log"}}
  {"@timestamp":"2016-11-07T09:41:22.375Z","message":"Time measuring log","severity":"info","fields":{"resTime":25.395093,"method":"GET","statusCode":200,"baseUrl":"/service","path":"/test","User-Agent":"ApacheBench/2.3","user":{"userId":1},"appName":"test"}}
  
  <- 200
  {
    "took": 136,
    "errors": false,
    "items": [
      {
        "create": {
          "_index": "test-2016.11.07",
          "_type": "log",
          "_id": "AVg-KeQJoqW3YlfWUnaJ",
          "_version": 1,
          "_shards": {
            "total": 2,
            "successful": 1,
            "failed": 0
          },
          "status": 201
        }
      }
    ]
  }

DEBUG: 2016-11-07T09:41:22Z
  Request complete

Collected data

{   
    "fields": {
        "resTime": "response time in [ms] or null",
        "method": "HTTP method",
        "statusCode": "HTTP status code or 0",
        "baseUrl": "express baseUrl",
        "path": "express path",
        "timestamp": "timestamp" 
    }
}
Example

onFinish

{ 
    "fields": {
        "resTime": 25.395093,
        "method": "GET",
        "statusCode": 200,
        "baseUrl": "/services",
        "path": "/test",
        "timestamp": 1474290310129,
        "User-Agent": "ApacheBench/2.3",
        "user": {
            "userId": 1
        },
        "appName": "test"
    }
}

onClose

{ 
    "fields": {
        "resTime": null,
        "method": "GET",
        "statusCode": 0,
        "baseUrl": "/services",
        "path": "/test",
        "timestamp": 1474290310132,
        "User-Agent": "ApacheBench/2.3",
        "user": {
            "userId": 1
        },
        "appName": "test"
    }
}