{"id":15270862,"url":"https://github.com/phara0h/nstats","last_synced_at":"2026-03-11T00:33:18.247Z","repository":{"id":34503190,"uuid":"38444153","full_name":"Phara0h/nstats","owner":"Phara0h","description":"A fast and compact way to get all your network and process stats for your node application","archived":false,"fork":false,"pushed_at":"2025-02-13T15:44:08.000Z","size":101,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-08T22:02:39.829Z","etag":null,"topics":["compact","express","express-middleware","fast","fastify","fastify-plugin","grafana","hacktoberfest","js","metrics","node","node-js","node-module","process-stats","prometheus","stats"],"latest_commit_sha":null,"homepage":"http://phara0h.github.io/nstats/","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/Phara0h.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-07-02T16:32:52.000Z","updated_at":"2025-06-06T21:20:49.000Z","dependencies_parsed_at":"2025-02-14T13:45:57.299Z","dependency_job_id":null,"html_url":"https://github.com/Phara0h/nstats","commit_stats":{"total_commits":33,"total_committers":3,"mean_commits":11.0,"dds":"0.21212121212121215","last_synced_commit":"3b4a534b6605d0dee6607a07feac87bbd6667447"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Phara0h/nstats","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phara0h%2Fnstats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phara0h%2Fnstats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phara0h%2Fnstats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phara0h%2Fnstats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Phara0h","download_url":"https://codeload.github.com/Phara0h/nstats/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Phara0h%2Fnstats/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269366853,"owners_count":24405250,"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","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["compact","express","express-middleware","fast","fastify","fastify-plugin","grafana","hacktoberfest","js","metrics","node","node-js","node-module","process-stats","prometheus","stats"],"created_at":"2024-09-30T08:05:01.699Z","updated_at":"2026-03-11T00:33:18.201Z","avatar_url":"https://github.com/Phara0h.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nstats\nA fast and compact way to get all your network and process stats for your node application. Websocket, http/s, express and prometheus compatible!\n\n## Installation\n\n```bash\n$ npm install nstats\n```\n## Quick Start (Express)\n\n```javascript\n// ws is a websocket server (ws.js) and httpServer is an http or https node server.\nvar nstats = require('nstats')(ws, httpServer);\n\n//use it with express\napp.use(nstats.express());\n\n//display the stats!\nconsole.log(nstats.data); // non-stringifyed\nconsole.log(nstats.toJson()) // stringifyed\nconsole.log(nstats.toPrometheus()) //  prometheus format\n```\n\n## Quick Start (Fastify 4.x.x)\n\n```javascript\n// ws is a websocket server (ws.js) and httpServer is an http or https node server.\nvar nstats = require('nstats')();\n\n//use it with express\napp.register(nstats.fastify(),{\n  ignored_routes:['/metrics','/health']\n});\n\napp.get('/metrics', (req, res) =\u003e {\n  res.code(200).send(nstats.toPrometheus());\n});\n\napp.get('/health', (req, res) =\u003e res.code(200).send('All Systems Nominal'));\n\n\n//display the stats!\nconsole.log(nstats.data); // non-stringifyed\nconsole.log(nstats.toJson()) // stringifyed\nconsole.log(nstats.toPrometheus()) //  prometheus format\n```\n\n\n## Grafana Sample\nImport the Grafana Dashboard example inside the Grafana folder to view the the stats\nin a graph like manner.\n\n## Example\n\n```js\nconst express = require('express');\nconst nstats = require('nstats');\nconst WebSocket = require('ws');\nconst app = express();\nconst server = require('http').createServer(app);\nconst port = 3042;\nconst wss = new WebSocket.Server({ server });\n\nvar stats = require('nstats')(wss, server);\nstats.interval = 500;\nstats.serverName = \"TestServer\";\n\nwss.on('connection', function connection(ws) {\n  ws.on('message', function incoming(message) {\n      ws.send(message);\n  });\n});\n\napp.use(stats.express());\n\napp.get('/', (req, res) =\u003e res.send());\napp.get('/metrics', (req, res) =\u003e res.send(stats.toPrometheus()));\napp.get('/stats', (req, res) =\u003e {\n  res.type('json')\n  stats.calc(()=\u003eres.send(stats.toJson()));\n});\n\nserver.listen(port, () =\u003e console.log(`Example app listening on port ${port}!`));\n\n```\n##Properties\n\n####`stats.data`\nThe `stats.data` object is a JavaScript object containing all the stats.\n\n```js\n{\n    \"uptime\": 209.653,\n    \"totalMemory\": \"29.17\",\n    \"activeSockets\": 2,\n    \"responseOverhead\": {\n        \"avg\": 0.5810644392156861,\n        \"highest\": 5.175994,\n        \"lowest\": 0.260562,\n        \"total\": 148.17143199999995\n    },\n    \"avgWriteKBs\": \"3.26\",\n    \"avgReadKBs\": \"0.28\",\n    \"avgPacketsSecond\": \"1.22\",\n    \"totalBytesWritten\": 700381,\n    \"totalMBytesWritten\": 0.67,\n    \"totalBytesRead\": 60813,\n    \"totalMBytesRead\": 0.06,\n    \"writeKBS\": \"0.00\",\n    \"readKBS\": \"0.00\",\n    \"packetsSecond\": \"0.00\",\n    \"totalPackets\": 255,\n    \"http\": {\n        \"GET\": {\n            \"200\": 255\n        }\n    }\n}\n```\nfeel free to add your own stats you want to keep track off too!\n\n```js\nstats.data['foo'] = \"some dank stat\";\n```\n\n---\n\n####`stats.interval`\nA time in milliseconds on when the stats will refresh and calculate.\n\n```js\nstats.interval = 5000; // default is 1 second\n```\nSet this to 0 if you do not want it to loop.\n\n##Methods\n`stats.addWeb(req,res,sTime)`\n\nA method to add network usage for http requests not done with express or w.s.\nres is optional if you want stats.data.http data.\nsTime (The start time of when you received the req BigInt) is optional if you want responseOverhead data.\n\n```js\nvar req = http.get(\"http://google.com\", function(res) {\n    res.on('end', function() {\n      stats.addWeb(req, res);\n    });\n});\n```\nSince its not express or ws, it does not know about it.\n\n---\n`stats.calc()`\n\nA method to allow you to manually trigger when the stats are computed.\n\noptional call back can be passed to let you know its done.\n\n```js\nstats.calc(function(){\n  //its done!\n  console.log(stats.data);\n});\n```\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphara0h%2Fnstats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphara0h%2Fnstats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphara0h%2Fnstats/lists"}