npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fleet-metrics-cron

v1.0.0

Published

Cloudflare Worker cron that aggregates fleet observability metrics from D1 into KV

Readme

fleet-metrics-cron

Cloudflare Worker that aggregates observability metrics for the SuperInstance fleet of 15 Workers. Runs every 5 minutes via Cron Trigger.

What It Does

Every 5 minutes, fleet-metrics-cron:

  1. Queries D1 — Reads the spans and events tables for the last 5-minute window for all 15 fleet workers
  2. Computes metrics — Latency percentiles (p50/p75/p90/p95/p99), error rates, throughput, budget consumption
  3. Detects anomalies — Runs 8 anomaly rules (high error rate, latency spikes, budget drain, cascading failures, etc.)
  4. Writes to KV — Stores results under metrics:* keys with 10-minute TTL
  5. Updates baselines — Recomputes 7-day rolling baselines daily at midnight UTC

KV Key Patterns

| Key | TTL | Content | |---|---|---| | metrics:latency:{worker}:{window} | 10 min | Latency percentiles per worker | | metrics:errors:{worker}:{window} | 10 min | Error counts and rates per worker | | metrics:throughput:{worker}:{window} | 10 min | Request counts per worker | | metrics:budget:{window} | 10 min | Budget consumption rates | | metrics:overview:{window} | 10 min | Fleet-wide dashboard summary | | metrics:anomalies:{window} | 10 min | Active anomaly flags | | metrics:baselines | 24 h | 7-day rolling baselines per worker |

Where {window} is an ISO 8601 timestamp truncated to the 5-minute boundary (e.g., 2026-06-10T03:30:00Z).

Anomaly Rules

| Rule | Condition | Severity | |---|---|---| | A1 | error_rate > 5% | critical | | A2 | p95 > 2× baseline | warning | | A3 | budget drain > 10%/min | critical | | A4 | error rate > 3× previous window | warning | | A5 | Worker silent (no spans, was active before) | warning | | A6 | ≥3 workers degraded simultaneously | critical | | A7 | p99 > 5× baseline | critical | | A8 | >10 timeouts in 5-min window | warning |

Each rule has a cooldown to prevent alert storms.

Prerequisites

  • D1 database named fleet-events with spans and events tables (migrations V006/V007 applied)
  • KV namespace named fleet-orchestrator-kv

Setup

# Install dependencies
npm install

# Create D1 database (if not already created)
npx wrangler d1 create fleet-events
# → copy database_id into wrangler.toml

# Create KV namespace (if not already created)
npx wrangler kv namespace create fleet-orchestrator-kv
# → copy id into wrangler.toml

# Apply migrations (from the main fleet repo)
npx wrangler d1 execute fleet-events --file=migrations/V006__add_trace_columns.sql
npx wrangler d1 execute fleet-events --file=migrations/V007__create_spans_table.sql

Development

# Local dev with cron trigger simulation
npx wrangler dev --test-scheduled
# Then: curl "http://localhost:8787/__scheduled?cron=*/5+*+*+*+*"

# Type check
npm run typecheck

Deploy

npm run deploy

Monitoring

# Live tail logs
npm run tail

Architecture

15 Workers → D1 (spans + events) → fleet-metrics-cron (every 5 min) → KV
                                                                    ↓
                                                            Dashboard API

Workers write spans to D1 as fire-and-forget (.run() without await). This cron reads them back in batches of 5 (D1 connection limit), aggregates, and writes to KV for dashboard consumption.