Prometheus metrics

This page lists every metric kōjō serves, how to scrape them, and example queries and alerts built on them. It is for operators who build dashboards and alerts for a deployment. Traces, logs and the health endpoints are on Observability.

kojo serve serves the Prometheus text format at GET /metrics on a port of its own, server.metrics_listen, without authentication. The dashboard, the API and the webhooks stay on server.listen, so publishing that port does not publish the metrics; the main port answers 404 on /metrics. Each replica reports its own counters: sum over replicas in queries.

server.metrics_listen Meaning
127.0.0.1:9090 (default) Reachable from the same host only. Fits the single-VM install, where Prometheus or an agent runs on the host.
:9090 Every interface. The Helm chart sets it; set it yourself in a container that is scraped from outside.
off No metrics.

It must not share server.listen’s port.

scrape_configs:
  - job_name: kojo
    static_configs:
      - targets: ["kojo:9090"]

The Helm chart serves the metrics port through a ClusterIP Service of its own, <fullname>-metrics, which neither the Ingress nor the HTTP Service carries. It can create a Prometheus Operator ServiceMonitor for it:

Chart value Default Meaning
serviceMonitor.enabled false Create the ServiceMonitor.
serviceMonitor.labels {} Extra labels, such as the one your Prometheus selects ServiceMonitors by.
serviceMonitor.interval 30s Scrape interval.
serviceMonitor.scrapeTimeout 10s Scrape timeout.
serviceMonitor.relabelings [] Relabelings applied before scraping.
serviceMonitor.metricRelabelings [] Metric relabelings applied before ingestion.

The rest of the chart is covered in Kubernetes with Helm.

Factory metrics

These are registered by the engine (internal/core/metrics.go). All counters start at zero when the process starts.

Metric Type Labels Meaning
kojo_requests_total counter surface, kind Requests accepted into the queue.
kojo_requests_rejected_total counter reason Requests refused before queueing.
kojo_sessions_total counter status, surface, trigger Sessions that ended.
kojo_session_duration_seconds histogram status Time from a session’s first start to its end.
kojo_session_cost_usd_total counter repo Model cost of ended sessions, in US dollars.
kojo_critic_verdicts_total counter skill, passed Final goal critic verdict of each delegated skill run.
kojo_skill_attempts histogram skill Attempts a skill run needed.
kojo_model_tokens_total counter tier, model, direction Model tokens.
kojo_model_cost_usd_total counter tier, model Model cost, in US dollars.
kojo_sandbox_startup_seconds histogram driver Time the driver took to create a sandbox.
kojo_pull_requests_opened_total counter draft Pull requests opened.
kojo_pull_requests_merged_total counter none Pull requests merged by the merge policy.
kojo_pull_requests_closed_total counter repo, skill, outcome, human_edited Pull requests kōjō opened that were merged or closed without merging, by anyone.
kojo_lessons_learned_total counter repo, skill Lessons saved to team memory from maintainers’ reviews of kōjō’s pull requests.
kojo_skill_proposals_total counter scope, skill, trigger Proposals kōjō started for its own skills (self-improvement).
kojo_skill_proposal_outcomes_total counter scope, skill, outcome What became of those proposals.
kojo_config_proposals_total counter object, outcome Edits of a repository’s settings kept in .factory/ that became pull requests (Editing a setting that lives in git). object is settings/merge_policy, schedules or move; outcome is opened, updated or refused.
kojo_budget_waits_total counter limit, window Times a session that had not started was put back in the queue for 10 minutes because a budget or limit it counts against was spent.
kojo_budget_stops_total counter limit, window Model calls refused because a budget or limit was spent, which stops the session.

Label values:

Label Values
surface Where the request came from: github, gitlab, forgejo, slack, sentry, datadog, cli, mcp, dashboard, schedule, campaign, eval.
kind, trigger The request kind: mention, issue_opened, pr_opened, pr_updated, check_failed, schedule, manual, chat, skill_test, eval, feedback (a review to learn from), improve (a proposal for one of kōjō’s skills), alert (a production alert from Sentry or Datadog), campaign (one repository’s session of a campaign). On kojo_skill_proposals_total, trigger is schedule (the periodic check) or manual (asked for through the API, the dashboard, MCP or the CLI).
status succeeded, failed or cancelled.
reason The refusal, as written in the request.reject audit entry: a sentence such as repository is not enabled, the author lacks the permission to trigger kōjō, the user lacks the operator role or the ticket maps to no repository, or for a production alert a code such as alert_unmapped or alert_daily_limit (the list is on Sentry, and Datadog’s two more on Datadog).
repo The repository as forge/owner/name.
skill The skill name. On the pull request and lesson counters it is the skill whose change the pull request carries: the last skill of the session that changed files. It is empty for a pull request opened before kōjō recorded it.
outcome merged, or closed for a pull request closed without merging. On kojo_skill_proposal_outcomes_total: ready (measured and left for a person), approved, rejected, did_not_hold_up, refused, nothing_to_propose or failed. A proposal counts under ready, then again under what a person decided.
scope org, or repo:<forge/owner/name>.
human_edited true when someone other than kōjō pushed commits to the pull request while it was open.
passed true or false.
tier The model tier name from models.tiers, for example fast or strong.
model The model that answered.
direction input or output.
driver The sandbox driver: sbx, k8s, docker or fake.
draft true or false.
limit Whose budget was spent: session (budgets.per_session_usd), install (budgets.per_day_usd), team or repo (settings/limits).
window session, day (the last 24 hours) or month (the calendar month, UTC).

