{"id":15673724,"url":"https://github.com/lmammino/metrica","last_synced_at":"2025-05-09T00:32:59.950Z","repository":{"id":57295992,"uuid":"134427761","full_name":"lmammino/metrica","owner":"lmammino","description":"Event Emitter based node library that emits process metrics (uptime, memory, cpu) at given intervals","archived":false,"fork":false,"pushed_at":"2018-05-23T14:01:24.000Z","size":54,"stargazers_count":6,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-03T19:41:11.048Z","etag":null,"topics":["cpu","eventemitter","library","metrics","nodejs","process-metrics","uptime"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmammino.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-05-22T14:29:09.000Z","updated_at":"2023-05-12T16:51:15.000Z","dependencies_parsed_at":"2022-08-31T22:32:17.729Z","dependency_job_id":null,"html_url":"https://github.com/lmammino/metrica","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmetrica","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmetrica/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmetrica/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmammino%2Fmetrica/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmammino","download_url":"https://codeload.github.com/lmammino/metrica/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253171056,"owners_count":21865275,"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":["cpu","eventemitter","library","metrics","nodejs","process-metrics","uptime"],"created_at":"2024-10-03T15:41:51.397Z","updated_at":"2025-05-09T00:32:59.882Z","avatar_url":"https://github.com/lmammino.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# metrica\n\n[![npm version](https://badge.fury.io/js/metrica.svg)](http://badge.fury.io/js/metrica)\n[![CircleCI](https://circleci.com/gh/lmammino/metrica.svg?style=shield)](https://circleci.com/gh/lmammino/metrica)\n[![codecov.io](https://codecov.io/gh/lmammino/metrica/coverage.svg?branch=master)](https://codecov.io/gh/lmammino/metrica)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nEvent Emitter based node library that emits process metrics (uptime, memory, cpu) at given intervals\n\n\n## Install \u0026 quick usage\n\n**Requirements**: this library is written for Node.js \u003e= 6.0\n\nAs usual, this happens through NPM:\n\n```bash\nnpm install --save metrica\n```\n\nThen, in your code:\n\n```javascript\nconst m = require('metrica')()\n// metrics is an event emitter\n\nm.on('tick', (data) =\u003e console.log(data))\n// tick happens (by default) every minute and data will look like:\n// {\n//   cpu: {\n//     user: 129255,\n//     system: 25515\n//   },\n//   memory: {\n//     rss: 21843968,\n//     heapTotal: 8208384,\n//     heapUsed: 5394352,\n//     external: 8628\n//   },\n//   uptime: 44.858\n// }\n```\n\n\n## 🤔 Rationale\n\nWhen running your Node.js app in production you might be interested in gathering metrics\nabout the running process. Perhaps, you want to log this information or send it to\na centralized metrics system.\n\nThis library gives you an easy way to collect process metric continuously and offers\na convenient event based interface so that you can easily attach your custom logic\nto handle the new metrics.\n\n\n## Options\n\nWhen instantiating a new process metrics you can specify some options:\n\ninterval: 60000,\nautoStart: true\n\n  - `interval` (default `60000`) - Allows you to specify how often the metrics are collected.\n    This can be a number (milliseconds) or a string expression as supported by the [`ms` module](http://npm.im/ms)\n  - `autoStart` (default `true`) - Will automatically start the collection of metrics at given intervals. If set to `false`\n    you should start the collection with the `.start()` method\n\n## Methods\n\nA process metrics instance will expose few methods:\n\n  - `.start()` - Will start the automatic collection of metrics (which will trigger `tick` events at given intervals)\n  - `.stop()` - Will stop the automatic collection of metrics\n  - `.getMetrics()` - Will get and return the current metrics. It's not going to trigger a `tick` event.\n\n## Events\n\nA process metrics instance is an event emitter and will emit the following events:\n\n  - `tick` - triggered continuously at the given interval time. It will contain as a payload the\n    current metrics object.\n\n\n## Complete example\n\nThis example will collect and log metrics for 5 seconds and then stop the collection:\n\n```javascript\nconst metrica = require('metrica')\nconst m = metrica({ interval: '1s', autoStart: false })\nm.on('tick', (metrics) =\u003e console.log('Tick:', metrics))\nsetTimeout(() =\u003e m.stop(), 5000)\nm.start()\n```\n\n\n## 👯‍ Contributing\n\nEveryone is very welcome to contribute to this project.\nYou can contribute just by submitting bugs or suggesting improvements by\n[opening an issue on GitHub](https://github.com/lmammino/metrica/issues).\n\n\n## 🤦‍ License\n\nLicensed under [MIT License](LICENSE). © Luciano Mammino.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fmetrica","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmammino%2Fmetrica","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmammino%2Fmetrica/lists"}