{% 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

{% for h in [1, 24, 168, 720] %} {{ '1h' if h==1 else ('24h' if h==24 else ('7d' if h==168 else '30d')) }} {% endfor %}
{% 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

{% for f in stats.by_function %} {% else %} {% endfor %}
FunctionCallsBlockedCost
{{ f.function }}{{ f.calls }}{{ f.blocked }}${{ '%.4f'|format(f.cost_usd) }}
no calls

By outcome

{% for outcome, n in stats.by_outcome.items() %} {% else %} {% endfor %}
{{ outcome }}{{ n }}
no data

By domain lens

{% for d in stats.by_domain %} {% else %} {% endfor %}
{{ d.domain }}{{ d.calls }}
no data

By tenant

{% for t in stats.by_tenant %} {% else %} {% endfor %}
TenantCallsBlocked
{{ t.tenant_id }}{{ t.calls }}{{ t.blocked }}
no data

By gate β€” where the chain spends its time

{% for g in stats.by_gate %} {% else %} {% endfor %}
GateCallsAvgTotal
{{ g.gate }}{% if g.gate == 'operation' %} (the call itself){% endif %}{{ g.calls }}{{ '%.1f'|format(g.avg_ms) }} ms{{ '%.0f'|format(g.total_ms) }} ms
no timed calls

By model

{% for m in stats.by_model %} {% else %} {% endfor %}
ModelCallsTokensCost
{{ m.model }}{{ m.calls }}{{ '{:,}'.format(m.total_tokens) }}${{ '%.4f'|format(m.cost_usd) }}
no data
{% endif %} {% endblock %}