Histogram buckets:

Metric Buckets
kojo_session_duration_seconds 12 buckets doubling from 15 seconds to 30720 seconds.
kojo_skill_attempts 1, 2, 3, 4, 5, 10.
kojo_sandbox_startup_seconds 10 buckets doubling from 0.25 seconds to 128 seconds.

Things to know when reading them:

  • kojo_sessions_total, kojo_session_duration_seconds and kojo_session_cost_usd_total are recorded by the worker that ends a session. A session cancelled while it is still queued or waiting is closed in the database without a worker and is not counted.
  • kojo_session_duration_seconds includes the time a session spent waiting for an approval.
  • kojo_requests_total counts every accepted request, including dry runs and eval cases.
  • kojo_requests_rejected_total counts the refusals that are written to the audit log as request.reject. Webhook events kōjō ignores for other reasons (an unhandled event type, a repeated delivery, no automatic skill configured) are not counted, and neither are requests the API refuses.
  • kojo_session_cost_usd_total and kojo_model_cost_usd_total stay at zero for a tier without a configured price. kōjō ships no price table, see Models.
  • kojo_model_tokens_total and kojo_model_cost_usd_total are recorded per model call, as it happens. kojo_session_cost_usd_total is recorded once, when the session ends.
  • kojo_budget_waits_total counts each time a waiting session is looked at again and still waits, so one session that waits an hour counts six times. A session held by a cap on running sessions is passed over by the queue without a worker taking it, and is not counted: GET /api/v1/limits shows how many each cap holds.
  • kojo_pull_requests_closed_total is recorded when the forge reports that a pull request a session opened was merged or closed, which needs the pull request webhook events. A pull request closed, reopened and then merged counts once under each outcome.

Merge rate and human-edit rate

The merge rate of a skill is the share of its decided pull requests that were merged. The human-edit rate is the share of the merged ones a person pushed commits to first: how often the work was not accepted as it came. Both are ratios over kojo_pull_requests_closed_total:

# Merge rate per repository and skill, over 30 days
sum by (repo, skill) (increase(kojo_pull_requests_closed_total{outcome="merged"}[30d]))
  /
sum by (repo, skill) (increase(kojo_pull_requests_closed_total[30d]))

# Human-edit rate per repository and skill, over 30 days
sum by (repo, skill) (increase(kojo_pull_requests_closed_total{outcome="merged", human_edited="true"}[30d]))
  /
sum by (repo, skill) (increase(kojo_pull_requests_closed_total{outcome="merged"}[30d]))

The same two rates, computed from the database instead of the counters, are on the dashboard’s overview and in GET /api/v1/stats (pull_request_outcomes, one row per repository and skill, for the pull requests opened in the last 30 days). A push counts as a human edit whatever it contains, including a merge of the base branch made with the forge’s “update branch” button.

Proxy metrics

Metric Type Labels Meaning
kojo_proxy_requests_total counter decision Requests the egress proxy decided on.
kojo_proxy_policies_resent_total counter replica Sandbox policies kōjō sent a standalone proxy replica again because it had restarted, was new, or had missed them. replica is the replica’s admin address (host:port); the series of a replica that is no longer discovered is removed.

decision is one of:

Value Meaning
allowed The host is on the sandbox’s allowlist.
denied_host The host is not on the allowlist (HTTP 403).
unauthenticated No or wrong proxy credentials (HTTP 407).
blocked_address The host is allowlisted but resolves to a non-public address (HTTP 403).
too_many_connections The sandbox already has sandbox.proxy.max_conns_per_sandbox connections open through the proxy (HTTP 429).

One decision is counted per plain-HTTP request, per request inside an intercepted TLS connection, and per CONNECT that is denied or tunnelled without interception.

