{"id":22093197,"url":"https://github.com/iadvize/nodejs-prometheus-wrapper","last_synced_at":"2026-01-12T05:36:29.167Z","repository":{"id":57331224,"uuid":"57888543","full_name":"iadvize/nodejs-prometheus-wrapper","owner":"iadvize","description":"Wrapper to official NodeJS Prometheus exporter ","archived":false,"fork":false,"pushed_at":"2022-07-23T13:41:41.000Z","size":40,"stargazers_count":17,"open_issues_count":1,"forks_count":2,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-08-19T04:09:29.999Z","etag":null,"topics":["metrics","nodejs","prometheus"],"latest_commit_sha":null,"homepage":"","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/iadvize.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null}},"created_at":"2016-05-02T12:25:29.000Z","updated_at":"2021-03-31T09:02:15.000Z","dependencies_parsed_at":"2022-09-21T02:10:54.775Z","dependency_job_id":null,"html_url":"https://github.com/iadvize/nodejs-prometheus-wrapper","commit_stats":null,"previous_names":["iadvize/prometheus-wrapper"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/iadvize/nodejs-prometheus-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fnodejs-prometheus-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fnodejs-prometheus-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fnodejs-prometheus-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fnodejs-prometheus-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iadvize","download_url":"https://codeload.github.com/iadvize/nodejs-prometheus-wrapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iadvize%2Fnodejs-prometheus-wrapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28335215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T00:36:25.062Z","status":"online","status_checked_at":"2026-01-12T02:00:08.677Z","response_time":98,"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":["metrics","nodejs","prometheus"],"created_at":"2024-12-01T03:13:15.968Z","updated_at":"2026-01-12T05:36:29.135Z","avatar_url":"https://github.com/iadvize.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"NodeJS Prometheus Wrapper [![CircleCI](https://circleci.com/gh/iadvize/nodejs-prometheus-wrapper.svg?style=svg)](https://circleci.com/gh/iadvize/nodejs-prometheus-wrapper)\n===========================\n\nWrapper to official NodeJS Prometheus exporter ([prom-client](https://github.com/siimon/prom-client))\n\nThe official NodeJS client for prometheus requires to transporter the metrics variables in your code (counters, gauges, histograms and summaries).\n\nThis small library allow to control variables from the whole code, in a singleton, by getting the metric by name, just like that: ```require('prometheus-wrapper').get(\"\u003ccounter-name\u003e\").inc()```\n\n## Examples\n\ninit.js\n\n```javascript\nvar prometheus = require(\"prometheus-wrapper\");\n\nvar express = require('express');\nvar app = express();\n\nprometheus.setNamespace(\"myapp\");\n\napp.get('/metrics', function(req, res) {\n  res.end(prometheus.getMetrics());\n});\n\n// Counter\nprometheus.createCounter(\"mycounter\", \"A number we occasionally increment.\");\n\n// Gauge\nprometheus.createGauge(\"mygauge\", \"A random number we occasionally set.\");\n\n// Histogram\nprometheus.createHistogram(\"myhistogram\", \"A chat duration histogram.\", {\n\tbuckets: [ 10, 30, 60, 300, 600, 1800, 3600 ]\n});\n\n// Summary\nprometheus.createSummary(\"mysummary\", \"Compute quantiles and median of a random list of numbers.\", {\n\tpercentiles: [ 0.01, 0.1, 0.5, 0.9, 0.99 ]\n});\n\napp.listen(8080);\n```\n\nwherever-in-your-code.js\n\n```javascript\nvar prometheus = require(\"prometheus-wrapper\");\n\nsetInterval(function () {\n\tprometheus.get(\"mycounter\").inc(42);\n}, 10000);\n\nprometheus.get(\"mygauge\").set(42);\n\nvar end = prometheus.get(\"myhistogram\").startTimer();\nsetTimeout(function () {\n\tend();\n}, 15000);\n\nfor (var i = 0; i \u003c 100000; ++i) {\n\tprometheus.get(\"mysummary\").observe(Math.random());\n}\n```\n\nExposed ```/metrics``` :\n\n```sh\n$ curl 127.0.0.1:8080\n\n# HELP myapp_mycounter A number we occasionally increment.\n# TYPE myapp_mycounter counter\nmyapp_mycounter 84\n\n# HELP myapp_mygauge A random number we occasionally set.\n# TYPE myapp_mygauge gauge\nmyapp_mygauge 42\n\n# HELP examples_myhistogram A chat duration histogram.\n# TYPE examples_myhistogram histogram\nmyapp_myhistogram_bucket{le=\"10\"} 0\nmyapp_myhistogram_bucket{le=\"30\"} 1\nmyapp_myhistogram_bucket{le=\"60\"} 1\nmyapp_myhistogram_bucket{le=\"300\"} 1\nmyapp_myhistogram_bucket{le=\"600\"} 1\nmyapp_myhistogram_bucket{le=\"1800\"} 1\nmyapp_myhistogram_bucket{le=\"3600\"} 1\nmyapp_myhistogram_bucket{le=\"+Inf\"} 1\nmyapp_myhistogram_sum 15.002\nmyapp_myhistogram_count 1\n\n# HELP myapp_mysummary Compute quantiles and median of a random list of numbers.\n# TYPE myapp_mysummary summary\nmyapp_mysummary{quantile=\"0.01\"} 0.009997170550270069\nmyapp_mysummary{quantile=\"0.1\"} 0.09957970759409267\nmyapp_mysummary{quantile=\"0.5\"} 0.5016970195079504\nmyapp_mysummary{quantile=\"0.9\"} 0.8993228241841542\nmyapp_mysummary{quantile=\"0.99\"} 0.9901868947762174\nmyapp_mysummary_sum 4999.807495853165\nmyapp_mysummary_count 10000\n```\n\n### Labels\n\nExample:\n\n```javascript\nvar prometheus = require(\"prometheus-wrapper\");\n\n// Init Counter\nprometheus.createCounter(\"mycounter\", \"A number we occasionally increment.\", ['foo']);\n\nsetInterval(function () {\n\tprometheus.get(\"mycounter\").inc({foo: 'bar'}, 42);\n\tprometheus.get(\"mycounter\").inc({foo: 'baz'}, 21);\n}, 10000);\n\nprometheus.get(\"mygauge\").set(42);\n```\n\n\n```sh\n$ curl 127.0.0.1:8080\n\n# HELP myapp_mycounter A number we occasionally increment.\n# TYPE myapp_mycounter counter\nmyapp_mycounter{foo=\"bar\"} 42\nmyapp_mycounter{foo=\"baz\"} 42\n```\n\n## Install\n\n```\nnpm install --save prometheus-wrapper\n```\n\n## Documentation\n\n### Full list of metrics types\n\n[Official documentation](https://prometheus.io/docs/concepts/metric_types/)\n\n#### Counter\n```\nA counter is a cumulative metric that represents a single numerical value that only ever goes up. A counter is typically used to count requests served, tasks completed, errors occurred, etc. Counters should not be used to expose current counts of items whose number can also go down, e.g. the number of currently running goroutines. Use gauges for this use case.\n```\n\n#### Gauge\n```\nA gauge is a metric that represents a single numerical value that can arbitrarily go up and down.\n\nGauges are typically used for measured values like temperatures or current memory usage, but also \"counts\" that can go up and down, like the number of running goroutines.\n```\n\n#### Histogram\n\n```\nA histogram samples observations (usually things like request durations or response sizes) and counts them in configurable buckets. It also provides a sum of all observed values.\n\nA histogram with a base metric name of \u003cbasename\u003e exposes multiple time series during a scrape:\n\n- cumulative counters for the observation buckets, exposed as \u003cbasename\u003e_bucket{le=\"\u003cupper inclusive bound\u003e\"}\n- the total sum of all observed values, exposed as \u003cbasename\u003e_sum\n- the count of events that have been observed, exposed as \u003cbasename\u003e_count (identical to \u003cbasename\u003e_bucket{le=\"+Inf\"} above)\n```\n\n#### Summary\n\n```\nSimilar to a histogram, a summary samples observations (usually things like request durations and response sizes). While it also provides a total count of observations and a sum of all observed values, it calculates configurable quantiles over a sliding time window.\n\nA summary with a base metric name of \u003cbasename\u003e exposes multiple time series during a scrape:\n\n- streaming φ-quantiles (0 ≤ φ ≤ 1) of observed events, exposed as \u003cbasename\u003e{quantile=\"\u003cφ\u003e\"}\n- the total sum of all observed values, exposed as \u003cbasename\u003e_sum\n- the count of events that have been observed, exposed as \u003cbasename\u003e_count\n```\n\n### Methods available\n\n#### setNamespace\n\n- ```client.setNamespace(\u003cnamespace\u003e)``` =\u003e prefixes every metric name\n\n#### getMetrics\n\n- ```client.getMetrics()``` =\u003e what to expose in your server under /metrics\n\n#### Counter\n\n- ```client.createCounter(\u003cname\u003e, \u003chelp\u003e, [ \u003clabel-list\u003e ])```\n- ```client.get(\u003cname\u003e).get()```\n- ```client.get(\u003cname\u003e).inc()```\n- ```client.get(\u003cname\u003e).inc(\u003cdelta\u003e)```\n\n#### Gauge\n\n- ```client.createGauge(\u003cname\u003e, \u003chelp\u003e, [ \u003clabel-list\u003e ])```\n- ```client.get(\u003cname\u003e).get()```\n- ```client.get(\u003cname\u003e).set(\u003cvalue\u003e)```\n- ```client.get(\u003cname\u003e).setToCurrentTime()``` =\u003e expose a timestamp in ms\n- ```var end = client.get(\u003cname\u003e).startTimer()``` =\u003e call ```end()``` to stop the timer, expose a timestamp in seconds\n\n#### Histogram\n- ```client.createHistogram(\u003cname\u003e, \u003chelp\u003e, buckets: [ \u003ccategories\u003e ], [ \u003clabel-list\u003e ])```\n- ```client.get(\u003cname\u003e).get()```\n- ```client.get(\u003cname\u003e).observe(\u003cvalue\u003e)```\n- ```client.get(\u003cname\u003e).reset()```\n- ```var end = client.get(\u003cname\u003e).startTimer()``` =\u003e call ```end()``` to stop the timer, expose a timestamp in seconds\n\n#### Summary\n- ```client.createSummary(\u003cname\u003e, \u003chelp\u003e, buckets: [ \u003ccategories\u003e ], [ \u003clabel-list\u003e ])```\n- ```client.get(\u003cname\u003e).get()```\n- ```client.get(\u003cname\u003e).observe(\u003cvalue\u003e)```\n- ```client.get(\u003cname\u003e).reset()```\n- ```var end = client.get(\u003cname\u003e).startTimer()``` =\u003e call ```end()``` to stop the timer, expose a timestamp in seconds\n\n## Contribute\n\nLook at contribution guidelines here : [CONTRIBUTING.md](CONTRIBUTING.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiadvize%2Fnodejs-prometheus-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiadvize%2Fnodejs-prometheus-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiadvize%2Fnodejs-prometheus-wrapper/lists"}