Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

fleet-metrics-cron

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fleet-metrics-cron

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

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

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:

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

KV Key Patterns

KeyTTLContent
metrics:latency:{worker}:{window}10 minLatency percentiles per worker
metrics:errors:{worker}:{window}10 minError counts and rates per worker
metrics:throughput:{worker}:{window}10 minRequest counts per worker
metrics:budget:{window}10 minBudget consumption rates
metrics:overview:{window}10 minFleet-wide dashboard summary
metrics:anomalies:{window}10 minActive anomaly flags
metrics:baselines24 h7-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

RuleConditionSeverity
A1error_rate > 5%critical
A2p95 > 2× baselinewarning
A3budget drain > 10%/mincritical
A4error rate > 3× previous windowwarning
A5Worker silent (no spans, was active before)warning
A6≥3 workers degraded simultaneouslycritical
A7p99 > 5× baselinecritical
A8>10 timeouts in 5-min windowwarning

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.

FAQs

Package last updated on 11 Jun 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts