{% extends "base.html" %}
{% block title %}Cortex Metrics β ICDEVβ’{% endblock %}
{% block content %}
CUI // SP-CTI
π Cortex Metrics
Governance, usage & spend over the append-only cortex_audit trail Β· last {{ stats.window_hours }}h Β· β back to Cortex
{% if stats.status == 'unavailable' %}
Metrics unavailable.
The cortex_audit trail could not be read β the table is missing or the query failed.
This is a fault, not an idle system. On a fresh database the table is created on the first governed call.
{% elif stats.status == 'idle' %}
Idle β the audit trail is readable but recorded no governed calls in the last {{ stats.window_hours }}h.
{% if stats.last_call_at %}
Last governed call:
{{ stats.last_call_at }}.
History outside this window is still there β
last 7 days Β·
last 30 days.
{% else %}
No governed calls have ever been recorded.
{% endif %}
{% else %}
{% set s = stats.summary %}
{% if stats.detail and stats.detail.truncated %}
Partial spend detail.
Calls, blocked and the by-function / by-outcome / by-tenant counts below are exact for the full {{ stats.window_hours }}h window.
Cost, tokens, latency, governance timing, redactions, cache hits and the domain / model / gate breakdowns are computed from the most recent
{{ '{:,}'.format(stats.detail.rows_scanned) }} calls only β this window holds more than the {{ '{:,}'.format(stats.detail.limit) }}-row detail cap.
Narrow the window for complete spend figures.
{% endif %}
{% macro card(label, value, hint='') -%}
{{ label }}
{{ value }}
{% if hint %}
{{ hint }}
{% endif %}
{%- endmacro %}
{{ card('Calls', s.calls) }}
{{ card('Blocked', s.blocked, s.block_rate_pct ~ '% block rate') }}
{{ card('Redactions', s.redactions, 'PII/CUI spans masked') }}
{{ card('Cache hits', s.cache_hits) }}
{{ card('Cost (USD)', '$%.4f'|format(s.cost_usd)) }}
{{ card('Avg latency', s.avg_latency_ms ~ ' ms', 'LLM call only') }}
{{ card('Avg governance', s.avg_governance_ms ~ ' ms', s.governance_pct ~ '% of wall time') }}
{{ card('Avg wall time', s.avg_total_ms ~ ' ms', 'gates + operation') }}
{{ card('Tokens', '{:,}'.format(s.total_tokens), '{:,} in / {:,} out'.format(s.input_tokens, s.output_tokens)) }}
{# The governance-cost figures have their own denominator: only calls the
pipeline timed. Saying so is the same honesty as detail.truncated above β
a "0 ms governance" tile must not read as "the chain is free" when the real
answer is "these rows predate the timer". #}
{% if s.timed_calls < s.calls %}
Governance timing covers {{ '{:,}'.format(s.timed_calls) }} of the {{ '{:,}'.format(stats.detail.rows_scanned) }} calls read
{%- if s.timed_calls == 0 %} β none of them recorded a chain timing (rows written before governance timed itself, or cache hits, which never enter the pipeline){% else %}; the rest recorded no chain timing and are excluded from the averages rather than counted as zero{% endif %}.
{% endif %}
By function
| Function | Calls | Blocked | Cost |
{% for f in stats.by_function %}
| {{ f.function }} | {{ f.calls }} | {{ f.blocked }} | ${{ '%.4f'|format(f.cost_usd) }} |
{% else %}
| no calls |
{% endfor %}
By outcome
{% for outcome, n in stats.by_outcome.items() %}
| {{ outcome }} | {{ n }} |
{% else %}
| no data |
{% endfor %}
By domain lens
{% for d in stats.by_domain %}
| {{ d.domain }} | {{ d.calls }} |
{% else %}
| no data |
{% endfor %}
By tenant
| Tenant | Calls | Blocked |
{% for t in stats.by_tenant %}
| {{ t.tenant_id }} | {{ t.calls }} | {{ t.blocked }} |
{% else %}
| no data |
{% endfor %}
By gate β where the chain spends its time
| Gate | Calls | Avg | Total |
{% for g in stats.by_gate %}
| {{ g.gate }}{% if g.gate == 'operation' %} (the call itself){% endif %} | {{ g.calls }} | {{ '%.1f'|format(g.avg_ms) }} ms | {{ '%.0f'|format(g.total_ms) }} ms |
{% else %}
| no timed calls |
{% endfor %}
By model
| Model | Calls | Tokens | Cost |
{% for m in stats.by_model %}
| {{ m.model }} | {{ m.calls }} | {{ '{:,}'.format(m.total_tokens) }} | ${{ '%.4f'|format(m.cost_usd) }} |
{% else %}
| no data |
{% endfor %}
{% endif %}
{% endblock %}