Cloudflare Worker that collects and stores OpenBreweryDB traffic metrics from Cloudflare Analytics GraphQL API to Workers KV under the key transparency_dashboard.
The worker runs on the following schedules:
- Production: Hourly at the top of each hour (
0 * * * *) - Testing: Every 5 minutes (
*/5 * * * *)
Each run collects:
- Last 24 hours of traffic data
- Last 7 days of aggregated traffic data
- Metrics broken down by: API requests, WWW requests, other requests, visits, and bandwidth
- Cloudflare account +
wranglerauthenticated (npx wrangler login) - A Workers KV namespace bound as
OBDB_METRICS - Secrets in the production environment:
CLOUDFLARE_API_TOKENZONE_ID
npm install
npm run typecheck
npm run dev -- --env testingWrangler will not automatically run cron triggers locally. To manually trigger the scheduled handler while running wrangler dev:
curl "http://localhost:8787/cdn-cgi/handler/scheduled"npx wrangler deploy --env productionSet required secrets:
npx wrangler secret put CLOUDFLARE_API_TOKEN --env production
npx wrangler secret put ZONE_ID --env productionThis worker includes an authenticated endpoint for on-demand runs:
- Path:
GET /__scheduled - Header:
x-manual-trigger-token: <MANUAL_TRIGGER_TOKEN>
Set the token secret:
npx wrangler secret put MANUAL_TRIGGER_TOKEN --env productionTrigger a run:
curl -sS -i \
-H "x-manual-trigger-token: <YOUR_TOKEN>" \
https://openbrewerydb-metrics.wandering-leaf-studios.workers.dev/__scheduledWrangler v4 commands default to local mode, so to read data from the Cloudflare-hosted KV namespace you must pass --remote.
Reference: Cloudflare docs (Wrangler v3 -> v4 migration) state that wrangler kv key get now queries locally unless --remote is specified.
Production namespace:
npx wrangler kv key get transparency_dashboard --binding OBDB_METRICS --env production --text --remoteTesting namespace:
npx wrangler kv key get transparency_dashboard --binding OBDB_METRICS --env testing --text --remotePreview namespace (if you explicitly wrote to preview):
npx wrangler kv key get transparency_dashboard --binding OBDB_METRICS --env testing --preview --text --remote