truenas-burnin/app/templates/stats.html
Brandon Walter 2dff58bd52 Stage 7: SSH architecture, SMART attribute monitoring, drive reset, and polish
SSH (app/ssh_client.py — new):
- asyncssh-based client: start_smart_test, poll_smart_progress, abort_smart_test,
  get_smart_attributes, run_badblocks with streaming progress callbacks
- SMART attribute table: monitors attrs 5/10/188/197/198/199 for warn/fail thresholds
- Falls back to REST API / mock simulation when ssh_host is not configured

Burn-in stages updated (burnin.py):
- _stage_smart_test: SSH path polls smartctl -a, stores raw output + parsed attributes
- _stage_surface_validate: SSH path streams badblocks, counts bad blocks vs configurable threshold
- _stage_final_check: SSH path checks smartctl attributes; DB fallback for mock mode
- New DB helpers: _append_stage_log, _update_stage_bad_blocks, _store_smart_attrs,
  _store_smart_raw_output

Database (database.py):
- Migrations: burnin_stages.log_text, burnin_stages.bad_blocks,
  drives.smart_attrs (JSON), smart_tests.raw_output

Settings (config.py + settings_store.py):
- ssh_host, ssh_port, ssh_user, ssh_password, ssh_key — all runtime-editable
- SSH section in Settings UI with Test SSH Connection button

Webhook (notifier.py):
- Added bad_blocks and timestamp fields to payload per SPEC

Drive reset (routes.py + drives_table.html):
- POST /api/v1/drives/{id}/reset — clears SMART state, smart_attrs; audit logged
- Reset button visible on drives with completed test state (no active burn-in)

Log drawer (app.js):
- Burn-In tab: shows raw stage log_text (SSH output) with bad block highlighting
- SMART tab: shows SMART attribute table with warn/fail colouring + raw smartctl output

Polish:
- Version badge (v1.0.0-6d) in header via Jinja2 global
- Parallel burn-in warning when max_parallel_burnins > 8 in Settings
- Stats page: avg duration by drive size + failure breakdown by stage
- settings.html: SSH section with key textarea, parallel warn div

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 08:09:30 -05:00

183 lines
6.3 KiB
HTML

