investigating-metric-anomalies
What it does
This skill finds out why an infrastructure metric is rising, falling or spiking, such as ingestion lag or error rate. It is for engineers responding to an alert or a worrying chart.
When to use it
- βWhen an alert fires on a server metric and you want to know the likely cause.
- βWhen error rate, latency or queue depth has changed and you want to know why.
- βWhen you are handling an incident that starts with a change in a metric.
Skill link
https://github.com/PostHog/posthog/blob/master/products/metrics/skills/investigating-metric-anomalies/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βOur ingestion lag has been rising since this morning. Find out what is causing it.β
5 new skills a week. 1 minute to read.
How it works
It names the metric, measures how big the change is and when it started, then checks logs and traces around that time. It combines the evidence into a probable cause.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Investigating metric anomalies
The job: go from a metric symptom ("ingestion lag is rising") to a probable cause with evidence, fast. The metric tells you what and when; logs and traces tell you why. Follow the loop below β it front-loads the cheap, high-information calls and only fans out when the blast radius is unclear.
The loop
1. Pin down the metric
If you have the exact metric name, skip ahead. Otherwise call metric-names-list with a substring from the symptom (lag, error, latency, queue). The returned metric_type decides the lens: counters (sum) are only meaningful as rate/increase, gauges as avg, histograms as histogram_quantile.
2. Characterize first β one call, three answers
Call characterize-metric-anomaly with the metric name and anomalyFrom (the alert fire time, or when the user says it started looking wrong; subtract some margin if unsure). It compares against the preceding window by default and answers:
- How bad:
direction,change_ratio,anomaly_peakvsbaseline_mean. Ifdirectionisflat, your window or metric is wrong β widen the window, or compare against the same window yesterday viabaselineFrom/baselineTo(daily-pattern metrics often look "anomalous" against the immediately-preceding hours). - When:
onset_timeβ treat this timestamp as the pivot for everything that follows. - Where:
top_moversβ label values whose behavior changed. One mover (a single pod, shard, or endpoint) means a localized culprit; everything moving together means a shared cause (an upstream dependency, a deploy, infra).
3. Sharpen with targeted metric queries
Use query-metrics to test the hypotheses the report raises:
- Drill a mover: re-query with
filterspinning the suspicious label value, grouped by a second key, to localize further (pod β container, endpoint β status code). - Normalize: a rising error count means nothing if traffic doubled β use
clauses+formula(errors / requests) to separate rate changes from volume changes. - Check the neighbors: query the obvious companion metrics over the same window (for lag: throughput and error counters of the same service; for latency: request rate and saturation gauges). Use the same
intervalso the grids align visually.
4. Correlate across signals at the onset
Pivot into logs and traces using the same service and a window bracketing onset_time (a few buckets before, through the peak):
- Logs: use
query-logs(follow its own discover-first workflow) filtered to the implicatedservice.nameand window, severityerrorfirst, thenwarn. Restarts, crash loops, connection errors, and deploy markers right before onset are the classic causes. Widen to other services in the request path if the service's own logs are clean. - Traces: use the APM span tools (
query-apm-spansetc.) for the same service/window β slow or erroring spans show which dependency degraded, and atrace_idfrom an exemplar or log line links a concrete request across all three signals.
5. Conclude with evidence, not vibes
State: the symptom (metric, magnitude, onset), the probable cause (what you found in logs/traces and how its timing aligns with the onset), the blast radius (which services/labels are affected, from the movers and grouped queries), and the confidence level. If the cause is still ambiguous, say which hypothesis the evidence favors and what would disambiguate (e.g. "the lag began draining at 20:12 β consistent with a consumer restart; check who restarted it").
Worked example: "ingestion lag is rising β why?"
metric-names-listwithvalue: "lag"βlogs_rate_limiter_message_lag_seconds(histogram) and friends.characterize-metric-anomalyon it withanomalyFrom= alert time β directionup, change ratio 40x,onset_time20:10, top moverservice_name = logs-ingestion(the other services' lag stayed flat) β so the logs consumer specifically is behind, not the whole pipeline.query-metrics:rateof the consumer's throughput counter over the same window β throughput was zero during the gap and spiked after onset: the consumer wasn't slow, it was down, and the "rising lag" is it draining the backlog.query-logsforservice.name = logs-ingestion(and its neighbors) around 20:00β20:15 β process exit + restart lines at the gap boundaries.- Conclusion: consumer outage 20:01β20:10 (restart visible in logs); lag spike is backlog
FAQ
How does it find when the problem started?
It finds the onset time of the change and uses that time as the starting point for the logs and traces.
What if the metric looks flat?
The time window or metric may be wrong, so the skill widens the window or compares with the same time yesterday.
Does it fix the problem?
No. It explains the probable cause with evidence so you can decide what to fix.
Details
Original description by the author
Investigates server/infrastructure metric anomalies in PostHog Metrics β from "this metric is rising/dropping/spiking" or a fired alert to a probable cause with evidence. Use when asked why a metric looks wrong (ingestion lag rising, error rate spiking, latency degrading, queue depth growing, throughput dropping), when an alert fires on an OTel/Prometheus metric, or for any incident triage that starts from a metric symptom. Composes characterize-metric-anomaly, query-metrics, and metric-names-list with logs (query-logs) and traces (APM span tools) for cross-signal root-cause correlation.
repo: PostHog/posthog
Popularity
- GitHub stars
- 41k
- Ranking position
- #6895
- License
- β
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
depot-ci
41kHelps your agent set up and run Depot CI workflows, a GitHub Actions alternative, including migrating existing workflows and reading run logs.
depot-container-builds
41kHelps your agent build Docker images on Depot's remote builders, including multi-platform images, pushing to registries, and fixing build failures.
depot-github-runners
41kHelps your agent move GitHub Actions jobs to Depot-managed runners, choosing runner sizes and labels, and troubleshooting runner setup issues.
editing-agents-md
41kHelps your agent decide whether a rule belongs in an AGENTS.md or CLAUDE.md file, and write it so it sticks without bloating the file.
Similar skills
openclaw-update
394kHelps your agent update an existing OpenClaw Gateway, choosing the update method that fits how it was installed and keeping your session working.
diagnose-gateway
394kHelps your agent find out why your OpenClaw Gateway is failing by checking settings, channels, and ports without changing anything.
crabbox-apps
394kHelps your agent open and run an app on a temporary cloud machine, then show its view in your chat side panel.