Repository navigation
feat: expose Prometheus /metrics for the agent itself (#125) - #156
Merged
Merged
Conversation
Operators could not monitor or alert on the agent (#125). GET /metrics serves a dedicated registry (services/metrics.py): incidents by type/source/outcome and their duration, queue depth, tool calls by tool and result, Slack approval decisions, Claude token usage, fix-verification results, HTTP requests by route template and status, and an emergency-stop gauge. Labels never carry incident IDs, orgs, repos or hosts; request-supplied types, sources and unknown tool names collapse to "other" so a crafted webhook cannot create unbounded series. Queue depth and emergency stop are computed at scrape time, and a storage error there never breaks the scrape. METRICS_TOKEN optionally requires a bearer token. Tool calls are counted at both call sites of _execute_tool (agent loop and public execute_tool) rather than inside it, since tests parse that dispatcher's source. Docs: scrape config, metric table and example alert rules in docs/GRAFANA_PROMETHEUS.md; endpoint in docs/API_REFERENCE.md. Fixes #125 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #125.
prometheus-clientwas already a dependency, but nothing exposed metrics, so operators couldn't monitor or alert on the on-call agent itself.GET /metrics(Prometheus text format, dedicated registry inservices/metrics.py):devops_agent_incidents_totaltype,source,outcome(resolved/unresolved/failed)agent.rundevops_agent_incident_duration_seconds(histogram)typedevops_agent_queue_depthstatedevops_agent_tool_calls_totaltool,result(ok/error/blocked/requires_approval/emergency_stop)execute_tool(MCP)devops_agent_approvals_totaldecisiondevops_agent_llm_tokens_totalmodel,kind(incl. cache read/creation)_call_claudedevops_agent_fix_verification_totalstatusverify_fixdevops_agent_http_requests_totalroutetemplate,method,status/metrics)devops_agent_emergency_stopDesign notes
type/sourcevalues and unknown tool names collapse toother, so a crafted webhook can't create unbounded series. HTTP requests are labelled by route template (/orgs/{org_id}/docs), not the raw path.failedonly whenagent.runitself raised. If a later step (audit, escalation) fails, the incident was already counted with its real outcome, so nothing is double-counted._execute_tool, not inside it, becausetests/test_host_mutation_approval.pyparses that dispatcher's source.METRICS_TOKEN(optional) requiresAuthorization: Bearer <token>. Unset leaves/metricsopen, as is usual for internal scraping; this is documented.Type of Change
Testing
tests/test_metrics.py(14 tests):/metricsnot countedother; LLM usage; verification_process_incident_with_org_credscounts resolved, unresolved and failed; publicexecute_toolcountsrequires_approval; approval decisions counted-llclean.mkdocs build --strictplus link check: 0 errors.Docs
docs/GRAFANA_PROMETHEUS.mdhas a new "Monitoring the agent itself" section (scrape config, metric table, and alert rules for a stuck queue, high failure rate, fixes not holding, and emergency stop).docs/API_REFERENCE.mddocumentsGET /metrics..env.exampleaddsMETRICS_TOKEN.🤖 Generated with Claude Code