{"id":18347896,"url":"https://github.com/collaborne/node-http-prometheus-agent","last_synced_at":"2026-04-25T12:36:44.241Z","repository":{"id":55375751,"uuid":"257584366","full_name":"Collaborne/node-http-prometheus-agent","owner":"Collaborne","description":"Implementation of an http.Agent/https.Agent that exposes request metrics through prom-client","archived":false,"fork":false,"pushed_at":"2021-01-04T17:16:29.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T22:38:53.446Z","etag":null,"topics":["nodejs","prometheus"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Collaborne.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":"2020-04-21T12:12:42.000Z","updated_at":"2021-01-04T17:15:50.000Z","dependencies_parsed_at":"2022-08-14T22:50:39.911Z","dependency_job_id":null,"html_url":"https://github.com/Collaborne/node-http-prometheus-agent","commit_stats":null,"previous_names":["collaborne/nodejs-http-prometheus-agent"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Collaborne%2Fnode-http-prometheus-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Collaborne%2Fnode-http-prometheus-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Collaborne%2Fnode-http-prometheus-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Collaborne%2Fnode-http-prometheus-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Collaborne","download_url":"https://codeload.github.com/Collaborne/node-http-prometheus-agent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248127996,"owners_count":21052330,"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":["nodejs","prometheus"],"created_at":"2024-11-05T21:15:31.321Z","updated_at":"2026-04-25T12:36:44.207Z","avatar_url":"https://github.com/Collaborne.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-http-prometheus-agent\n\nImplementation of an http.Agent/https.Agent that exposes request metrics through [prom-client](https://github.com/siimon/prom-client).\n\n## Installation\n\n```sh\nnpm install --save node-http-prometheus-agent\nnpm install --save prom-client@^11\n```\n\n_Note: This library is only tested with prom-client 11.x, but a later version should work as well._\n\n## Usage\n\nThe purpose of the this agent is watch requests going through the NodeJS HTTP/HTTPS client library, and expose the path and their status through the prom-client.\n\n 1. Create a suitable `Counter` metric, for example for capturing requests from the AWS SDK:\n\n    ```js\n    const AWS_SDK_STATUS_CODE_METRIC = new Counter({\n        help: 'Counter for the status codes for requests from the AWS SDK',\n        labelNames: ['path', 'status', 'service'],\n        name: `aws_sdk_http_status`,\n    });\n    ```\n\n    The metric must minimally declare the `path` and `status` label names.\n\n 2. Create the agent\n\n    ```js\n    import { defaultAgent } from 'https';\n    import { wrapAgent } from 'node-http-prometheus-agent';\n\n    const s3Agent = wrapAgent(defaultAgent, AWS_SDK_STATUS_CODE_METRIC, {\n        extraLabels: {\n            'service': 's3',\n        },\n    });\n    ```\n\n 3. Configure the consumer (the AWS SDK S3 client here) to use the agent for requests\n\n    ```js\n    import { S3 } from 'aws-sdk';\n\n    const s3 = new S3({\n        httpOptions: {\n            agent: s3Agent,\n        },\n    });\n    ```\n\n 4. The metrics exposed by the prom-client library will now include the `aws_sdk_http_status` metric.\n\n## Configuration\n\nThe `wrapAgent` takes the agent-to-be-wrapped, the metric, and an additional options object with these fields:\n\n| Option         | Type                      | Default | Description\n|----------------|---------------------------|---------|------------\n| `extraLabels`  | `prom-client.labelValues` | none    | Set of labels that should be used together with the `path` and `status` labels when incrementing the counter value\n| `normalizePath`| `(req: http.ClientRequest) =\u003e string` | Remove query strings and replace values through [url-value-parser](https://github.com/disjunction/url-value-parser) | A function that extracts and normalizes the path from the provided request\n\n## License\n\n```license\nThis software is licensed under the Apache 2 license, quoted below.\n\nCopyright 2020-2020 Collaborne B.V. \u003chttp://github.com/Collaborne/\u003e\n\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not\nuse this file except in compliance with the License. You may obtain a copy of\nthe License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\nWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\nLicense for the specific language governing permissions and limitations under\nthe License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcollaborne%2Fnode-http-prometheus-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcollaborne%2Fnode-http-prometheus-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcollaborne%2Fnode-http-prometheus-agent/lists"}