{"id":17836489,"url":"https://github.com/haysclark/nexus-plugin-prometheus","last_synced_at":"2026-05-06T22:07:32.958Z","repository":{"id":74966344,"uuid":"295941596","full_name":"haysclark/nexus-plugin-prometheus","owner":"haysclark","description":"A nexus-framework plugin for reporting basic GraphQL metrics through Prometheus (via prom-client)","archived":false,"fork":false,"pushed_at":"2020-09-22T02:58:37.000Z","size":253,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-10T23:09:04.605Z","etag":null,"topics":["express","graphql","metrics","nexus","nexus-framework","prom-client","prometheus","server"],"latest_commit_sha":null,"homepage":"https://github.com/haysclark/nexus-plugin-prometheus","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/haysclark.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2020-09-16T06:20:13.000Z","updated_at":"2021-01-14T11:15:37.000Z","dependencies_parsed_at":"2023-03-08T19:45:22.337Z","dependency_job_id":null,"html_url":"https://github.com/haysclark/nexus-plugin-prometheus","commit_stats":{"total_commits":3,"total_committers":2,"mean_commits":1.5,"dds":"0.33333333333333337","last_synced_commit":"898dcbf7723a120fbe922071741ad70120789e62"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haysclark%2Fnexus-plugin-prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haysclark%2Fnexus-plugin-prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haysclark%2Fnexus-plugin-prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haysclark%2Fnexus-plugin-prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haysclark","download_url":"https://codeload.github.com/haysclark/nexus-plugin-prometheus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246827758,"owners_count":20840464,"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":["express","graphql","metrics","nexus","nexus-framework","prom-client","prometheus","server"],"created_at":"2024-10-27T20:40:17.397Z","updated_at":"2026-05-06T22:07:27.932Z","avatar_url":"https://github.com/haysclark.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nexus-plugin-prometheus\n\n[![Version](https://img.shields.io/npm/v/nexus-plugin-prometheus.svg?style=flat-square)](https://www.npmjs.com/package/nexus-plugin-prometheus?activeTab=versions) [![Downloads](https://img.shields.io/npm/dt/nexus-plugin-prometheus.svg?style=flat-square)](https://www.npmjs.com/package/nexus-plugin-prometheus) [![Last commit](https://img.shields.io/github/last-commit/haysclark/nexus-plugin-prometheus.svg?style=flat-square)](https://github.com/haysclark/nexus-plugin-prometheus/graphs/commit-activity) [![License](https://img.shields.io/github/license/haysclark/nexus-plugin-prometheus.svg?style=flat-square)](https://github.com/haysclark/nexus-plugin-prometheus/blob/master/LICENSE) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/haysclark/nexus-plugin-prometheus#can-i-contribute-code) [![Code of conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](https://github.com/haysclark/nexus-plugin-prometheus/blob/master/CODE_OF_CONDUCT.md)\n\n\u003e A nexus-framework plugin for reporting basic GraphQL metrics through Prometheus (via prom-client)\n\n---\n\nThis [nexus-framework](https://nexusjs.org/) [plugin](https://nexusjs.org/guides/plugins) collects basics _GraphQL_ metrics and reports them to a [Prometheus](https://prometheus.io/) server. The plugin utilizes the [prom-client](https://github.com/siimon/prom-client) library to communicate with Prometheus and thus requires Nexus' instance of [express](https://expressjs.com/) to be provided to the plugin.\n\n\u003e ⚠️ This plugin does **NOT** support _Nexus_ projects utilizing serverless _Next.JS_ implementations!\n\n## Installation\n\nThis module is distributed via [npm](https://www.npmjs.com/) which is bundled with [Node.js](https://nodejs.org).\n\n```bash\nnpm install --save nexus-plugin-prometheus\n```\n\nOR\n\n```bash\nyarn add nexus-plugin-prometheus\n```\n\n## Usage\n\nFind a full example in the [examples/basic-prometheus](https://github.com/haysclark/nexus-plugin-prometheus/blob/master/examples/basic-prometheus) folder, which also includes a basic [Grafana](https://grafana.com/) Dashboard and [docker-compose](https://www.docker.com/) file to fully illustrate the plugin in use.\n\n### Setup\n\nDue to the _middleware_ architecture of Nexus-framework plugins, it is vital that one `use` the _nexus-plugin-prometheus_ **_first_**, so that no requests are culled by another plugin.\n\n```typescript\n// app.ts\n\nimport { use, server } from 'nexus'\nimport { prometheus } from 'nexus-plugin-prometheus'\n\n// Enables the Prometheus reporting plugin\nuse(\n  prometheus({\n    express: server.express, // inject Nexus express instance\n  })\n)\n```\n\nPrometheus will now be able to collect metrics from the servers `/metrics` url.\n\n### Running `collectDefaultMetrics` for collecting server metrics\n\nExecuting _prom-client_'s `collectDefaultMetrics` method can be done by providing the plugin with a custom `configureRegistry` method.\n\n\u003e For more information on configuring _prom-client_, see it's [usage](https://github.com/siimon/prom-client#usage) documentation.\n\n```typescript\n// app.ts\n\nimport { use, server } from 'nexus'\nimport { prometheus } from 'nexus-plugin-prometheus'\nimport { Registry, collectDefaultMetrics } from 'prom-client'\n\n// Define custom configuration of prom-client\nfunction configureRegistry(): Registry[] {\n  const register = new Registry()\n  collectDefaultMetrics({ register })\n  return [register]\n}\n\n// Enables the Prometheus reporting plugin\nuse(\n  prometheus({\n    express: server.express,\n    configureRegistry, // provide custom\n  })\n)\n```\n\n### Adding a **_prefix_** to my metrics\n\nExecuting _prom-client_'s `collectDefaultMetrics` method with any additional configuration, such as a `prefix`, can be done by providing the plugin with a custom `configureRegistry` method.\n\n\u003e For more information on configuring _prom-client_, see it's [usage](https://github.com/siimon/prom-client#usage) documentation.\n\n```typescript\n// app.ts\n\nimport { use, server } from 'nexus'\nimport { prometheus } from 'nexus-plugin-prometheus'\nimport { Registry, collectDefaultMetrics } from 'prom-client'\n\n// Define custom configuration of prom-client\nfunction configureRegistry(): Registry[] {\n  const register = new Registry()\n  const prefix = 'my_application_'\n  collectDefaultMetrics({ register, prefix })\n  return [register]\n}\n\n// Enables the Prometheus reporting plugin\nuse(\n  prometheus({\n    express: server.express,\n    configureRegistry, // provide custom\n  })\n)\n```\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## Related\n\n- [prom-client](https://github.com/siimon/prom-client)\n- [Prometheus](https://prometheus.io/)\n- [Grafana](https://grafana.com/)\n- [Docker](https://www.docker.com/)\n\n## Inspiration\n\n- [dotellie/apollo-metrics](https://github.com/dotellie/apollo-metrics)\n- [simondujardin/graphql-middleware-prometheus](https://github.com/simondujardin/graphql-middleware-prometheus)\n- [Camji55/nexus-plugin-jwt-auth](https://github.com/Camji55/nexus-plugin-jwt-auth)\n\n## Credits\n\nAuthored and maintained by Hays Clark.\n\nTo all [contributors](https://github.com/haysclark/nexus-plugin-prometheus/graphs/contributors) - Thank you!\n\n## License\n\nOpen-source under [MIT License](https://github.com/haysclark/nexus-plugin-prometheus/blob/master/LICENSE).\n\n## FAQ\n\n\u003c!-- START doctoc generated TOC please keep comment here to allow auto update --\u003e\n\u003c!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --\u003e\n\n- [Uh oh, something went wrong!](#uh-oh-something-went-wrong)\n- [I wish something was different…](#i-wish-something-was-different)\n- [Can I contribute code?](#can-i-contribute-code)\n- [My question isn't answered :(](#my-question-isnt-answered-)\n\n\u003c!-- END doctoc generated TOC please keep comment here to allow auto update --\u003e\n\n### Uh oh, something went wrong!\n\nSorry about that. It is recommended that you enable \"debug\" and \"allowExternalErrors\" in your plugin. Additionally, if you are using other Nexus plugins, you may want to do the same for them.\n\n```typescript\n// app.ts\n\nimport { use, server } from 'nexus'\nimport { prometheus } from 'nexus-plugin-prometheus'\n\n// Enables the Prometheus reporting plugin\nuse(\n  prometheus({\n    express: server.express,\n    debug: true,\n    allowExternalErrors: true,\n  })\n)\n```\n\nIf you are still stuck, please submit a bug report using the [GitHub issue tracker](https://github.com/haysclark/nexus-plugin-prometheus/issues).\n\n### I wish something was different…\n\nKeen to hear all ideas! Create an enhancement request using the [GitHub issue tracker](https://github.com/haysclark/nexus-plugin-prometheus/issues).\n\n### Can I contribute code?\n\nYes please! See [DEVELOPING.md](./DEVELOPING.md).\n\n### My question isn't answered :(\n\nAsk away using the [GitHub issue tracker](https://github.com/haysclark/nexus-plugin-prometheus/issues).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaysclark%2Fnexus-plugin-prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaysclark%2Fnexus-plugin-prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaysclark%2Fnexus-plugin-prometheus/lists"}