{"id":19653533,"url":"https://github.com/sematext/spm-agent-nodejs","last_synced_at":"2025-04-28T17:31:34.392Z","repository":{"id":27902121,"uuid":"31393807","full_name":"sematext/spm-agent-nodejs","owner":"sematext","description":"NodeJS Monitoring Agent","archived":false,"fork":false,"pushed_at":"2023-10-17T05:15:38.000Z","size":1129,"stargazers_count":60,"open_issues_count":5,"forks_count":6,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-17T20:13:20.130Z","etag":null,"topics":["agent","apm","developer-tools","devops","javascript","monitoring","nodejs","performance-metrics","performance-monitoring","tracing"],"latest_commit_sha":null,"homepage":"https://sematext.com/integrations/nodejs-monitoring","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sematext.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-26T23:12:47.000Z","updated_at":"2024-10-14T15:01:35.000Z","dependencies_parsed_at":"2024-06-18T20:16:18.926Z","dependency_job_id":null,"html_url":"https://github.com/sematext/spm-agent-nodejs","commit_stats":{"total_commits":363,"total_committers":11,"mean_commits":33.0,"dds":0.5647382920110193,"last_synced_commit":"a43f7fa735fb2d09c995dc621bcb48dbeffe450e"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fspm-agent-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fspm-agent-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fspm-agent-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fspm-agent-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sematext","download_url":"https://codeload.github.com/sematext/spm-agent-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251355418,"owners_count":21576355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","apm","developer-tools","devops","javascript","monitoring","nodejs","performance-metrics","performance-monitoring","tracing"],"created_at":"2024-11-11T15:14:26.501Z","updated_at":"2025-04-28T17:31:34.100Z","avatar_url":"https://github.com/sematext.png","language":"JavaScript","readme":"spm-agent-nodejs\n================\n\u003c!-- ![build status](https://api.travis-ci.org/sematext/spm-agent-nodejs.svg) --\u003e\n\n![npm-stats](https://nodei.co/npm/spm-agent-nodejs.png?downloads=true\u0026downloadRank=true)\n\nThis is the [Node.js monitoring](https://sematext.com/integrations/nodejs-monitoring) agent for [Sematext Cloud](https://sematext.com/cloud).\n\nThe following information is collected and transmitted to Sematext:\n\n- OS Metrics (CPU / Mem)\n- Process Memory\n- EventLoop stats\n- Garbage Collector stats\n- Web server stats (requests, error rate, response times etc.)\n  Working for all web servers frameworks that use Node.js http/https module including \n  - \"connect\" based frameworks\n  - Express.js, \n  - Sails.js\n  - Hapi.js\n  - Restify\n  - and others ...\n\nThe module is able to run in cluster mode (master/worker). \n\n# Status\n\nSupported Node-Versions: Node \u003e= 6.x. \n\nPlease check our [blog](https://sematext.com/tag/node-js/) for more information or contact us at [npmjs@sematext.com](mailto:npmjs@sematext.com).\n\n# Installation\n\n- [How to Add Performance Monitoring to Node.js Applications](https://sematext.com/blog/adding-monitoring-to-node-js-and-io-js-apps/)\n\n```\n\n    npm install spm-agent-nodejs\n\n```\n\nGet a free account and create a Node.js API token at [sematext.com/spm](https://apps.sematext.com/ui/registration)\n\n# Configuration\n\nWe use https://www.npmjs.com/package/rc for configuration. This means config parameters can be passed via several config\nlocations command-line args or ENV variables. We recommend to use a file in current directory in INI or JSON format called \".spmagentrc\".\nThis file can be generated by calling a helper script:\n\n        export MONITORING_TOKEN=YOUR-NODEJS-MONITORING-TOKEN\n        export INFRA_TOKEN=YOUR-INFRA-MONITORING-TOKEN\n        node ./node_modules/spm-agent-nodejs/bin/spmconfig.js\n\nThe command above generates following default configuration file (YAML format):\n\n        # Directory for buffered metrics\n        dbDir: ./spmdb\n\n        # Application Token for SPM\n        tokens:\n          monitoring: YOUR-NODEJS-MONITORING-TOKEN\n          infra: YOUR-INFRA-MONITORING-TOKEN\n\n        logger\n          # log file directory default is ./spmlogs\n          dir: ./spmlogs\n          # silent = true means no creation of log files\n          silent: false\n          # log level for output - debug, info, error, defaults to error to be quiet\n          level: error\n\n\nThe only required setting is the Sematext App Token, this could be set via config file \".spmagentrc\" or environment variable:\n\n    export spmagent_tokens__monitoring=YOUR-NODEJS-MONITORING-TOKEN\n\nPlease note the use of double \"_\" for nested properties\n\n\n## Configuration via Environment Variables\n\n    export MONITORING_TOKEN=YOUR-NODEJS-MONITORING-TOKEN\n    export INFRA_TOKEN=YOUR-INFRA-MONITORING-TOKEN\n    # default is SaaS at sematext.com, URL needs to be changed for on-prem to the local SPM receiver\n    export SPM_RECEIVER_URL=https://local-spm-server:8084/_bulk\n    export EVENTS_RECEIVER_URL=https://local-event-receiver/\n    export SPM_DB_DIR=/tmp\n    export SPM_LOG_DIRECTORY=./logs\n    export SPM_LOG_LEVEL=error\n    export SPM_LOG_TO_CONSOLE=true\n    export HTTPS_PROXY=http://my-local-proxy-server\n\n## Changing API endpoints for Sematext Cloud EU \n\n```\nexport SPM_RECEIVER_URL=https://spm-receiver.eu.sematext.com/receiver/v1\nexport EVENTS_RECEIVER_URL=https://event-receiver.eu.sematext.com\n```\n\n# Tags\n\nTo configure tags to send along with metrics please see [spm-agent README](https://github.com/sematext/spm-agent/blob/master/README.md).\n\n# Usage\n\n## Method 1: Preloading spm-agent-nodejs - no source code modifications requred\n\nThe command line option \"-r\" preloads node modules before the actual application is started. In this case the original source code needs no modification:\n\n```sh\n  node -r './spm-agent-nodejs' yourApp.js\n```\n\n## Method 2: Add spm-agent-nodejs to your source code\nAdd this line at the begin of your source code / main script / app.js\n\n```\n# add spm-agent-nodejs to your project\nnpm i spm-agent-nodejs --save\n```\n\n```js\nrequire('spm-agent-nodejs')\n```\n\n## With PM2\nUse the absolute path to your `.env` file to enable PM2 monitoring.\n\n```js\n// load env vars if you're using dotenv\nrequire('dotenv').config({ path: '/absolute/path/to/your/project/.env' })\n// start agent\nrequire('spm-agent-nodejs')\n```\n\n```bash\npm2 start app.js -i max\n```\n\n# Results\n\n- _[Top Node.js Metrics to Watch](https://blog.sematext.com/top-nodejs-metrics-to-watch/)\n![SPM for Node.js screenshot](https://sematext.com/wp-content/uploads/2019/04/sematext-nodejs-metrics.png)_\n\n# Troubleshooting\n\nPlease visit our [documentation](https://sematext.com/docs/integration/node.js/) for more information.\n\n# Other monitoring packages\n\nPlease check out [spm-metrics-js](https://www.npmjs.com/package/spm-metrics-js) to monitor any custom metric in your application.\n\n[Sematext Docker Agent](https://hub.docker.com/r/sematext/agent/) (see also: https://sematext.com/docker and https://sematext.com/kubernetes)\n\n# LICENSE\n\nApache 2 - see [LICENSE](https://github.com/sematext/spm-agent-nodejs/blob/master/LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsematext%2Fspm-agent-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsematext%2Fspm-agent-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsematext%2Fspm-agent-nodejs/lists"}