{% extends "layout.html" %}
{% block title %}TrueNAS Burn-In — Stats{% endblock %}
{% block content %}
<div class="page-toolbar">
<h1 class="page-title">Analytics</h1>
<div class="toolbar-right">
<span class="page-subtitle">{{ drives_total }} drives tracked</span>
</div>
</div>
<!-- Overall stat cards -->
<div class="stats-row" style="margin-bottom:24px">
<div class="overview-card">
<span class="ov-value">{{ overall.total or 0 }}</span>
<span class="ov-label">Total Jobs</span>
</div>
<div class="overview-card ov-green">
<span class="ov-value">{{ overall.passed or 0 }}</span>
<span class="ov-label">Passed</span>
</div>
<div class="overview-card ov-red">
<span class="ov-value">{{ overall.failed or 0 }}</span>
<span class="ov-label">Failed</span>
</div>
<div class="overview-card ov-blue">
<span class="ov-value">{{ overall.running or 0 }}</span>
<span class="ov-label">Running</span>
</div>
<div class="overview-card ov-gray">
<span class="ov-value">{{ overall.cancelled or 0 }}</span>
<span class="ov-label">Cancelled</span>
</div>
{% if overall.total and overall.total > 0 %}
<div class="overview-card ov-green">
<span class="ov-value">{{ "%.0f" | format(100 * (overall.passed or 0) / overall.total) }}%</span>
<span class="ov-label">Pass Rate</span>
</div>
{% endif %}
</div>
<div class="stats-grid">
<!-- Failure rate by model -->
<div class="stats-section">
<h2 class="section-title">Results by Drive Model</h2>
{% if by_model %}
<div class="table-wrap" style="max-height:none">
<table>
<thead>
<tr>
<th>Model</th>
<th style="text-align:right">Total</th>
<th style="text-align:right">Passed</th>
<th style="text-align:right">Failed</th>
<th style="text-align:right">Pass Rate</th>
<th style="min-width:120px">Rate Bar</th>
</tr>
</thead>
<tbody>
{% for m in by_model %}
<tr>
<td style="font-weight:500;color:var(--text-strong)">{{ m.model }}</td>
<td class="mono text-muted" style="text-align:right">{{ m.total }}</td>
<td class="mono" style="text-align:right;color:var(--green)">{{ m.passed }}</td>
<td class="mono" style="text-align:right;color:{% if m.failed > 0 %}var(--red){% else %}var(--text-muted){% endif %}">{{ m.failed }}</td>
<td class="mono" style="text-align:right;font-weight:600;color:{% if (m.pass_rate or 0) >= 90 %}var(--green){% elif (m.pass_rate or 0) >= 70 %}var(--yellow){% else %}var(--red){% endif %}">
{{ m.pass_rate or 0 }}%
</td>
<td>
<div class="rate-bar-wrap">
<div class="rate-bar-fill rate-pass" style="width:{{ m.pass_rate or 0 }}%"></div>
<div class="rate-bar-fill rate-fail" style="width:{{ 100 - (m.pass_rate or 0) }}%"></div>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="empty-state" style="border:1px solid var(--border);border-radius:8px;padding:32px">
No completed burn-in jobs yet.
</div>
{% endif %}
</div>
<!-- Activity last 14 days -->
<div class="stats-section">
<h2 class="section-title">Activity — Last 14 Days</h2>
{% if by_day %}
<div class="table-wrap" style="max-height:none">
<table>
<thead>
<tr>
<th>Date</th>
<th style="text-align:right">Total</th>
<th style="text-align:right">Passed</th>
<th style="text-align:right">Failed</th>
</tr>
</thead>
<tbody>
{% for d in by_day %}
<tr>
<td class="mono text-muted">{{ d.day }}</td>
<td class="mono" style="text-align:right;color:var(--text-strong)">{{ d.total }}</td>
<td class="mono" style="text-align:right;color:var(--green)">{{ d.passed }}</td>
<td class="mono" style="text-align:right;color:{% if d.failed > 0 %}var(--red){% else %}var(--text-muted){% endif %}">{{ d.failed }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="empty-state" style="border:1px solid var(--border);border-radius:8px;padding:32px">
No activity in the last 14 days.
</div>
{% endif %}
</div>
</div>
<div class="stats-grid" style="margin-top:24px">
<!-- Average duration by drive size -->
<div class="stats-section">
<h2 class="section-title">Avg. Test Duration by Drive Size</h2>
{% if by_size %}
<div class="table-wrap" style="max-height:none">
<table>
<thead>
<tr>
<th>Size</th>
<th style="text-align:right">Jobs</th>
<th style="text-align:right">Avg Duration</th>
</tr>
</thead>
<tbody>
{% for s in by_size %}
<tr>
<td style="font-weight:500;color:var(--text-strong)">{{ s.size_tb }} TB</td>
<td class="mono text-muted" style="text-align:right">{{ s.total }}</td>
<td class="mono" style="text-align:right;color:var(--text-strong)">{{ s.avg_hours }}h</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="empty-state" style="border:1px solid var(--border);border-radius:8px;padding:32px">No completed jobs yet.</div>
{% endif %}
</div>
<!-- Failure breakdown by stage -->
<div class="stats-section">
<h2 class="section-title">Failures by Stage</h2>
{% if by_failure_stage %}
<div class="table-wrap" style="max-height:none">
<table>
<thead>
<tr>
<th>Stage</th>
<th style="text-align:right">Count</th>
</tr>
</thead>
<tbody>
{% for f in by_failure_stage %}
<tr>
<td style="font-weight:500;color:var(--red)">{{ f.failed_stage | replace('_',' ') | title }}</td>
<td class="mono" style="text-align:right;color:var(--red)">{{ f.count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% else %}
<div class="empty-state" style="border:1px solid var(--border);border-radius:8px;padding:32px">No failures recorded.</div>
{% endif %}
</div>
</div>
{% endblock %}