{"id":15715601,"url":"https://github.com/skye-31/workers-prometheus","last_synced_at":"2025-09-06T15:34:48.266Z","repository":{"id":253476277,"uuid":"843607713","full_name":"Skye-31/workers-prometheus","owner":"Skye-31","description":"A Cloudflare Workers prometheus exporter powered by Durable Objects \u0026 RPC","archived":false,"fork":false,"pushed_at":"2024-08-18T19:57:34.000Z","size":25,"stargazers_count":19,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-06T21:02:20.212Z","etag":null,"topics":["cloudflare","cloudflare-workers","durable-objects","prometheus","prometheus-exporter","workers"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/workers-prometheus","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Skye-31.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-08-16T22:46:00.000Z","updated_at":"2025-04-20T05:51:03.000Z","dependencies_parsed_at":"2024-10-24T12:57:51.946Z","dependency_job_id":"b8888dd7-47eb-481d-8c91-af965753053e","html_url":"https://github.com/Skye-31/workers-prometheus","commit_stats":null,"previous_names":["skye-31/workers-prometheus"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skye-31%2Fworkers-prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skye-31%2Fworkers-prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skye-31%2Fworkers-prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Skye-31%2Fworkers-prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Skye-31","download_url":"https://codeload.github.com/Skye-31/workers-prometheus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252769398,"owners_count":21801376,"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":["cloudflare","cloudflare-workers","durable-objects","prometheus","prometheus-exporter","workers"],"created_at":"2024-10-03T21:42:07.332Z","updated_at":"2025-05-06T21:03:52.835Z","avatar_url":"https://github.com/Skye-31.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloudflare Workers Prometheus Exporter\n\n1. Install\n\n`$ npm i workers-prometheus` / `$ pnpm add workers-prometheus`\n\n2. Set up a prometheus registry\n\n```js\nimport { Registry } from 'workers-prometheus/client';\nimport { getPrometheusExporter } from 'workers-prometheus/server';\nimport type { PrometheusServer } from 'workers-prometheus/server';\n\nexport const PROMETHEUS = getPrometheusExporter();\n```\n\nAdd a Durable object to your wrangler.toml (requires workers paid plan)\n\n```toml\n[[durable_objects.bindings]]\nname = \"PROMETHEUS\"\nclass_name = \"PROMETHEUS\"\n\n[[migrations]]\nnew_classes=[\"PROMETHEUS\"]\ntag = \"v1\"\n```\n\n3. Write your worker!\n\n```js\nexport default {\n\tasync fetch(request, env, ctx): Promise\u003cResponse\u003e {\n\t\tconst url = new URL(request.url);\n\n\t\tconst REGISTRY = new Registry(env.PROMETHEUS, ctx);\n\n\t\tswitch (url.pathname) {\n\t\t\tcase '/metrics':\n\t\t\t\treturn new Response(await REGISTRY.metrics());\n\t\t\tcase '/flush':\n\t\t\t\treturn new Response(await REGISTRY.clear());\n\n\t\t\tdefault:\n\t\t\t\tconst counter = REGISTRY.counter('http_requests', 'Number of HTTP requests received');\n\t\t\t\tcounter.inc({ method: request.method });\n\n\t\t\t\tconst gauge = REGISTRY.gauge('my-gauge', 'an increasing and decreasing gauge');\n\t\t\t\tgauge.inc();\n\n\t\t\t\tconst histogram = REGISTRY.histogram('examplecom_latency', 'Counts latency for getting data from example.com', [50, 100, 250, 500, 1000]);\n\t\t\t\tconst time = Date.now();\n\t\t\t\tconst resp = await fetch('https://example.com');\n\t\t\t\tconst latency = Date.now() - time;\n\t\t\t\thistogram.observe(latency, { status: resp.status });\n\n\t\t\t\treturn new Response('ok');\n\t\t}\n\t},\n} satisfies ExportedHandler\u003c{ PROMETHEUS: DurableObjectNamespace\u003cPrometheusServer\u003e }\u003e;\n```\n\n4. Deploy your worker\n\n```\n$ wrangler deploy\n```\n\n5. Set up a prometheus scraper\n\n```yml\nscrape_configs:\n  - job_name: prometheus\n    static_configs:\n      - targets: ['\u003cworker_name\u003e.\u003caccount\u003e.workers.dev/metrics']\n```\n\nFor a full example, see the `example` directory.\n\nPlanned features:\n\n- Automatically flushing data periodically (important when using histograms)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskye-31%2Fworkers-prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskye-31%2Fworkers-prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskye-31%2Fworkers-prometheus/lists"}