{"id":15842357,"url":"https://github.com/bobbytes/node-service-metrics-logger","last_synced_at":"2026-02-17T22:31:22.106Z","repository":{"id":35054554,"uuid":"201219620","full_name":"bobbytes/node-service-metrics-logger","owner":"bobbytes","description":"Service Metrics Logger","archived":false,"fork":false,"pushed_at":"2023-01-04T06:36:43.000Z","size":1493,"stargazers_count":0,"open_issues_count":16,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-26T21:27:19.846Z","etag":null,"topics":["cloudfoundry","database","javascript","logger","metrics","mongodb","nodejs","rabbitmq","redis","service","type","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bobbytes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-08T08:58:12.000Z","updated_at":"2020-05-27T11:12:47.000Z","dependencies_parsed_at":"2023-01-15T12:51:31.408Z","dependency_job_id":null,"html_url":"https://github.com/bobbytes/node-service-metrics-logger","commit_stats":null,"previous_names":["danautilus/node-service-metrics-logger"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/bobbytes/node-service-metrics-logger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbytes%2Fnode-service-metrics-logger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbytes%2Fnode-service-metrics-logger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbytes%2Fnode-service-metrics-logger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbytes%2Fnode-service-metrics-logger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bobbytes","download_url":"https://codeload.github.com/bobbytes/node-service-metrics-logger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bobbytes%2Fnode-service-metrics-logger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29560722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T21:50:49.831Z","status":"ssl_error","status_checked_at":"2026-02-17T21:46:15.313Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["cloudfoundry","database","javascript","logger","metrics","mongodb","nodejs","rabbitmq","redis","service","type","typescript"],"created_at":"2024-10-05T17:01:21.318Z","updated_at":"2026-02-17T22:31:22.079Z","avatar_url":"https://github.com/bobbytes.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eNode Service Metrics Logger\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://david-dm.org/DaNautilus/node-service-metrics-logger\"\u003e\n    \u003cimg src=\"https://david-dm.org/DaNautilus/node-service-metrics-logger/status.svg?style=flat\" alt=\"dependency\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/DaNautilus/node-service-metrics-logger\"\u003e\n    \u003cimg src=\"https://travis-ci.org/DaNautilus/node-service-metrics-logger.svg?branch=master\" alt=\"travis\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://ci.appveyor.com/project/DaNautilus/node-service-metrics-logger/branch/master\"\u003e\n    \u003cimg src=\"https://ci.appveyor.com/api/projects/status/dt0uy3lkpt22u4pu?svg=true\u0026passingText=windows%20passing\u0026pendingText=windows%20pending\u0026failingText=windows%20failing\" alt=\"appveyor\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://sonarcloud.io/dashboard?id=DaNautilus_node-service-metrics-logger\"\u003e\n    \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=DaNautilus_node-service-metrics-logger\u0026metric=coverage\" alt=\"coverage\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://sonarcloud.io/dashboard/index/DaNautilus_node-service-metrics-logger\"\u003e\n    \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=DaNautilus_node-service-metrics-logger\u0026metric=alert_status\" alt=\"quality gate\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr /\u003e\n\n![divider](./divider.png)\n\n## ❯ Why\n\nYou want to log service metrics from your application and push it to a metrics provided? - Yes? - Here you are 🙌 !!  \nCurrently there's only support for `Datadog` as metrics provider.\n\n![divider](./divider.png)\n\n## ❯ Table of Contents\n\n- [Supported Services](#-supported-services)\n- [Quick Start](#-quick-start)\n- [API](#-api)\n- [Cloud Connectors](#-cloud-connectors)\n- [Transports](#-transports)\n- [Development](#-development)\n- [Project Structure](#-project-structure)\n\n![divider](./divider.png)\n\n## ❯ Supported Services\n\n| Service      | Version  |\n| ------------ | -------- |\n| **MongoDB**  | \u003e=3.6.6  |\n| **Redis**    | \u003e=2.3.9  |\n| **RabbitMQ** | \u003e=3.7.15 |\n\n![divider](./divider.png)\n\n## ❯ Quick Start\n\n### Installation\n\nInstall library by using `npm`\n\n```shell\nnpm install node-service-metrics-logger\n```\n\nor by using `yarn`\n\n```shell\nyarn add node-service-metrics-logger\n```\n\n### How to use\n\n#### Step 1: Import NodeServiceMetricsLogger\n\nUsing `CommonJS` module loader:\n\n```javascript\nconst NodeServiceMetricsLogger = require('node-service-metrics-logger);\n```\n\nUsing `ES6` module loader:\n\n```javascript\nimport { NodeServiceMetricsLogger } from 'node-service-metrics-logger;\n```\n\n#### Step 2: Create new instance of CfServiceMetricsLogger\n\nCreate new instance of `NodeServiceMetricsLogger` and provide options:\n\n```javascript\nconst serviceCredentials = [\n  {\n    serviceType: 'mongodb',\n    host: 'your-mongodb-host',\n    username: 'user',\n    password: 'this-is-secret',\n    port: 27017\n    database: 'your-database-name',\n  },\n  {\n    serviceType: 'redis',\n    host: 'your-redis-host',\n    port: 6379,\n    password: 'this-is-secret',\n  }\n];\n\nconst nodeServiceMetricsLogger = new NodeServiceMetricsLogger({serviceCredentials});\n```\n\n#### Step 3: Subscribe to receive service metrics and general logs\n\nSubscribe `metrics` to receive service metrics data:\n\n```javascript\nnodeServiceMetricsLogger.subscribe('metrics', data =\u003e {\n  // do some fancy stuff with your metrics\n});\n```\n\nSubscribe `logs` to receive general application logs:\n\n```javascript\nnodeServiceMetricsLogger.subscribe('logs', {message, level} =\u003e {\n  console[level](message));\n});\n```\n\n#### Step 3: Start and stop service metrics logging\n\nStart service metrics logging:\n\n```javascript\nnodeServiceMetricsLogger.start();\n```\n\nStop service metrics logging:\n\n```javascript\nnodeServiceMetricsLogger.stop();\n```\n\n![divider](./divider.png)\n\n## ❯ API\n\n### Credentials Options\n\n| Option                | Description                                                                    | Default Value |\n| --------------------- | ------------------------------------------------------------------------------ | ------------: |\n| `serviceType`         | Type of service. Currently only `mongodb`, `redis` and `rabbitmq` are available |               |\n| `name`                | Name of credential to identify your specific service in a mass of logs          | your `host`   |\n| `host`                | Host of service                                                                 |               |\n| `port` (optional)     | Port of service                                                                 |               |\n| `uri` (optional)      | Instead of port and host, you can provide an URI                                |               |\n| `username` (optional) | Username                                                                        |               |\n| `password` (optional) | Password                                                                        |               |\n| `interval` (optional) | Service metrics polling interval in ms                                          | `10000`       | \n\n### Methods\n\n| Method                           | Description            |\n| -------------------------------- | ---------------------- |\n| `start()`                        | Start service metrics  |\n| `stop()`                         | Stop service metrics   |\n| `subscribe(eventId, callback)`   | Subscribe an event     |\n| `unsubscribe(eventId, callback)` | Unsubscribe an event   |\n| `unsubscribeAll()`               | Unsubscribe all events |\n\n### Subscription event id's\n\n| Id        | Description                                                            |\n| --------- | ---------------------------------------------------------------------- |\n| `metrics` | Service metrics                                                        |\n| `logs`    | General application logs for levels `debug`, `info`, `warn` and `error` |\n\n![divider](./divider.png)\n\n## ❯ Cloud Connectors\n\nYou can use a cloud connector to log metrics from your cloud instance services.\n\n### Cloud Foundry\n\n#### Options\n\n| Option                                    | Description                                                    | Default Value |\n| ----------------------------------------- | -------------------------------------------------------------- | ------------: |\n| `vcap` (optional)                         | Provide local `VCAP_SERVICES` and/or `VCAP_APPLICATION` values | `{}`          |\n| `vcapFile` (optional)                     | Provide local `VCAP_SERVICES` and/or `VCAP_APPLICATION` file   | `''`          |\n\n#### Methods\n\n| Method             | Description                           |\n| ------------------ | ------------------------------------- |\n| `getCredentials()` | Get Cloud Foundry service credentials |\n\n#### Example\n\n```javascript\n// import using `CommonJS` module loader:\nconst { CloudFoundryConnector, NodeServiceMetricsLogger } = require('node-service-metrics-logger');\n\n// or import using `ES6` module loader:\nimport { CloudFoundryConnector, NodeServiceMetricsLogger } from 'node-service-metrics-logger';\n\nconst options = {\n  vcapFile: 'your-vcap-file-path/vcap.json' \n};\n\nconst cloudFoundryConnector = new CloudFoundryConnector(options);\nconst serviceCredentials = cloudFoundryConnector.getCredentials();\nconst nodeServiceMetricsLogger = new NodeServiceMetricsLogger({serviceCredentials});\n\nnodeServiceMetricsLogger.subscribe('metrics', data =\u003e {\n  // do some fancy stuff with your metrics\n});\n\nnodeServiceMetricsLogger.start();\n\nsetTimeout(() =\u003e {\n  nodeServiceMetricsLogger.stop();\n}, 30000);\n```\n\n![divider](./divider.png)\n\n## ❯ Transports\n\nWith transports you can log metrics to metrics services like Datadog. Datadog is currently the one and only implemented transport.\n\n###  Datadog\n\n#### Example\n\n```javascript\n// import using `CommonJS` module loader:\nconst { NodeServiceMetricsLogger, DatadogTransport } = require('node-service-metrics-logger');\n\n// or import using `ES6` module loader:\nimport { NodeServiceMetricsLogger, DatadogTransport } from 'node-service-metrics-logger';\n\nconst datadogTransport = new DatadogTransport({\n  apiKey: 'datadog-api-key',\n  appKey: 'datadog-app-key',\n  host: 'app.datadoghq.com',\n  tags: ['env:development']\n});\n\nconst serviceCredentials = [\n  {\n    serviceType: 'mongodb',\n    host: 'your-mongodb-host',\n    username: 'user',\n    password: 'this-is-secret',\n    port: 27017,\n    database: 'your-database-name',\n  }\n];\n\nconst nodeServiceMetricsLogger = new NodeServiceMetricsLogger({\n  serviceCredentials,\n  transports: [datadogTransport],\n});\n\nnodeServiceMetricsLogger.start();\n```\n\n## ❯ Development\n\n### Getting Started\n\n#### Step 1: Set up the Development Environment\n\nYou need to set up your development environment before you can do anything.\n\nInstall [Node.js and NPM](https://nodejs.org/en/download/)\n\n- on OSX use [homebrew](http://brew.sh) `brew install node`\n- on Windows use [chocolatey](https://chocolatey.org/) `choco install nodejs`\n\nInstall yarn globally\n\n```bash\nyarn install yarn -g\n```\n\n#### Step 2: Install dependencies\n\nInstall all dependencies with yarn.\n\n```bash\nyarn install\n```\n\n### Scripts and Tasks\n\n#### Install\n\n- Install all dependencies with `yarn install`\n\n#### Linting\n\n- Run code quality analysis using `yarn run lint`. This runs tslint.\n\n#### Tests\n\n- Run unit test using `yarn run test`.\n\n#### Building the project\n\n- Run `yarn run build` to generate commonJS and ES6 modules as well as declaration from the TypeScript source.\n- Builded sources are located in `dist` folder.\n\n### Debugger\n\n#### VS Code\n\nJust set a breakpoint in source or unit test and hit \u003ckbd\u003eF5\u003c/kbd\u003e in your Visual Studio Code to execute and debug all unit tests.\n\n![divider](./divider.png)\n\n## ❯ Project Structure\n\n| Name                              | Description |\n| --------------------------------- | ----------- |\n| **.vscode/**                      | VSCode tasks, launch configuration and some other settings |\n| **dist/**                         | Compiled and bundled source files will be placed here |\n| **src/**                          | Source files |\n| **src/types/** *.d.ts             | Custom type definitions and files that aren't on DefinitelyTyped |\n| **test/**                         | Tests |\n| **test/unit/** *.test.ts          | Unit tests |\n| rollup.config.js                  | Config for Rollup module bundler |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbytes%2Fnode-service-metrics-logger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobbytes%2Fnode-service-metrics-logger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobbytes%2Fnode-service-metrics-logger/lists"}