cloudflare-prometheus-exporter
AGENTS.md182 starsChanged 9 months agoMITView on GitHub
Generated: 2026-01-05 Change: p Cloudflare Prometheus exporter: Worker + Durable Objects fetching CF metrics via GraphQL/REST, exposing Prometheus format. Stack: Hono, gql.tada, Zod, urql. TypeScript (strict mode enforced): - noUncheckedIndexedAccess: true - index access returns T | undefined - verbatimModuleSyntax: true - explicit type imports required - Zod for runtime validation at boundaries Formatting (Biome): - Tabs, double quotes - Auto-organize imports DO Patterns: - State loaded in blockConcurrencyWhile constructor - Alarms for refresh scheduling (jitter applied) - Static get()…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repositoryOne other file it gives its agents.
- adding-metricsSkill
The file
We split this AGENTS.md into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 63
Avoid adding new as casts
- Very specific: line 82
Metric types: Only counter and gauge (no histogram/summary)
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
PROJECT KNOWLEDGE BASE
Generated: 2026-01-05 Change: p
OVERVIEW
Cloudflare Prometheus exporter: Worker + Durable Objects fetching CF metrics via GraphQL/REST, exposing Prometheus format. Stack: Hono, gql.tada, Zod, urql.
STRUCTURE
src/
worker.tsx # Entry: Hono app + DO exports
durable-objects/ # 3 DOs: MetricCoordinator → AccountMetricCoordinator → MetricExporter
lib/ # Shared: types, config, prometheus serialization, logging
cloudflare/ # CF API client + GraphQL queries
gql/ # Generated: schema.gql, graphql-env.d.ts (DO NOT EDIT)
components/ # Landing page JSX (Hono JSX, not React)WHERE TO LOOK
| Task | Location | Notes |
| Add metric query | src/cloudflare/queries.ts + src/cloudflare/client.ts | Add to enum, implement in client |
| Modify DO state | src/durable-objects/*.ts | Each DO has typed state, persisted via ctx.storage |
| Config options | src/lib/runtime-config.ts | KV overrides + env defaults, Zod-validated |
| Prometheus output | src/lib/prometheus.ts | serializeToPrometheus() |
| GraphQL types | Run bun run gql:generate | Regenerates src/cloudflare/gql/ |
CODE MAP
| Symbol | Type | Location | Role |
MetricCoordinator | DO | durable-objects/MetricCoordinator.ts | Singleton, owns account list, delegates to AccountMetricCoordinator |
AccountMetricCoordinator | DO | durable-objects/AccountMetricCoordinator.ts | Per-account, manages zone list + MetricExporter DOs |
MetricExporter | DO | durable-objects/MetricExporter.ts | Per-query scope, fetches + caches metrics, handles counter accumulation |
CloudflareMetricsClient | Class | cloudflare/client.ts | GraphQL + REST client, DataLoader batching |
getConfig | Fn | lib/runtime-config.ts | Merges KV overrides with env defaults |
serializeToPrometheus | Fn | lib/prometheus.ts | MetricDefinition[] → text format |
CONVENTIONS
TypeScript (strict mode enforced):
noUncheckedIndexedAccess: true- index access returnsT | undefinedverbatimModuleSyntax: true- explicit type imports required- Zod for runtime validation at boundaries
Formatting (Biome):
- Tabs, double quotes
- Auto-organize imports
DO Patterns:
- State loaded in
blockConcurrencyWhileconstructor - Alarms for refresh scheduling (jitter applied)
- Static
get()factory ensures initialization
ANTI-PATTERNS (THIS PROJECT)
Type assertions exist but constrained:
env as Env & OptionalEnvVarsin config files (widening for optional vars)- Avoid adding new
ascasts
console.error in DOs:
- Some DOs use
console.errorinstead of logger for uninitialized state errors - New code should use
createLogger()
Silent catches:
worker.tsx:98-.catch(() => null)for JSON parse- Acceptable for input validation; avoid for business logic
Generated files - DO NOT EDIT:
src/cloudflare/gql/graphql-env.d.tssrc/cloudflare/gql/schema.gqlworker-configuration.d.ts
UNIQUE STYLES
DO ID format: "scope:id:queryName" (e.g., "account:abc123:http-metrics")
Metric types: Only counter and gauge (no histogram/summary)
Free tier handling: CF_FREE_TIER_ACCOUNTS env var, zones filtered from paid-tier GraphQL queries
Counter accumulation: Cloudflare returns window totals; DOs accumulate for Prometheus monotonic semantics
Hostname metrics: Allowlist-based (HOST_METRICS_ALLOWLIST, max 50). All gauges, fixed 1-minute window for alerting. Avg latencies as primary metrics; P50/P95 as separate metric families (_p50_seconds, _p95_seconds). Ingestion delay controlled by HOST_METRICS_DELAY_SECONDS (default 60s), independent from global SCRAPE_DELAY_SECONDS. Hosts normalized to lowercase. Disabled when allowlist empty or excludeHost=true.
COMMANDS
bun run dev # Local dev (wrangler dev)
bun run deploy # Deploy to CF
bun run check # Biome lint + format check
bun run format # Auto-format
bun run gql:generate # Regenerate GraphQL types
bun run cf-typegen # Regenerate worker-configuration.d.tsNOTES
No tests: Project lacks test infrastructure
Docker: For local Prometheus scraping only, not production deployment
Rate limiting: CF_API_RATE_LIMITER binding (200 req/10s) - shared across all DOs in worker. Rough budget: ~160 req/60s per 50-zone account (incl REST); ~7 such accounts can saturate.
Dual config: wrangler.jsonc vars + optional env vars + KV runtime overrides
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

