Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

spm-agent-nodejs

sematext1.4kCopyright (c) Sematext Group, Inc.4.2.7

Node.js monitoring agent for SPM by Sematext

SPM, APM, application performance monitoring, Sematext, performance monitoring, monitoring, alerting, anomaly detection, heartbeat, metrics, custom metrics, devops, operations, dashboards, profiling, memwatch, gc-profiler, agent, logging

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 npmjs@sematext.com.

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.

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

4.2.7

7 August 2023

  • fix: upgrade libraries #69
  • Bump semver from 5.7.1 to 5.7.2 #67
  • Bump word-wrap from 1.2.3 to 1.2.4 #68

4.2.6

15 June 2023

  • chore: upgrade spm-agent library #66
  • Release 4.2.6 ca7868b

4.2.5

15 June 2023

  • chore: upgrade spm_agent library #65
  • Release 4.2.5 2d472a5

4.2.4

15 June 2023

  • Fix library vulnerabilities #64
  • Bump yaml from 1.10.2 to #61
  • Bump vm2 from 3.9.17 to 3.9.19 #63
  • Bump vm2 from 3.9.16 to 3.9.17 #60
  • Bump vm2 from 3.9.11 to 3.9.16 #59
  • Bump http-cache-semantics from 4.1.0 to 4.1.1 #58
  • chore: upgrade the libraries with vulnerabilities 332bd95
  • chore: remove the test of already deleted process 9fdfbd1
  • Release 4.2.4 91e7cd3

4.2.3

16 December 2022

  • SC-14625: Update mocha to version 10.2.0 and switch gc-stats to Sematext fork #55
  • Bump qs from 6.5.2 to 6.5.3 #53
  • Update mocha to version 10.2.0 and switch gc-stats to Sematext fork 3df9823
  • Release 4.2.3 d8d2dbe

4.2.2

13 October 2022

  • Point gc-stats to fork with custom binary URI #51
  • Bump vm2 from 3.9.10 to 3.9.11 #50
  • Release 4.2.2 ab462d6

4.2.1

20 September 2022

  • Update dependencies #49
  • Bump jose from 1.28.1 to 1.28.2 #48
  • SC-12404: Address high score vulnerability #47
  • Address high score vulnerability f423b8e
  • Release 4.2.1 b55e454

4.2.0

8 July 2022

  • SC-13033 Update dependencies #46
  • Bump minimist from 1.2.5 to 1.2.6 #43
  • Bump node-fetch from 2.6.1 to 2.6.7 #44
  • Bump moment from 2.29.1 to 2.29.2 #42
  • Update dependencies 1f14495
  • Release 4.2.0 5276ebf
  • Added a pointer to tag configuration 04429df

4.1.4

1 July 2021

  • Bump ws from 6.2.1 to 6.2.2 #40
  • Bump glob-parent from 5.1.1 to 5.1.2 #41
  • Bump hosted-git-info from 2.8.8 to 2.8.9 #39
  • Bump handlebars from 4.7.6 to 4.7.7 #38
  • Bump jose from 1.28.0 to 1.28.1 #37
  • update deps 2a336ec
  • updated deps 36dd221
  • Release 4.1.4 55aad02

4.1.3

7 April 2021

4.1.2

15 February 2021

4.1.1

13 January 2021

4.1.0

22 December 2020

4.0.4

21 October 2020

4.0.3

21 October 2020

4.0.2

11 May 2020

4.0.1

17 April 2020

4.0.0

17 April 2020

  • Remove OS monitor with node-df #31
  • Added release it config #30
  • added auto changelog to release it scripts bffe2d8
  • removed npx 30f0566
  • removed OS monitor 739806f

3.0.3

21 February 2020

  • Fix and edit for spmconfig command to take env vars #28
  • clean up generated file 8c965bf
  • fixed and refactored spmconfig command to take env vars 4d08b2c
  • update readme pm2 section 15c8da9

3.0.1

22 January 2020

  • Added fixes to process metrics #22
  • Add missing tags pid, ppid #27
  • add process.thread.count metric #26
  • Add infra token to setup script #24
  • add infra token to process metrics #25
  • hotfix: updated OS agent, edited pm2 config to not need env var 78f936d
  • update npm packages eb8b6eb
  • fix failing tests for processAgent 5c2d99a

3.0.0

5 December 2019

  • Bump lodash from 4.17.11 to 4.17.15 #19
  • Bump eslint from 3.18.0 to 6.4.0 #20
  • SC-4677: Added support for tracking process types #17
  • change all nodejs-metrics to influx-metric format #18
  • SC-4677: added generic tests for various cases 7c84fd7
  • SC-4677: code cleanup + testing 22494f7
  • SC-4677: separated worker metrics into dedicated agent and added process agent 31a85e8

2.0.4

5 November 2019

  • update dependencies, standard code format, remove deprecated modules daf61a9
  • Tweaked a few old links d47ac12
  • Release 2.0.4 3b00ecd

2.0.3

26 April 2019

2.0.2

26 April 2019

2.0.1

28 December 2018

  • remove mentions of node 0.10/0.12/4 1664702
  • remove support for Node.js v4 1369f91
  • Release 2.0.1 45c5b0d

2.0.0

28 December 2018

1.30.9

6 July 2017

1.30.8

7 April 2017

1.30.7

8 March 2017

  • feat: domain handling #11
  • style: standard ec58d43
  • fix: typos, constants 1bf739d
  • fix: make sure we clean setInterval 4faffe5

1.30.6

27 February 2017

1.30.4

25 January 2017

  • generate default config in YAML format, updated dependencies db18cde
  • Release 1.30.4 029c6c1

1.30.3

16 January 2017

1.30.2

22 September 2016

  • add check for pm2 env / master mode, fix typo 478105e
  • Release 1.30.2 0dd50a5
  • add check for pm2 env / master mode 69fcd99

1.30.1

15 July 2016

  • updated test and readme 8adcfb4
  • code format, multi-version test script 040b981
  • jshintrc and code formatting caa22c4