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

spm-agent-nodejs

v4.2.7

Published

Node.js monitoring agent for SPM by Sematext

Downloads

1,065

Readme

spm-agent-nodejs

npm-stats

This is the Node.js monitoring agent for Sematext Cloud.

The following information is collected and transmitted to Sematext:

  • OS Metrics (CPU / Mem)
  • Process Memory
  • EventLoop stats
  • Garbage Collector stats
  • Web server stats (requests, error rate, response times etc.) Working for all web servers frameworks that use Node.js http/https module including
    • "connect" based frameworks
    • Express.js,
    • Sails.js
    • Hapi.js
    • Restify
    • and others ...

The module is able to run in cluster mode (master/worker).

Status

Supported Node-Versions: Node >= 6.x.

Please check our blog for more information or contact us at [email protected].

Installation


    npm install spm-agent-nodejs

Get a free account and create a Node.js API token at sematext.com/spm

Configuration

We use https://www.npmjs.com/package/rc for configuration. This means config parameters can be passed via several config locations command-line args or ENV variables. We recommend to use a file in current directory in INI or JSON format called ".spmagentrc". This file can be generated by calling a helper script:

    export MONITORING_TOKEN=YOUR-NODEJS-MONITORING-TOKEN
    export INFRA_TOKEN=YOUR-INFRA-MONITORING-TOKEN
    node ./node_modules/spm-agent-nodejs/bin/spmconfig.js

The command above generates following default configuration file (YAML format):

    # Directory for buffered metrics
    dbDir: ./spmdb

    # Application Token for SPM
    tokens:
      monitoring: YOUR-NODEJS-MONITORING-TOKEN
      infra: YOUR-INFRA-MONITORING-TOKEN

    logger
      # log file directory default is ./spmlogs
      dir: ./spmlogs
      # silent = true means no creation of log files
      silent: false
      # log level for output - debug, info, error, defaults to error to be quiet
      level: error

The only required setting is the Sematext App Token, this could be set via config file ".spmagentrc" or environment variable:

export spmagent_tokens__monitoring=YOUR-NODEJS-MONITORING-TOKEN

Please note the use of double "_" for nested properties

Configuration via Environment Variables

export MONITORING_TOKEN=YOUR-NODEJS-MONITORING-TOKEN
export INFRA_TOKEN=YOUR-INFRA-MONITORING-TOKEN
# default is SaaS at sematext.com, URL needs to be changed for on-prem to the local SPM receiver
export SPM_RECEIVER_URL=https://local-spm-server:8084/_bulk
export EVENTS_RECEIVER_URL=https://local-event-receiver/
export SPM_DB_DIR=/tmp
export SPM_LOG_DIRECTORY=./logs
export SPM_LOG_LEVEL=error
export SPM_LOG_TO_CONSOLE=true
export HTTPS_PROXY=http://my-local-proxy-server

Changing API endpoints for Sematext Cloud EU

export SPM_RECEIVER_URL=https://spm-receiver.eu.sematext.com/receiver/v1
export EVENTS_RECEIVER_URL=https://event-receiver.eu.sematext.com

Tags

To configure tags to send along with metrics please see spm-agent README.

Usage

Method 1: Preloading spm-agent-nodejs - no source code modifications requred

The command line option "-r" preloads node modules before the actual application is started. In this case the original source code needs no modification:

  node -r './spm-agent-nodejs' yourApp.js

Method 2: Add spm-agent-nodejs to your source code

Add this line at the begin of your source code / main script / app.js

# add spm-agent-nodejs to your project
npm i spm-agent-nodejs --save
require('spm-agent-nodejs')

With PM2

Use the absolute path to your .env file to enable PM2 monitoring.

// load env vars if you're using dotenv
require('dotenv').config({ path: '/absolute/path/to/your/project/.env' })
// start agent
require('spm-agent-nodejs')
pm2 start app.js -i max

Results

Troubleshooting

Please visit our documentation for more information.

Other monitoring packages

Please check out spm-metrics-js to monitor any custom metric in your application.

Sematext Docker Agent (see also: https://sematext.com/docker and https://sematext.com/kubernetes)

LICENSE

Apache 2 - see LICENSE file.