{# Rich runtime diagnostics partial — rendered on /partials/diagnostics every 5s. #} {% set p = snap.process or {} %} {% set rss = p.get('rss_mb') %} {% if rss is none %} {% set rss_color = 'var(--c-fg-muted)' %} {% elif rss < 800 %} {% set rss_color = 'var(--c-ok)' %} {% elif rss < 1200 %} {% set rss_color = 'var(--c-warn)' %} {% else %} {% set rss_color = 'var(--c-err)' %} {% endif %}
{{ rss if rss is not none else '-' }} {{ t('diag.memory_rss_label') }} {% if can_edit(request, 'diagnostics') %} {% endif %} {% set age = p.get('create_age_secs') %} {% if age %}up {{ (age // 3600) }}h {{ ((age % 3600) // 60) }}m{% endif %}
{% set hist = snap.rss_history or [] %} {% if hist|length > 2 %} {% set vals = hist|map(attribute='rss_mb')|list %} {% set vmin = vals|min %} {% set vmax = vals|max %} {% set w = 240 %} {% set h = 36 %} {% set vrange = (vmax - vmin) if (vmax > vmin) else 1 %}
trend {{ hist|length }}m, {{ '%.0f'|format(vmin) }} → {{ '%.0f'|format(vmax) }} MB, Δ {{ '%+.0f'|format(vals[-1] - vals[0]) }}
{% endif %}
{{ t('diag.uss') }}
{{ '%.0f'|format(p.get('uss_mb') or 0) }} MB
{{ t('diag.private') }}
{{ '%.0f'|format(p.get('private_mb') or 0) }} MB
{{ t('diag.virtual') }}
{{ '%.0f'|format(p.get('vms_mb') or 0) }} MB
{{ t('diag.threads') }}
{{ p.get('num_threads', '-') }}
{{ t('diag.handles') }}
{{ p.get('num_handles') or p.get('num_fds', '-') }}
{{ t('diag.cpu') }}
{{ p.get('cpu_percent', '-') }}
{{ t('diag.pid') }}
{{ p.get('pid', '?') }}
{{ t('diag.python') }}
{{ snap.python }}
{% if snap._timing_ms %}
{{ t('diag.snapshot_timing') }}
{% for name, ms in snap._timing_ms|dictsort(by='value', reverse=true) %} {{ name }} {{ ms }}ms {% endfor %}
{% endif %}
{{ t('diag.threads') }} {{ t('diag.threads_total', count=(snap.threads or {}).get('total', 0)) }}
{% for r in (snap.threads or {}).get('by_prefix', []) %}
{{ r.count }}{{ r.name }}
{% else %}
-
{% endfor %}
{{ t('diag.asyncio_tasks') }} {{ t('diag.asyncio_active', count=(snap.asyncio or {}).get('task_count', 0)) }}
{% for r in (snap.asyncio or {}).get('top_coros', []) %}
{{ r.count }}{{ r.coro }}
{% else %}
-
{% endfor %}
{{ t('diag.child_processes') }}
{% for c in snap.children %}
PID={{ c.pid }} {{ c.name }} {% if c.label %} [{{ c.label }}]{% endif %} {% if c.source == 'registered' %} ⚑{% endif %} {{ '%.1f'|format(c.rss_mb) }} MB {% if c.cmd %}{{ c.cmd[:110] }}{% endif %}
{% else %}
{{ t('diag.no_children') }}
{% endfor %}
{{ t('diag.gc') }} {{ t('diag.allocated_blocks', count='{:,}'.format((snap.gc or {}).get('allocated_blocks', 0))) }}
{% set gc_counts = (snap.gc or {}).get('gc_counts') %} {% if gc_counts %}
{{ t('diag.gen_thresholds') }}{{ gc_counts[0] }} / {{ gc_counts[1] }} / {{ gc_counts[2] }}
{% endif %} {% for s in (snap.gc or {}).get('gen_stats', []) %}
{{ t('diag.gen_label', gen=s.gen) }}collections={{ '{:,}'.format(s.collections) }}, collected={{ '{:,}'.format(s.collected) }}, uncollectable={{ s.uncollectable }}
{% endfor %}
{{ t('diag.gc_live_types_note') }}
{{ t('diag.tracemalloc_header') }} {% set tm = snap.tracemalloc or {} %} {{ t('diag.tracemalloc_tracked', tracked=tm.get('tracked_mb', 0), rss=(rss if rss is not none else '?')) }} {% set tmage = tm.get('cache_age_secs') %} {% if tmage is not none %}, {{ t('diag.tracemalloc_cached', age=tmage) }}{% endif %}
{% for r in tm.get('top_lines', []) %}
{{ '{:,.1f}'.format(r.kb) }} KB{{ '{:,}'.format(r.count) }}×{{ r.file }}:{{ r.line }}
{% else %}
{% if tm.get('enabled') %}-{% else %}{{ t('diag.tracemalloc_disabled') }}{% endif %}
{% endfor %}
{{ t('diag.httpx_pools') }}
{% for pool in snap.httpx_pools %}
{{ pool.origin }} {% if pool.state == 'not_initialized' %}{{ t('diag.httpx_not_initialized') }} {% elif pool.error %}{{ pool.error }} {% else %}{{ t('diag.httpx_conns', conns=(pool.connections or 0)) }}, {{ pool.by_state or {} }}, queued={{ pool.requests_in_pool or 0 }}{% endif %}
{% else %}
-
{% endfor %}
{{ t('diag.http_errors') }} {{ t('diag.http_errors_buffer', count=(snap.http_errors or [])|length) }}
{% set errs = snap.http_errors or [] %} {% if errs %}
{% for e in errs %}
{{ e.status }} {{ e.method }} {{ e.path }} {{ e.duration_ms }}ms, {{ e.client }} {% if e.exc_type %}
{{ e.exc_type }}: {{ e.exc_msg }}
{% endif %}
{% endfor %}
{% else %}
{{ t('diag.http_no_errors') }}
{% endif %}
{{ t('diag.gc_runs') }}
{% set glog = snap.gc_log or [] %} {% if glog %}
{% for g in glog|reverse %}
{{ t('diag.gc_collected', collected=g.collected) }}, {{ g.before_mb }}→{{ g.after_mb }} MB ({{ t('diag.gc_freed', freed=g.freed_mb) }}), {{ g.elapsed_ms }}ms
{% endfor %}
{% else %}
{{ t('diag.gc_no_runs') }}
{% endif %}
{% set eb = snap.event_buffer %} {% if eb %}
{{ eb.label }} {% if eb.alarm %}{{ t('diag.at_capacity') }}{% endif %}
{{ eb.value or '-' }}
{% endif %} {% set ps = snap.plugin_setup %} {% if ps and ps.failed %}
{{ t('diag.plugin_setup') }}
{% for name in ps.failed %}
{{ t('diag.plugin_setup.failed') }}{{ name }}
{% endfor %}
{% endif %} {% set tr = snap.topic_rules %} {% if tr %}
{{ t('diag.topic_rules') }} {% if tr.uncovered or tr.skipped %}{{ t('diag.topic_rules.gaps', count=(tr.uncovered|length + tr.skipped|length)) }} {% else %}{{ t('diag.topic_rules.covered') }}{% endif %}
{% for topic in tr.uncovered %}
{{ t('diag.topic_rules.uncovered') }}{{ topic }}
{% endfor %} {% for topic in tr.skipped %}
{{ t('diag.topic_rules.skipped') }}{{ topic }}
{% endfor %} {% if not tr.uncovered and not tr.skipped %}
{{ t('diag.topic_rules.none') }}
{% endif %}
{% endif %} {% set st = snap.streams %} {% if st %}
{{ t('diag.streams') }} {% if not st.enabled %}{{ t('diag.streams.disabled') }} {% elif not st.proc_alive %}{{ t('diag.streams.not_running') }} {% else %}{{ t('diag.streams.running') }}{% endif %}
{% if st.enabled %}
{{ t('diag.streams.backend') }}{{ st.backend }}{% if st.manage %} {{ t('diag.streams.managed') }}{% endif %}
{{ t('diag.streams.broker') }}{{ st.api_url }}
{% if st.proc_alive %}
{{ t('diag.streams.process') }}pid {{ st.proc_pid }}, {{ t('diag.streams.uptime_s', uptime=(st.uptime_s or 0)) }}
{% endif %}
{{ t('diag.streams.viewers') }}{{ st.active_ws or 0 }}
{% if st.last_error %}
{{ t('diag.streams.last_error') }}{{ st.last_error }}
{% endif %} {% if st.log_path %}
{{ t('diag.streams.log') }}{{ st.log_path }}
{% endif %} {% else %}
{{ t('diag.streams.no_config') }}
{% endif %}
{% endif %} {% for plugin_name, data in (snap.plugins or {}).items() %}
{{ t('diag.plugin_header', name=plugin_name) }}
{{ data|tojson(indent=2) }}
{% else %}
{{ t('diag.plugins') }}
{{ t('diag.plugins.none') }}
{% endfor %}