Where they are. kojo_proxy_requests_total is on kojo serve’s /metrics when sandbox.proxy.mode is embedded. A standalone kojo proxy (sandbox.proxy.mode: remote) registers no metrics and serves no /metrics endpoint. It logs every refusal at warn level instead (msg="egress refused"), see Logs. kojo_proxy_policies_resent_total is the other way round: it is on kojo serve’s /metrics when sandbox.proxy.mode is remote, counted by kōjō as it sends a replica policies after a restart, or that it missed. Each kōjō replica counts its own.

How the proxy decides is described in kojo-proxy.

Runtime metrics

The registry also holds the standard Go and process collectors of the Prometheus Go client: the go_* metrics (goroutines, memory, garbage collection) and the process_* metrics (CPU, resident memory, open file descriptors, start time).

Example queries and alerts

These use only the metrics listed above. Adjust the windows and thresholds to your traffic.

Queries

Sessions ended per hour, by status:

sum by (status) (increase(kojo_sessions_total[1h]))

Share of sessions that failed over the last day:

sum(increase(kojo_sessions_total{status="failed"}[1d]))
  / sum(increase(kojo_sessions_total[1d]))

Median and 95th percentile session duration:

histogram_quantile(0.5, sum by (le) (rate(kojo_session_duration_seconds_bucket[6h])))
histogram_quantile(0.95, sum by (le) (rate(kojo_session_duration_seconds_bucket[6h])))

Goal critic pass rate per skill over a week:

sum by (skill) (increase(kojo_critic_verdicts_total{passed="true"}[7d]))
  / sum by (skill) (increase(kojo_critic_verdicts_total[7d]))

Mean attempts per skill run:

sum by (skill) (rate(kojo_skill_attempts_sum[1d]))
  / sum by (skill) (rate(kojo_skill_attempts_count[1d]))

Model spend over the last 24 hours, by tier and model:

sum by (tier, model) (increase(kojo_model_cost_usd_total[24h]))

Spend per repository over a week:

sum by (repo) (increase(kojo_session_cost_usd_total[7d]))

Tokens per minute, by direction:

sum by (direction) (rate(kojo_model_tokens_total[5m])) * 60

95th percentile sandbox start-up time per driver:

histogram_quantile(0.95, sum by (le, driver) (rate(kojo_sandbox_startup_seconds_bucket[1h])))

Share of opened pull requests that the merge policy merged:

sum(increase(kojo_pull_requests_merged_total[7d]))
  / sum(increase(kojo_pull_requests_opened_total[7d]))

Egress the proxy refused, by reason:

sum by (decision) (rate(kojo_proxy_requests_total{decision!="allowed"}[5m]))

Alert ideas

Alert Expression Why
Spend above a daily amount sum(increase(kojo_model_cost_usd_total[24h])) > 50 Catches a runaway before the budget does, or where no budget is set. Replace 50 with your amount.
Failure share rising sum(increase(kojo_sessions_total{status="failed"}[1h])) / sum(increase(kojo_sessions_total[1h])) > 0.5 A broken model key, forge token or sandbox driver fails most sessions.
A skill stopped passing sum by (skill) (increase(kojo_critic_verdicts_total{passed="false"}[1d])) / sum by (skill) (increase(kojo_critic_verdicts_total[1d])) > 0.5 A skill or goals change made the critic reject most runs.
Sandboxes slow to start histogram_quantile(0.95, sum by (le) (rate(kojo_sandbox_startup_seconds_bucket[30m]))) > 60 Image pulls or a saturated cluster.
Denied egress sum(increase(kojo_proxy_requests_total{decision="denied_host"}[15m])) > 20 A skill needs a host that is not on its allowlist, or an agent is being steered somewhere it should not go.
Unauthenticated proxy traffic sum(increase(kojo_proxy_requests_total{decision="unauthenticated"}[15m])) > 0 Something other than a sandbox with a valid token is reaching the proxy.
Proxy restarts sum by (replica) (increase(kojo_proxy_policies_resent_total[1h])) > 0 A standalone proxy replica restarted, appeared or missed policies while sandboxes were running. kōjō sent them again; one replica that keeps coming back points at its pod (its memory limit, evictions) or at the network between it and kōjō.
Requests refused sum by (reason) (increase(kojo_requests_rejected_total[1h])) > 10 People without permission are mentioning kōjō, or a repository was never enabled.
No work accepted sum(increase(kojo_requests_total[1d])) == 0 Webhooks stopped arriving. Only useful where daily traffic is expected.
Not ready A probe of /readyz that fails for 2 minutes Postgres is unreachable.

There is no metric for queue depth or for sessions in progress. To see what is queued or running, use kojo sessions list --status queued and kojo sessions list --status running.

Scroll to move. + - zoom, 0 fit, Esc close.100%