agentleFS
CloudflareKnown publishercloudflare/cloudflare-prometheus-exporter/.agents/skills/adding-metrics/SKILL.md

adding-metrics

Skill182 starsChanged 9 months agoMITView on GitHub

Add new Prometheus metrics to the Cloudflare exporter. Use when adding metrics, implementing new GraphQL/REST queries, or extending metric coverage. Covers the full workflow from schema discovery through client implementation and README updates.

  • In this repositoryOne other file it gives its agents.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is 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.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Empty filter: Always return [...metrics].filter(m => m.values.length > 0)

    line 46

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Adding Metrics

Guided workflow for adding new Prometheus metrics to the Cloudflare Prometheus Exporter. Derived from patterns in PRs #10, #13, #14, #15, and opencode session 1770403408223-happy-garden.

Decision Tree

What kind of metric are you adding?
|
+-- Uses Cloudflare GraphQL API?
|   |
|   +-- Scoped to a single account (no zones)?
|   |   -> Account-level GraphQL
|   |   -> See workflow.md, Step A
|   |
|   +-- Scoped to zones (needs zoneTag_in)?
|       -> Zone-level GraphQL
|       -> See workflow.md, Step B
|
+-- Uses Cloudflare REST API?
    -> REST API (zone-scoped DO)
    -> See workflow.md, Step C

Quick Reference: Files to Modify

StepFileChange
1src/cloudflare/gql/queries.tsAdd graphql() tagged template (skip for REST)
2src/cloudflare/queries.tsAdd to MetricQueryNameSchema enum + category arrays
3src/cloudflare/client.tsImport query, add switch case, implement handler
4src/durable-objects/MetricExporter.tsOnly if special guardrails needed (e.g. allowlists)
5README.mdAdd metric docs + update architecture diagram counts

Key Conventions

  • Metric names: cloudflare_<scope>_<thing>_<unit> -- _total for counters, _seconds for durations
  • Label keys: snake_case always. Normalize accounts via normalizeAccountName(), zones via findZoneName()
  • Counter vs Gauge: counters for window totals (DO accumulates); gauges for snapshots/rates/ratios
  • Null safety: noUncheckedIndexedAccess is on -- null-coalesce everything: dims?.field ?? ""
  • Empty filter: Always return [...metrics].filter(m => m.values.length > 0)
  • Exhaustive switch: Both dispatch methods use const _exhaustive: never = query -- TS errors if case missing

Reading Order

TaskFiles
Add a metric (full workflow)workflow.md
Copy/paste code templatespatterns.md
Avoid known pitfallsgotchas.md

In This Reference

FilePurpose
workflow.mdStep-by-step checklist per metric category
patterns.mdCode templates for queries, handlers, and MetricDefinitions
gotchas.mdPitfalls from real PRs and code reviews

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.