{"id":19653554,"url":"https://github.com/sematext/sematext-agent-express","last_synced_at":"2025-04-28T17:31:36.818Z","repository":{"id":36471338,"uuid":"226706937","full_name":"sematext/sematext-agent-express","owner":"sematext","description":"Express.js Monitoring and Logging Agent by Sematext","archived":false,"fork":false,"pushed_at":"2023-10-19T08:44:04.000Z","size":937,"stargazers_count":17,"open_issues_count":2,"forks_count":1,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-21T11:08:29.969Z","etag":null,"topics":["agent","express","express-js","express-middleware","javascript","logger","logger-middleware","logging","logging-and-metrics","metrics","monitoring","morgan","morgan-middleware","nodejs","sematext","sematext-agent-express","winston","winston-logsene"],"latest_commit_sha":null,"homepage":"https://sematext.com/docs/integration/express.js/","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}},"created_at":"2019-12-08T17:43:59.000Z","updated_at":"2025-03-16T08:24:47.000Z","dependencies_parsed_at":"2023-02-18T03:45:57.656Z","dependency_job_id":null,"html_url":"https://github.com/sematext/sematext-agent-express","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fsematext-agent-express","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fsematext-agent-express/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fsematext-agent-express/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sematext%2Fsematext-agent-express/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sematext","download_url":"https://codeload.github.com/sematext/sematext-agent-express/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251355425,"owners_count":21576357,"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","express","express-js","express-middleware","javascript","logger","logger-middleware","logging","logging-and-metrics","metrics","monitoring","morgan","morgan-middleware","nodejs","sematext","sematext-agent-express","winston","winston-logsene"],"created_at":"2024-11-11T15:14:29.568Z","updated_at":"2025-04-28T17:31:36.550Z","avatar_url":"https://github.com/sematext.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sematext Agent Express\n\n[![Build Status](https://travis-ci.org/sematext/sematext-agent-express.svg?branch=master)](https://travis-ci.org/sematext/sematext-agent-express)\n\n[![NPM](https://nodei.co/npm/sematext-agent-express.png)](https://nodei.co/npm/sematext-agent-express/)\n\nThis is the Express.js monitoring and logging agent for [Sematext](https://sematext.com/). The following data is collected and shipped to Sematext [Cloud](https://sematext.com/cloud/) / [Enterprise](https://sematext.com/enterprise/):\n\n- OS Metrics (CPU / Mem)\n- Process Memory\n- Process Metrics\n- EventLoop Metrics\n- Garbage Collector Metrics\n- Web Server Metrics:\n  - request rate\n  - error rate\n  - response times\n  - content size\n- HTTP Logs per API endpoint:\n  - response times\n  - content size\n  - URL\n  - status\n  - method\n- Custom Logs:\n  - Instead of using `console.log` ship all logs directly to Sematext Logs with `stLogger`\n\n## Quickstart \n\n1. Sign up to [Sematext for free](https://apps.sematext.com/ui/registration)  \n2. [Create a Node.js Monitoring App](https://apps.sematext.com/ui/integrations) and copy the Monitoring App Token\n3. [Create a Logs App](https://apps.sematext.com/ui/integrations) and copy the Logs App Token\n4. Install the `sematext-agent-express` npm module\n4. Configure environment variables\n5. Run the agent using the App tokens provided for your Monitoring and Logs Apps\n\n## Create Apps in Sematext\n\nAfter you sign up to Sematext [here](https://apps.sematext.com/ui/registration), you need to create Apps to store metrics and logs data.\n\n1. Create a [Logs App](https://sematext.com/docs/logs/quick-start/)\n2. Create a [Monitoring App](https://sematext.com/docs/monitoring/quick-start/)\n\n## Installation\n\nInstall the package from the NPM registry.\n\n```bash\nnpm i sematext-agent-express\n```\n\n## Configure Environment\n\nMake sure to configure your ENVIRONMENT variables before adding `sematext-agent-express`. You can do this either by exporting the variables to your environment or by using `dotenv`. We suggest you use `dotenv`.\n\n### Export env vars\n\nIf you are using the US region of Sematext Cloud:\n\n```bash\nexport MONITORING_TOKEN=\u003cYOUR_MONITORING_TOKEN\u003e\nexport LOGS_TOKEN=\u003cYOUR_LOGS_TOKEN\u003e\nexport INFRA_TOKEN=\u003cYOUR_INFRA_TOKEN\u003e\n```\n\nIf you are using the EU region of Sematext Cloud:\n\n```bash\nexport REGION=EU\nexport MONITORING_TOKEN=\u003cYOUR_MONITORING_TOKEN\u003e\nexport LOGS_TOKEN=\u003cYOUR_LOGS_TOKEN\u003e\nexport INFRA_TOKEN=\u003cYOUR_INFRA_TOKEN\u003e\n```\n\n### Use dotenv\n\n```bash\nnpm i dotenv\n```\n\nCreate a `.env` file in the root of your project.\n\nAdd this code if you are using the US region of Sematext Cloud:\n\n```\nMONITORING_TOKEN=\u003cYOUR_MONITORING_TOKEN\u003e\nLOGS_TOKEN=\u003cYOUR_LOGS_TOKEN\u003e\nINFRA_TOKEN=\u003cYOUR_INFRA_TOKEN\u003e\n```\n\nAdd this code if you are using the EU region of Sematext Cloud:\n\n```\nREGION=EU\nMONITORING_TOKEN=\u003cYOUR_MONITORING_TOKEN\u003e\nLOGS_TOKEN=\u003cYOUR_LOGS_TOKEN\u003e\nINFRA_TOKEN=\u003cYOUR_INFRA_TOKEN\u003e\n```\n\n## Configure Agent\n\nMake sure to load the environment variables at the top of your JavaScript entry point file. Then require `sematext-agent-express`.\n\nThe Agent has 3 parts:\n\n- `stMonitor` - Monitors metrics and sends to Sematext Monitoring\n- `stLogger` - A logger based on `winston`, that will send logs directly to Sematext Logs\n- `stHttpLoggerMiddleware` - Express.js middleware function that will send all HTTP endpoint logs to Sematext Logs\n\n### Usage\n\n```javascript\n// Load env vars\nrequire('dotenv').config()\n\n// require all agents\nconst { stMonitor, stLogger, stHttpLoggerMiddleware } = require('sematext-agent-express')\n\n// Start monitoring metrics\nstMonitor.start()\n\n// ...\n\n// At the top of your routes add the stHttpLoggerMiddleware to send HTTP logs to Sematext\nconst express = require('express')\nconst app = express()\napp.use(stHttpLoggerMiddleware)\n\n// ...\n\n// Use the stLogger to send all types of logs directly to Sematext\napp.get('/api', (req, res, next) =\u003e {\n  stLogger.info('Hello World.')\n  stLogger.error('Some error.')\n  res.status(200).send('Hello World.')\n})\n```\n\nYou can use all parts of the Agent of use them separately. It's all up to you.\n\n## Result\nThe Agents will capture both metrics, logs, and HTTP logs per API endpoint.\n\n### Metrics\n\n![](https://cdn.sematext.com/images/sample-nodejs-metrics.png)\n\n### Logs\n\n![](https://cdn.sematext.com/images/sample-nodejs-logs.png)\n\n## Troubleshooting\nCheck out our [documentation](https://sematext.com/docs/integration/express.js/) for more information.\n\n## Built with\n\n- [spm-agent-nodejs](https://github.com/sematext/spm-agent-nodejs)\n- [winston](https://github.com/winstonjs/winston)\n- [winston-logsene](https://github.com/sematext/winston-logsene)\n- [morgan](https://github.com/expressjs/morgan)\n- [morgan-json](https://github.com/indexzero/morgan-json)\n\n## LICENSE\n\nApache 2 - see the [LICENSE](./LICENSE) file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsematext%2Fsematext-agent-express","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsematext%2Fsematext-agent-express","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsematext%2Fsematext-agent-express/lists"}