GNMON-001 M3-Final: Ressourcen-Seite mit integrierten Braille-Charts
Betreiberlayout final: Overlay-Kacheln (CPU/RAM/Disk mit Chart hinter den Controls, Fade-Maske links, dichter Text-Halo) plus GPU-Kacheln mit kompakter Werteliste (max-content-Grid), Trennlinie und bündigem GPU-Util-Chart (AutoRows via Hoehenmessung, Y-Achse 0/25/50/75/100%, rechtsbuendig vor der Diagrammflaeche). ResizeObserver haelt Breite und Zeilenzahl beim Fenster-Resize aktuell (JS-Interop, dispose-safe). Erklaerungs-/Dev-Texte entfernt, Experimentseite RessourcenNeu geloescht, Layout-Metadaten aus der Statuszeile gestrichen. Komponente: ShowYLabels, YUnit, AutoRows, GridStyle(dots25), ResizeObserver-Support. Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
@* btop-style braille chart: 2x4 dot cells per character, vertical color
|
||||
gradient (green -> yellow -> red), one span per text row (cheap DOM).
|
||||
The dot grid is interpolated to the measured container width so the
|
||||
chart always spans the full panel. *@
|
||||
The dot grid is interpolated to the measured container width; a
|
||||
ResizeObserver keeps width and (optionally) row count in sync with the
|
||||
live layout. Optional Y-axis labels reserve space on the left. *@
|
||||
|
||||
@inject IJSRuntime JS
|
||||
@implements IAsyncDisposable
|
||||
|
||||
<div class="braille-chart @($"braille-grid-{GridStyle}")" @ref="_container" style="font-size: @(RowPx)px; line-height: @(RowPx)px">
|
||||
<div class="braille-chart @GridClass @YLabelClass" @ref="_container"
|
||||
style="font-size: @(RowPx)px; line-height: @(RowPx)px">
|
||||
@if (ShowYLabels)
|
||||
{
|
||||
<div class="braille-y-labels" aria-hidden="true">
|
||||
@foreach (var fraction in YLabelFractions)
|
||||
{
|
||||
<span style="bottom: @(fraction * 100)%; transform: @(fraction == 0 ? "translateY(-100%)" : "translateY(100%)")">@AxisLabel(fraction)</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@for (var r = 0; r < _rowStrings.Count; r++)
|
||||
{
|
||||
<span @ref="_rowSpans" style="color: @(_rowColors[r])">@_rowStrings[r]</span>
|
||||
@@ -14,6 +26,10 @@
|
||||
|
||||
@code
|
||||
{
|
||||
private const int YLabelWidthPx = 36;
|
||||
|
||||
private static readonly double[] YLabelFractions = [0, 0.25, 0.5, 0.75, 1.0];
|
||||
|
||||
/// <summary>Sample values in display order (oldest first).</summary>
|
||||
[Parameter]
|
||||
public IReadOnlyList<double>? Values { get; set; }
|
||||
@@ -22,7 +38,7 @@
|
||||
[Parameter]
|
||||
public int Rows { get; set; } = 22;
|
||||
|
||||
/// <summary>Total pixel height of the chart.</summary>
|
||||
/// <summary>Total pixel height (fallback before measurement).</summary>
|
||||
[Parameter]
|
||||
public int HeightPx { get; set; } = 220;
|
||||
|
||||
@@ -33,13 +49,27 @@
|
||||
[Parameter]
|
||||
public double? Max { get; set; }
|
||||
|
||||
/// <summary>Background grid style: lines (default), dots or none.</summary>
|
||||
/// <summary>Background grid style: lines (default), dots, dots25 or none.</summary>
|
||||
[Parameter]
|
||||
public string GridStyle { get; set; } = "lines";
|
||||
|
||||
/// <summary>Fallback dot columns when the container width is unknown
|
||||
/// (prerendering); replaced by the measured width after the first
|
||||
/// interactive render.</summary>
|
||||
/// <summary>Very small Y-axis labels at 25/50/75/100 % of the scale.</summary>
|
||||
[Parameter]
|
||||
public bool ShowYLabels { get; set; }
|
||||
|
||||
/// <summary>Unit suffix for the Y-axis labels (e.g. "%").</summary>
|
||||
[Parameter]
|
||||
public string YUnit { get; set; } = "%";
|
||||
|
||||
/// <summary>
|
||||
/// When true, the row count adapts to the measured container height
|
||||
/// (chart fills the available space exactly, e.g. between panel
|
||||
/// separators).
|
||||
/// </summary>
|
||||
[Parameter]
|
||||
public bool AutoRows { get; set; }
|
||||
|
||||
/// <summary>Fallback dot columns before the first measurement.</summary>
|
||||
[Parameter]
|
||||
public int WidthDots { get; set; } = 160;
|
||||
|
||||
@@ -48,18 +78,28 @@
|
||||
private List<string> _rowStrings = [];
|
||||
private List<string> _rowColors = [];
|
||||
private int _charCols = 40;
|
||||
private bool _widthMeasured;
|
||||
private int _rowsEff;
|
||||
private double _axisMax = 1;
|
||||
private double _advance;
|
||||
private bool _measured;
|
||||
private DotNetObjectReference<AsciiBrailleChart>? _resizeRef;
|
||||
|
||||
private string GridClass => $"braille-grid-{GridStyle}";
|
||||
|
||||
private string YLabelClass => ShowYLabels ? "with-y-labels" : "";
|
||||
|
||||
private int RowPx => Math.Max(6, HeightPx / Rows);
|
||||
|
||||
private string AxisLabel(double fraction) => $"{_axisMax * fraction:F0}{YUnit}";
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
// Only fall back before the first measurement; later data refreshes
|
||||
// must keep the measured width (the reset shrank the chart back to
|
||||
// half width every 10-second update).
|
||||
if (!_widthMeasured)
|
||||
// Fallback geometry only until the first measurement; later data
|
||||
// refreshes must keep measured values (resets shrank the chart).
|
||||
if (!_measured)
|
||||
{
|
||||
_charCols = Math.Max(10, WidthDots / 2);
|
||||
_rowsEff = Rows;
|
||||
}
|
||||
BuildRows();
|
||||
}
|
||||
@@ -72,37 +112,61 @@
|
||||
}
|
||||
try
|
||||
{
|
||||
// Measure the real container width AND the real per-glyph
|
||||
// Measure the real container width and the real per-glyph
|
||||
// advance (font fallbacks can render braille wider than the
|
||||
// 0.6em monospace default; fixed ratios under-filled panels).
|
||||
var width = await JS.InvokeAsync<int>("gnmon.clientWidth", _container);
|
||||
var advance = await JS.InvokeAsync<double>("gnmon.charAdvance", _rowSpans);
|
||||
if (width > 0 && advance > 0)
|
||||
_advance = await JS.InvokeAsync<double>("gnmon.charAdvance", _rowSpans);
|
||||
if (width > 0 && _advance > 0)
|
||||
{
|
||||
_charCols = Math.Max(10, (int)(width / advance));
|
||||
_widthMeasured = true;
|
||||
BuildRows();
|
||||
StateHasChanged();
|
||||
ApplyGeometry(width, await JS.InvokeAsync<int>("gnmon.clientHeight", _container));
|
||||
_measured = true;
|
||||
|
||||
// Keep the chart in sync when the window (and thus the
|
||||
// panel) is resized.
|
||||
_resizeRef = DotNetObjectReference.Create(this);
|
||||
await JS.InvokeVoidAsync("gnmon.observeSize", _container, _resizeRef);
|
||||
}
|
||||
}
|
||||
catch (JSDisconnectedException)
|
||||
{
|
||||
// Circuit already gone; next render retries.
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public async Task OnResized(int width, int height)
|
||||
{
|
||||
if (!_measured || _advance <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ApplyGeometry(width, height);
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
private void ApplyGeometry(int width, int height)
|
||||
{
|
||||
var usable = width - (ShowYLabels ? YLabelWidthPx : 0);
|
||||
_charCols = Math.Max(10, (int)(usable / _advance));
|
||||
if (AutoRows && height > 0)
|
||||
{
|
||||
_rowsEff = Math.Max(4, height / RowPx);
|
||||
}
|
||||
BuildRows();
|
||||
}
|
||||
|
||||
private void BuildRows()
|
||||
{
|
||||
_rowStrings = [];
|
||||
_rowColors = [];
|
||||
|
||||
var dotsHigh = Rows * 4;
|
||||
var dotsHigh = _rowsEff * 4;
|
||||
var dotCols = _charCols * 2;
|
||||
|
||||
// Interpolate samples onto the dot grid (btop-style full-width).
|
||||
// Interpolate samples onto the dot grid (full-width, btop-style).
|
||||
var grid = new double[dotCols];
|
||||
if (Values is not { Count: > 1 })
|
||||
{
|
||||
@@ -130,12 +194,13 @@
|
||||
{
|
||||
max = Math.Max(grid.DefaultIfEmpty(1).Max(), 1e-9);
|
||||
}
|
||||
_axisMax = max.Value;
|
||||
|
||||
for (var visualRow = 0; visualRow < Rows; visualRow++)
|
||||
for (var visualRow = 0; visualRow < _rowsEff; visualRow++)
|
||||
{
|
||||
_rowColors.Add(GradientColor(visualRow));
|
||||
var row = new char[_charCols];
|
||||
var charRowFromBottom = Rows - 1 - visualRow;
|
||||
var charRowFromBottom = _rowsEff - 1 - visualRow;
|
||||
|
||||
for (var cx = 0; cx < _charCols; cx++)
|
||||
{
|
||||
@@ -175,7 +240,7 @@
|
||||
/// <summary>Green (bottom) -> yellow -> red (top), Catppuccin tones.</summary>
|
||||
private string GradientColor(int visualRow)
|
||||
{
|
||||
var t = Rows <= 1 ? 1 : (Rows - visualRow) / (double)(Rows - 1);
|
||||
var t = _rowsEff <= 1 ? 1 : (_rowsEff - visualRow) / (double)(_rowsEff - 1);
|
||||
return t <= 0.5
|
||||
? Lerp(0xa6, 0xe3, 0xa1, 0xf9, 0xe2, 0xaf, t / 0.5)
|
||||
: Lerp(0xf9, 0xe2, 0xaf, 0xf3, 0x8b, 0xa8, (t - 0.5) / 0.5);
|
||||
@@ -188,4 +253,22 @@
|
||||
var b = (int)Math.Round(b1 + (b2 - b1) * t);
|
||||
return $"rgb({r},{g},{b})";
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
_resizeRef?.Dispose();
|
||||
try
|
||||
{
|
||||
if (_container.Id is not null)
|
||||
{
|
||||
await JS.InvokeVoidAsync("gnmon.unobserveSize", _container);
|
||||
}
|
||||
}
|
||||
catch (JSDisconnectedException)
|
||||
{
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
<footer class="statusline">
|
||||
<span class="status-ok"><span class="ascii-spin-css ascii-spin-green" aria-hidden="true"></span> LIVE</span>
|
||||
Quelle: VictoriaMetrics · Loki · Alertmanager — M3.3 GPU-Detail
|
||||
Quelle: VictoriaMetrics · Loki · Alertmanager
|
||||
<span class="cursor">▮</span>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
@@ -7,28 +7,6 @@
|
||||
<PageTitle>Ressourcen - Ghostnet.AI Monitoring</PageTitle>
|
||||
|
||||
<h1>Ressourcen</h1>
|
||||
<p class="hint">Host-Übersicht — Live-Werte aus VictoriaMetrics (2-s-Takt).</p>
|
||||
|
||||
<div class="tile-grid">
|
||||
<div class="tile">
|
||||
<span class="tile-label">CPU</span>
|
||||
<span class="tile-value">@Pct(_cpu)</span>
|
||||
<AsciiBar Value="_cpu" />
|
||||
<span class="tile-sub">Auslastung gesamt (10-s-Rate, gleitend)</span>
|
||||
</div>
|
||||
<div class="tile">
|
||||
<span class="tile-label">Arbeitsspeicher</span>
|
||||
<span class="tile-value">@Pct(_ramPct)</span>
|
||||
<AsciiBar Value="_ramPct" />
|
||||
<span class="tile-sub">@GB(_ramUsedBytes) von @GB(_ramTotalBytes) belegt</span>
|
||||
</div>
|
||||
<div class="tile">
|
||||
<span class="tile-label">Dateisystem (Root)</span>
|
||||
<span class="tile-value">@Pct(_diskPct)</span>
|
||||
<AsciiBar Value="_diskPct" />
|
||||
<span class="tile-sub">@GB(_diskUsedBytes) von @GB(_diskTotalBytes) belegt</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (_error is not null)
|
||||
{
|
||||
@@ -36,42 +14,122 @@
|
||||
}
|
||||
else if (!_loaded)
|
||||
{
|
||||
<div class="note"><Spinner Style="dots" Color="mauve" IntervalMs="90" /> Lade VictoriaMetrics-Daten …</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="note note-accent">Datenquelle aktiv: node_exporter → VictoriaMetrics (Scrape 10 s).</div>
|
||||
<div class="note"><Spinner Style="dots" Color="mauve" IntervalMs="90" /> Lade Daten …</div>
|
||||
}
|
||||
|
||||
<h2 class="section-title">Verläufe · CPU 1 h</h2>
|
||||
|
||||
@if (_cpuHistory.Count > 0)
|
||||
{
|
||||
<div class="tile-grid">
|
||||
<div class="panel">
|
||||
<div class="panel-header">CPU-Auslastung (auto-skaliert auf Fenstermaximum)</div>
|
||||
<ErrorBoundary>
|
||||
<AsciiBrailleChart Values="_cpuHistoryValues" HeightPx="220" />
|
||||
</ErrorBoundary>
|
||||
<div class="panel-footer-line">
|
||||
min @F0(_cpuHistoryMin) % · avg @F0(_cpuHistoryAvg) % · max @F0(_cpuHistoryMax) %
|
||||
· 60 min, 30-s-Schritt · Aktualisierung alle 10 s
|
||||
</div>
|
||||
<div class="tile-grid">
|
||||
<div class="tile tile-overlay">
|
||||
<div class="tile-copy">
|
||||
<span class="tile-label">CPU</span>
|
||||
<span class="tile-value">@Pct(_cpu)</span>
|
||||
<AsciiBar Value="_cpu" />
|
||||
<span class="tile-sub">Auslastung gesamt</span>
|
||||
</div>
|
||||
<div class="tile-chart">
|
||||
@if (_cpuHistory.Count > 0)
|
||||
{
|
||||
<AsciiBrailleChart Values="_cpuHistory" Max="100" GridStyle="none" HeightPx="118" Rows="10" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
<div class="tile tile-overlay">
|
||||
<div class="tile-copy">
|
||||
<span class="tile-label">Arbeitsspeicher</span>
|
||||
<span class="tile-value">@Pct(_ramPct)</span>
|
||||
<AsciiBar Value="_ramPct" />
|
||||
<span class="tile-sub">@GB(_ramUsedBytes) von @GB(_ramTotalBytes) belegt</span>
|
||||
</div>
|
||||
<div class="tile-chart">
|
||||
@if (_ramHistory.Count > 0)
|
||||
{
|
||||
<AsciiBrailleChart Values="_ramHistory" Max="100" GridStyle="none" HeightPx="118" Rows="10" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="tile tile-overlay">
|
||||
<div class="tile-copy">
|
||||
<span class="tile-label">Dateisystem (Root)</span>
|
||||
<span class="tile-value">@Pct(_diskPct)</span>
|
||||
<AsciiBar Value="_diskPct" />
|
||||
<span class="tile-sub">@GB(_diskUsedBytes) von @GB(_diskTotalBytes) belegt</span>
|
||||
</div>
|
||||
<div class="tile-chart">
|
||||
@if (_diskHistory.Count > 0)
|
||||
{
|
||||
<AsciiBrailleChart Values="_diskHistory" Max="100" GridStyle="none" HeightPx="118" Rows="10" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2 class="section-title">GPUs</h2>
|
||||
|
||||
@if (_cards.Count == 0 && _loaded)
|
||||
{
|
||||
<div class="note"><Spinner Style="dots" Color="mauve" IntervalMs="90" /> Sammle Verlaufsdaten …</div>
|
||||
<div class="note">Keine AMD-GPUs sichtbar.</div>
|
||||
}
|
||||
|
||||
<div class="tile-grid">
|
||||
@foreach (var card in _cards)
|
||||
{
|
||||
<div class="panel">
|
||||
<div class="panel-header">GPU @card.Id · @card.Model</div>
|
||||
<div class="gpu-split">
|
||||
<div class="gpu-values">
|
||||
<span class="tile-label">Auslastung</span><span class="val">@Val(card.Util, "%")</span>
|
||||
<span class="tile-label">VRAM</span><span class="val">@Val(card.VramUsed, "GB") / @Val(card.VramTotal, "GB")</span>
|
||||
<span class="tile-label">Edge / Junction</span><span class="val">@Temp(card.Edge) / @Temp(card.Junction)</span>
|
||||
<span class="tile-label">Leistung</span><span class="val">@Val(card.Power, " W")</span>
|
||||
<div class="bar-block gpu-values-wide">
|
||||
<span class="tile-label">Util</span>
|
||||
<AsciiBar Value="card.Util" />
|
||||
</div>
|
||||
<div class="bar-block gpu-values-wide">
|
||||
<span class="tile-label">VRAM</span>
|
||||
<AsciiBar Value="card.VramPct" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="gpu-chart">
|
||||
@if (card.UtilHistory.Count > 0)
|
||||
{
|
||||
<AsciiBrailleChart Values="card.UtilHistory" Max="100" GridStyle="none"
|
||||
AutoRows="true" ShowYLabels="true" HeightPx="176" Rows="16" />
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-footer-line">
|
||||
@if (card.FanRpm is > 0)
|
||||
{
|
||||
<Spinner Style="line" RatePerMinute="card.FanRpm" Color="teal" />
|
||||
}
|
||||
Lüfter: @Val(card.FanRpm, " RPM") (PWM @Val(card.FanPwm, " %"))
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@code
|
||||
{
|
||||
// Short window for a near-instant counter rate; display smoothing
|
||||
// happens client-side with an EMA (no window lag).
|
||||
private sealed class GpuCard
|
||||
{
|
||||
public required string Id { get; init; }
|
||||
public required string Model { get; init; }
|
||||
public double? Util;
|
||||
public double? VramUsed;
|
||||
public double? VramTotal;
|
||||
public double? VramPct;
|
||||
public double? Edge;
|
||||
public double? Junction;
|
||||
public double? Power;
|
||||
public double? FanRpm;
|
||||
public double? FanPwm;
|
||||
public List<double> UtilHistory = [];
|
||||
}
|
||||
|
||||
private const string CpuQuery =
|
||||
"(1 - avg(rate(node_cpu_seconds_total{mode=\"idle\"}[10s]))) * 100";
|
||||
private const double CpuEmaAlpha = 0.65;
|
||||
private const string RamPctQuery =
|
||||
"100 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100";
|
||||
private const string RamUsedQuery =
|
||||
"node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes";
|
||||
private const string RamTotalQuery = "node_memory_MemTotal_bytes";
|
||||
@@ -80,12 +138,12 @@ else
|
||||
private const string DiskTotalQuery = "node_filesystem_size_bytes{mountpoint=\"/\"}";
|
||||
private const string DiskPctQuery =
|
||||
"100 - (node_filesystem_avail_bytes{mountpoint=\"/\"} / node_filesystem_size_bytes{mountpoint=\"/\"}) * 100";
|
||||
private const string RamPctQuery =
|
||||
"100 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100";
|
||||
private const double CpuEmaAlpha = 0.65;
|
||||
|
||||
private CancellationTokenSource? _cts;
|
||||
private bool _loaded;
|
||||
private string? _error;
|
||||
private int _tick;
|
||||
|
||||
private double? _cpu;
|
||||
private double? _ramPct;
|
||||
@@ -95,13 +153,11 @@ else
|
||||
private double? _diskUsedBytes;
|
||||
private double? _diskTotalBytes;
|
||||
|
||||
private List<VictoriaMetricsClient.RangePoint> _cpuHistory = [];
|
||||
private double _cpuHistoryMin;
|
||||
private double _cpuHistoryAvg;
|
||||
private double _cpuHistoryMax;
|
||||
private int _tick;
|
||||
private List<double> _cpuHistory = [];
|
||||
private List<double> _ramHistory = [];
|
||||
private List<double> _diskHistory = [];
|
||||
|
||||
private IReadOnlyList<double> _cpuHistoryValues = [];
|
||||
private List<GpuCard> _cards = [];
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@@ -129,7 +185,7 @@ else
|
||||
{
|
||||
// Never let a data error kill the circuit: surface it.
|
||||
_error = $"{ex.GetType().Name}: {ex.Message}";
|
||||
Console.Error.WriteLine($"[Home] {ex}");
|
||||
Console.Error.WriteLine($"[Ressourcen] {ex}");
|
||||
}
|
||||
await InvokeAsync(StateHasChanged);
|
||||
if (!await timer.WaitForNextTickAsync(ct))
|
||||
@@ -140,68 +196,133 @@ else
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Circuit disposed; nothing to do.
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// Renderer already gone (e.g. tab closed mid-update).
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync(CancellationToken ct)
|
||||
{
|
||||
var values = await Vm.QueryAllAsync(
|
||||
[
|
||||
CpuQuery,
|
||||
RamUsedQuery,
|
||||
RamTotalQuery,
|
||||
RamPctQuery,
|
||||
DiskUsedQuery,
|
||||
DiskTotalQuery,
|
||||
DiskPctQuery,
|
||||
], ct);
|
||||
|
||||
_cpu = values[0] is { } rawCpu
|
||||
? _loaded ? CpuEmaAlpha * rawCpu + (1 - CpuEmaAlpha) * (_cpu ?? rawCpu) : rawCpu
|
||||
: null;
|
||||
_ramUsedBytes = values[1];
|
||||
_ramTotalBytes = values[2];
|
||||
_ramPct = values[3];
|
||||
_diskUsedBytes = values[4];
|
||||
_diskTotalBytes = values[5];
|
||||
_diskPct = values[6];
|
||||
|
||||
var up = await Vm.QuerySeriesAsync("gn_gpu_up", ct);
|
||||
if (up.Count == 0)
|
||||
{
|
||||
_cards = [];
|
||||
_error = null;
|
||||
_loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var utilTask = Vm.QuerySeriesAsync("gn_gpu_utilization_percent", ct);
|
||||
var vramUsedTask = Vm.QuerySeriesAsync("gn_gpu_vram_used_bytes", ct);
|
||||
var vramTotalTask = Vm.QuerySeriesAsync("gn_gpu_vram_total_bytes", ct);
|
||||
var edgeTask = Vm.QuerySeriesAsync("gn_gpu_edge_temp_celsius", ct);
|
||||
var junctionTask = Vm.QuerySeriesAsync("gn_gpu_junction_temp_celsius", ct);
|
||||
var powerTask = Vm.QuerySeriesAsync("gn_gpu_power_watts", ct);
|
||||
var fanTask = Vm.QuerySeriesAsync("gn_gpu_fan_rpm", ct);
|
||||
var pwmTask = Vm.QuerySeriesAsync("gn_gpu_fan_pwm_percent", ct);
|
||||
await Task.WhenAll(utilTask, vramUsedTask, vramTotalTask, edgeTask,
|
||||
junctionTask, powerTask, fanTask, pwmTask);
|
||||
|
||||
var oldCards = _cards.ToDictionary(c => c.Id);
|
||||
_cards = up
|
||||
.OrderBy(s => s.Labels.TryGetValue("card", out var id) ? id : "")
|
||||
.Select(s =>
|
||||
{
|
||||
var id = s.Labels.GetValueOrDefault("card", "?");
|
||||
return new GpuCard
|
||||
{
|
||||
Id = id,
|
||||
Model = s.Labels.GetValueOrDefault("gpu", "unknown"),
|
||||
UtilHistory = oldCards.TryGetValue(id, out var old) ? old.UtilHistory : [],
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
|
||||
foreach (var card in _cards)
|
||||
{
|
||||
card.Util = Lookup(utilTask.Result, card.Id);
|
||||
card.VramUsed = Lookup(vramUsedTask.Result, card.Id);
|
||||
card.VramTotal = Lookup(vramTotalTask.Result, card.Id);
|
||||
card.VramPct = card.VramUsed is not null && card.VramTotal > 0
|
||||
? card.VramUsed / card.VramTotal * 100.0
|
||||
: null;
|
||||
card.Edge = Lookup(edgeTask.Result, card.Id);
|
||||
card.Junction = Lookup(junctionTask.Result, card.Id);
|
||||
card.Power = Lookup(powerTask.Result, card.Id);
|
||||
card.FanRpm = Lookup(fanTask.Result, card.Id);
|
||||
card.FanPwm = Lookup(pwmTask.Result, card.Id);
|
||||
}
|
||||
|
||||
_error = null;
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
private async Task LoadHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
var end = DateTimeOffset.Now;
|
||||
var start = end.AddMinutes(-60);
|
||||
_cpuHistory = [.. await Vm.QueryRangeAsync(CpuQuery, start, end, TimeSpan.FromSeconds(30), ct)];
|
||||
_cpuHistoryValues = [.. _cpuHistory.Select(p => p.Value)];
|
||||
if (_cpuHistory.Count > 0)
|
||||
var step = TimeSpan.FromSeconds(30);
|
||||
|
||||
_cpuHistory = [.. (await Vm.QueryRangeAsync(CpuQuery, start, end, step, ct)).Select(p => p.Value)];
|
||||
_ramHistory = [.. (await Vm.QueryRangeAsync(RamPctQuery, start, end, step, ct)).Select(p => p.Value)];
|
||||
_diskHistory = [.. (await Vm.QueryRangeAsync(DiskPctQuery, start, end, step, ct)).Select(p => p.Value)];
|
||||
|
||||
var gpuHistory = await Vm.QueryRangeSeriesAsync(
|
||||
"gn_gpu_utilization_percent", start, end, step, ct);
|
||||
foreach (var card in _cards)
|
||||
{
|
||||
_cpuHistoryMin = _cpuHistoryValues.Min();
|
||||
_cpuHistoryMax = _cpuHistoryValues.Max();
|
||||
_cpuHistoryAvg = _cpuHistoryValues.Average();
|
||||
card.UtilHistory = [.. gpuHistory
|
||||
.Where(s => s.Labels.GetValueOrDefault("card") == card.Id)
|
||||
.SelectMany(s => s.Points)
|
||||
.OrderBy(p => p.Timestamp)
|
||||
.Select(p => p.Value)];
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var values = await Vm.QueryAllAsync(
|
||||
[
|
||||
CpuQuery,
|
||||
RamUsedQuery,
|
||||
RamTotalQuery,
|
||||
RamPctQuery,
|
||||
DiskUsedQuery,
|
||||
DiskTotalQuery,
|
||||
DiskPctQuery,
|
||||
], ct);
|
||||
|
||||
_cpu = values[0] is { } rawCpu
|
||||
? _loaded ? CpuEmaAlpha * rawCpu + (1 - CpuEmaAlpha) * (_cpu ?? rawCpu) : rawCpu
|
||||
: null;
|
||||
_ramUsedBytes = values[1];
|
||||
_ramTotalBytes = values[2];
|
||||
_ramPct = values[3];
|
||||
_diskUsedBytes = values[4];
|
||||
_diskTotalBytes = values[5];
|
||||
_diskPct = values[6];
|
||||
_error = null;
|
||||
_loaded = true;
|
||||
}
|
||||
catch (Exception ex) when (ex is HttpRequestException or TaskCanceledException)
|
||||
{
|
||||
_error = ex.Message;
|
||||
}
|
||||
}
|
||||
private static double? Lookup(IReadOnlyList<VictoriaMetricsClient.SeriesResult> series, string card)
|
||||
=> series.FirstOrDefault(s => s.Labels.GetValueOrDefault("card") == card)?.Value;
|
||||
|
||||
private static string Pct(double? value)
|
||||
=> value is null ? "-- %" : $"{value:F0} %";
|
||||
|
||||
private static string F0(double value) => $"{value:F0}";
|
||||
|
||||
private static string GB(double? bytes)
|
||||
=> bytes is null ? "--" : $"{bytes / 1024 / 1024 / 1024:F1} GB";
|
||||
|
||||
private static string Val(double? value, string unit)
|
||||
=> value is null ? "--" : unit switch
|
||||
{
|
||||
"%" => $"{value:F0} %",
|
||||
"GB" => $"{value / 1024 / 1024 / 1024:F1} GB",
|
||||
" W" => $"{value:F1} W",
|
||||
" RPM" => $"{value:F0} RPM",
|
||||
" %" => $"{value:F0} %",
|
||||
_ => value.ToString() ?? "--",
|
||||
};
|
||||
|
||||
private static string Temp(double? celsius)
|
||||
=> celsius is null ? "--" : $"{celsius:F0} °C";
|
||||
|
||||
public void Dispose() => _cts?.Cancel();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,64 @@ public sealed class VictoriaMetricsClient
|
||||
/// </summary>
|
||||
public sealed record SeriesResult(IReadOnlyDictionary<string, string> Labels, double Value);
|
||||
|
||||
/// <summary>
|
||||
/// One range series with its labels (e.g. per-GPU histories).
|
||||
/// </summary>
|
||||
public sealed record SeriesRange(
|
||||
IReadOnlyDictionary<string, string> Labels,
|
||||
IReadOnlyList<RangePoint> Points);
|
||||
|
||||
/// <summary>
|
||||
/// Runs a range query over every result series (label-aware).
|
||||
/// </summary>
|
||||
public async Task<IReadOnlyList<SeriesRange>> QueryRangeSeriesAsync(
|
||||
string promql, DateTimeOffset start, DateTimeOffset end, TimeSpan step,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var url = string.Create(CultureInfo.InvariantCulture,
|
||||
$"/api/v1/query_range?query={Uri.EscapeDataString(promql)}"
|
||||
+ $"&start={start.ToUnixTimeSeconds()}&end={end.ToUnixTimeSeconds()}"
|
||||
+ $"&step={(int)step.TotalSeconds}");
|
||||
using var response = await _http.GetAsync(url, ct);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
using var doc = await response.Content.ReadFromJsonAsync<JsonDocument>(ct);
|
||||
var series = new List<SeriesRange>();
|
||||
if (doc is null)
|
||||
{
|
||||
return series;
|
||||
}
|
||||
var result = doc.RootElement
|
||||
.GetProperty("data")
|
||||
.GetProperty("result");
|
||||
if (result.ValueKind != JsonValueKind.Array)
|
||||
{
|
||||
return series;
|
||||
}
|
||||
foreach (var item in result.EnumerateArray())
|
||||
{
|
||||
var labels = new Dictionary<string, string>();
|
||||
foreach (var label in item.GetProperty("metric").EnumerateObject())
|
||||
{
|
||||
labels[label.Name] = label.Value.GetString() ?? "";
|
||||
}
|
||||
var points = new List<RangePoint>();
|
||||
foreach (var point in item.GetProperty("values").EnumerateArray())
|
||||
{
|
||||
var raw = point[1].GetString();
|
||||
if (!double.TryParse(raw, NumberStyles.Float,
|
||||
CultureInfo.InvariantCulture, out var value))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
points.Add(new RangePoint(
|
||||
DateTimeOffset.FromUnixTimeSeconds(point[0].GetInt64()), value));
|
||||
}
|
||||
series.Add(new SeriesRange(labels, points));
|
||||
}
|
||||
return series;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// One point of a query_range result.
|
||||
/// </summary>
|
||||
|
||||
@@ -178,16 +178,45 @@ a {
|
||||
|
||||
/* ---- braille chart (btop style) ---- */
|
||||
.braille-chart {
|
||||
position: relative;
|
||||
font-family: "DejaVu Sans Mono", monospace;
|
||||
letter-spacing: 0.02em;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
/* Grid/Graph starten erst hinter der Y-Achsenbeschriftung. */
|
||||
background-origin: content-box;
|
||||
}
|
||||
|
||||
.braille-chart.with-y-labels {
|
||||
padding-left: 36px;
|
||||
}
|
||||
|
||||
.braille-chart span {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Very small Y-axis labels at 25/50/75/100 % of the scale. */
|
||||
.braille-y-labels {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: 30px;
|
||||
text-align: right;
|
||||
z-index: 1;
|
||||
pointer-events: none;
|
||||
font-size: 8px;
|
||||
line-height: 8px;
|
||||
}
|
||||
|
||||
.braille-y-labels span {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
transform: translateY(100%);
|
||||
color: var(--overlay0);
|
||||
text-shadow: 0 0 3px var(--base);
|
||||
}
|
||||
|
||||
/* Grid variants behind the graph (coarser than the data resolution). */
|
||||
.braille-grid-dots {
|
||||
background-image: radial-gradient(circle, var(--surface0) 1px, transparent 1.5px);
|
||||
@@ -206,6 +235,16 @@ a {
|
||||
background-image: none;
|
||||
}
|
||||
|
||||
/* Dots at 25% intervals: percentage background-size scales with any
|
||||
chart dimension; the dot sits on every quarter intersection. */
|
||||
.braille-grid-dots25 {
|
||||
background-image: radial-gradient(circle at left bottom,
|
||||
var(--surface0) 1.2px, transparent 1.9px);
|
||||
background-size: 25% 25%;
|
||||
background-repeat: repeat;
|
||||
background-position: left bottom;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 700;
|
||||
@@ -220,6 +259,95 @@ a {
|
||||
color: var(--surface2);
|
||||
}
|
||||
|
||||
/* ---- overlay tiles (chart behind the controls, fade to the left) ---- */
|
||||
.tile-overlay {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.tile-copy {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.15rem;
|
||||
/* Diffuser Schleier hinter den Controls: zur Chart-Seite auslaufend. */
|
||||
background: radial-gradient(ellipse at left center,
|
||||
rgba(30, 30, 46, 0.88) 0%,
|
||||
rgba(30, 30, 46, 0.55) 55%,
|
||||
transparent 78%);
|
||||
}
|
||||
|
||||
/* Glyphen-Halo, damit der Text über dem Graph lesbar bleibt.
|
||||
Die Legende (tile-sub) bekommt den dichtesten Halo: sie liegt
|
||||
am tiefsten im Chart und hat die kleinste Schrift. */
|
||||
.tile-copy .tile-label {
|
||||
text-shadow: 0 0 4px var(--base), 0 0 8px var(--base), 0 0 12px var(--base);
|
||||
}
|
||||
|
||||
.tile-copy .tile-sub {
|
||||
text-shadow: 0 0 3px var(--base), 0 0 6px var(--base),
|
||||
0 0 9px var(--base), 0 0 14px var(--base),
|
||||
0 0 20px var(--mantle), 0 0 26px var(--mantle);
|
||||
}
|
||||
|
||||
.tile-copy .tile-value {
|
||||
/* Glow der Werte nicht vom Halo erstickten lassen. */
|
||||
text-shadow: 0 0 4px var(--base), 0 0 8px var(--base),
|
||||
0 0 14px rgba(166, 227, 161, 0.4);
|
||||
}
|
||||
|
||||
.tile-chart {
|
||||
position: absolute;
|
||||
top: 0.55rem;
|
||||
right: 0.55rem;
|
||||
bottom: 0.55rem;
|
||||
width: 58%;
|
||||
z-index: 0;
|
||||
/* Graph fades out toward the controls on the left. */
|
||||
-webkit-mask-image: linear-gradient(to right, transparent 0, #000 30%);
|
||||
mask-image: linear-gradient(to right, transparent 0, #000 30%);
|
||||
}
|
||||
|
||||
/* ---- gpu split (compact values left, braille chart right) ---- */
|
||||
.gpu-split {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
/* Wertepaare kleben am Label (max-content), Rest geht an den Chart. */
|
||||
.gpu-values {
|
||||
display: grid;
|
||||
grid-template-columns: max-content max-content;
|
||||
column-gap: 0.9rem;
|
||||
row-gap: 0.25rem;
|
||||
align-content: start;
|
||||
border-right: 1px dashed var(--surface1);
|
||||
padding-right: 0.9rem;
|
||||
padding-left: 0.7rem;
|
||||
}
|
||||
|
||||
.gpu-values .val {
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.gpu-values-wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
/* Chart bündig mit den dashed Trennern (Panel-Padding 0.9rem). */
|
||||
.gpu-chart {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
padding-left: 0.9rem;
|
||||
margin-top: -0.9rem;
|
||||
margin-bottom: -0.9rem;
|
||||
}
|
||||
|
||||
/* ---- ascii spinners ---- */
|
||||
.ascii-spin {
|
||||
display: inline-block;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
window.gnmon = {
|
||||
clientWidth: (element) => element ? element.clientWidth : 0,
|
||||
|
||||
clientHeight: (element) => element ? element.clientHeight : 0,
|
||||
|
||||
// Exact per-glyph advance of a rendered monospace text row
|
||||
// (includes letter-spacing and any font fallback metrics).
|
||||
charAdvance: (span) => {
|
||||
@@ -14,4 +16,27 @@ window.gnmon = {
|
||||
const chars = span.textContent ? span.textContent.length : 0;
|
||||
return chars > 0 && rect.width > 0 ? rect.width / chars : 0;
|
||||
},
|
||||
|
||||
_sizeObservers: new Map(),
|
||||
|
||||
observeSize: (element, dotnetRef) => {
|
||||
if (!element || !dotnetRef) {
|
||||
return;
|
||||
}
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
const rect = entries[0].contentRect;
|
||||
dotnetRef.invokeMethodAsync('OnResized',
|
||||
Math.round(rect.width), Math.round(rect.height));
|
||||
});
|
||||
observer.observe(element);
|
||||
window.gnmon._sizeObservers.set(element, observer);
|
||||
},
|
||||
|
||||
unobserveSize: (element) => {
|
||||
const observer = window.gnmon._sizeObservers.get(element);
|
||||
if (observer) {
|
||||
observer.disconnect();
|
||||
window.gnmon._sizeObservers.delete(element);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user