4.2.7 • Published 9 months ago

spm-agent-nodejs v4.2.7

Weekly downloads
877
License
Copyright (c) Sem...
Repository
github
Last release
9 months ago

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.

4.2.5

11 months ago

4.2.4

11 months ago

4.2.7

9 months ago

4.2.6

11 months ago

4.2.3

1 year ago

4.2.2

2 years ago

4.2.1

2 years ago

4.2.0

2 years ago

4.1.4

3 years ago

4.1.3

3 years ago

4.1.2

3 years ago

4.1.1

3 years ago

4.1.0

3 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.4

4 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.30.9

7 years ago

1.30.8

7 years ago

1.30.7

7 years ago

1.30.6

7 years ago

1.30.4

7 years ago

1.30.3

7 years ago

1.30.2

8 years ago

1.30.1

8 years ago

1.30.0

8 years ago

1.29.12

8 years ago

1.29.11

8 years ago

1.29.9

8 years ago

1.29.8

8 years ago

1.29.7

8 years ago

1.29.6

8 years ago

1.29.5

8 years ago

1.29.4

8 years ago

1.29.3

8 years ago

1.29.2

8 years ago

1.29.1

8 years ago

1.28.2

8 years ago

1.28.1

8 years ago

1.28.0

8 years ago

1.27.4

9 years ago

1.27.3

9 years ago

1.27.2

9 years ago

1.27.1

9 years ago

1.27.0

9 years ago

1.24.19

9 years ago

1.24.18

9 years ago

1.24.17

9 years ago

1.24.16

9 years ago

1.24.15

9 years ago

1.24.14

9 years ago

1.24.13

9 years ago

1.24.12

9 years ago

1.24.11

9 years ago

1.24.10

9 years ago

1.24.9

9 years ago

1.24.8

9 years ago

1.24.7

9 years ago

1.24.6

9 years ago

1.24.5

9 years ago

1.24.4

9 years ago

1.24.3

9 years ago

1.24.2

9 years ago

1.24.1

9 years ago

1.24.0

9 years ago

1.0.32

9 years ago

1.0.31

9 years ago

1.0.29

9 years ago

1.0.28

9 years ago

1.0.27

9 years ago

1.0.26

9 years ago

1.0.25

9 years ago

1.0.24

9 years ago

1.0.23

9 years ago

1.0.22

9 years ago

1.0.21

9 years ago

1.0.20

9 years ago

1.0.19

9 years ago

1.0.18

9 years ago

1.0.17

9 years ago

1.0.16

9 years ago

1.0.15

9 years ago

1.0.14

9 years ago

1.0.13

9 years ago

1.0.12

9 years ago

1.0.11

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago