Skip to content

OpenTelemetry export

agentistics exports usage metrics through OpenTelemetry (OTLP/HTTP). It works with Grafana, Datadog, New Relic, Honeycomb and any OTLP-compatible collector.

Set the endpoint before starting the server:

Janela do terminal
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 agentop server

The OpenTelemetry daemon already runs inside agentop server. On a headless machine, run only the daemon:

Janela do terminal
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 agentop watch

To keep the daemon running with the system:

Janela do terminal
agentop autostart watch enable
Variable Default Description
OTEL_EXPORTER_OTLP_ENDPOINT none (export disabled) OTLP collector endpoint
OTEL_EXPORTER_OTLP_HEADERS none extra headers, e.g. Authorization=Bearer token
OTEL_SERVICE_NAME agentistics service name reported in the metrics
CLAUDE_STATS_WATCH_INTERVAL 30 polling interval in seconds (minimum 5)

The daemon watches Claude Code’s data in ~/.claude/, rebuilds the metrics on every change (with a 2-second window to batch changes in a row), re-reads every CLAUDE_STATS_WATCH_INTERVAL seconds so nothing is missed, and sends everything to the endpoint.

All of them use the claude_stats prefix:

Metric Type Unit
claude_stats.messages.total Counter messages
claude_stats.sessions.total Counter sessions
claude_stats.tool_calls.total Counter calls
claude_stats.tokens.input Counter tokens
claude_stats.tokens.output Counter tokens
claude_stats.cost.usd Counter USD (estimated)
claude_stats.git.commits Counter commits
claude_stats.git.lines_added Counter lines
claude_stats.git.lines_removed Counter lines
claude_stats.git.files_modified Counter files
claude_stats.streak Gauge days
claude_stats.longest_session Gauge minutes
claude_stats.active_projects Gauge projects
claude_stats.tokens.by_model.input Counter tokens per model
claude_stats.tokens.by_model.output Counter tokens per model
claude_stats.tool_calls.by_tool Counter calls per tool
otel-config.yaml
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
exporters:
prometheus:
endpoint: "0.0.0.0:8889"
service:
pipelines:
metrics:
receivers: [otlp]
exporters: [prometheus]

In Grafana, add a Prometheus data source pointing at the collector (port 8889) and use the claude_stats.* metrics.

The grafana/ folder in the repository ships a ready local stack, with Docker Compose: the OTel collector on port 4318, Prometheus on 9090 and Grafana on 3000, with the data source and an agentistics panel already configured.