{"id":16189476,"url":"https://github.com/shuhei/rolling-window","last_synced_at":"2025-09-25T02:31:44.487Z","repository":{"id":39898086,"uuid":"164155547","full_name":"shuhei/rolling-window","owner":"shuhei","description":"A rolling time window implementation for hdr-histogram-js","archived":false,"fork":false,"pushed_at":"2024-05-04T12:35:22.000Z","size":1432,"stargazers_count":6,"open_issues_count":15,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-31T07:07:36.446Z","etag":null,"topics":["hdr-histogram","histogram","metrics","node","nodejs","rolling-time-window"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/shuhei.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,"zenodo":null}},"created_at":"2019-01-04T21:16:18.000Z","updated_at":"2024-05-04T12:35:26.000Z","dependencies_parsed_at":"2025-05-30T22:21:36.828Z","dependency_job_id":"86f57a36-72f7-4e3d-afec-2a7cb6510237","html_url":"https://github.com/shuhei/rolling-window","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/shuhei/rolling-window","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuhei%2Frolling-window","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuhei%2Frolling-window/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuhei%2Frolling-window/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuhei%2Frolling-window/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shuhei","download_url":"https://codeload.github.com/shuhei/rolling-window/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuhei%2Frolling-window/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276848182,"owners_count":25715259,"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-09-25T02:00:09.612Z","response_time":80,"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":["hdr-histogram","histogram","metrics","node","nodejs","rolling-time-window"],"created_at":"2024-10-10T07:35:35.928Z","updated_at":"2025-09-25T02:31:44.200Z","avatar_url":"https://github.com/shuhei.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rolling-window\n\n[![Actions Status](https://github.com/shuhei/rolling-window/workflows/NodeCI/badge.svg)](https://github.com/shuhei/rolling-window/actions)\n[![Codecov](https://codecov.io/gh/shuhei/rolling-window/branch/master/graph/badge.svg)](https://codecov.io/gh/shuhei/rolling-window)\n[![npm version](https://badge.fury.io/js/%40shuhei%2Frolling-window.svg)](https://badge.fury.io/js/%40shuhei%2Frolling-window)\n\nImplements \"Reset reservoir periodically by chunks\" strategy to use [hdr-histogram-js](https://github.com/HdrHistogram/HdrHistogramJS) for monitoring. Inspired by [vladimir-bukhtoyarov/rolling-metrics](https://github.com/vladimir-bukhtoyarov/rolling-metrics). No additional dependencies.\n\nSee [rolling-metrics' documentation](https://github.com/vladimir-bukhtoyarov/rolling-metrics/blob/master/histograms.md) for the background.\n\n## Install\n\nWith `hdr-histogram-js@2`:\n\n```sh\nnpm install -S hdr-histogram-js @shuhei/rolling-window\n```\n\nWith `hdr-histogram-js@1`:\n\n```sh\nnpm install -S hdr-histogram-js@1 @shuhei/rolling-window@^0.2.1\n```\n\n## Usage\n\n```js\nconst { RollingWindowHistogram } = require(\"@shuhei/rolling-window\");\n\n// This configuration creates 7 internal histograms (6 + 1) and rotates them\n// one by one in each 10 seconds. `getSnapshot()` returns a histogram of the\n// last 60 to 70 seconds. These additional 0 to 10 seconds make sure that the\n// rolling window can provide a fresh histogram without losing any records at\n// any given time.\nconst rollingWindowHistogram = new RollingWindowHistogram({\n  timeWindow: 1000 * 60,\n  numChunks: 6,\n});\n\n// Record a value\nrollingWindowHistogram.recordValue(value);\n\n// Get a snapshot\nconst snapshot = rollingWindowHistogram.getSnapshot();\nconst p99 = snapshot.getValueAtPercentile(99);\n```\n\n## API\n\n### new RollingWindowHistogram([options])\n\n- `options`\n  - `timeWindow: number` The length of a time window in milliseconds. **Default: `60000`**\n  - `numChunks: number` The number of chunks in the time window. **Default: `6`**\n  - `buildHistogram: () =\u003e Histogram` A factory function to create a histogram. This will be called multiple times to prepare necessary histograms in the rolling window. Use this to provide custom options to histograms. **Default: `build` from `hdr-histogram-js`**\n\nCreates a rolling window histogram with `numChunks + 1` histograms in it and starts rotating chunks with an interval of `timeWindow / numChunks`.\n\n### rollingWindowHistogram.stop()\n\nStop the rotation timer. When you stop using a rolling window histogram, make sure to call this method to avoid memory leak.\n\n### rollingWindowHistogram.recordValue(value)\n\n- `value: number` A numerical value to record. It must not be negative.\n\n### rollingWindowHistogram.getSnapshot([snapshot])\n\n- `snapshot: Histogram` A histogram to accumulate histograms. It is reset before accumulating histograms. If this is not provided, a `Histogram` is created and kept for reuse.\n- Returns: `Histogram`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuhei%2Frolling-window","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshuhei%2Frolling-window","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshuhei%2Frolling-window/lists"}