Table/columns: - Fix the "columns shrink to tiny" bug on language change / add / hide (#3, #24): the rebuild-time capped autosize read column widths before GTK's measurement landed. Columns keep their default widths; autosize is on-demand only. - Right-align every column except IP (#21): new alignment param on the bridge append calls; the SegmentRenderer and the tooltip hit-test honour it. - "Auto-size all columns" header menu item; Ctrl+A selects all rows (#4). - Remove the Boards (dots) column (#7). - Split the slash-joined Fan column into per-fan columns Fan 1-4 (#8). - Efficiency: unit moved into the value and made algorithm-aware (J/TH for SHA256 families, J/kSol for Equihash), fixing the blank/garbage figure on non-SHA256 miners (#9, #23). - Pool account column before Worker by default (#22). Scan: - Fast scan (#18): emit a lightweight identity row the instant a miner is identified, then upsert the full telemetry row when get_data completes. - User-adjustable scan concurrency with a bounded max (#25). - Surface more scanned values as columns (#10): current tuning target, accepted / rejected shares + reject %, and per-hashboard hashrate / voltage / frequency. Logs (#11-16): fetch the miner log through asic-rs's per-backend read_logs() instead of the narrow curl paths, fixing Braiins / LuxOS / Z15 / BixBit / stock Antminer; WhatsMiner keeps the fault-code fallback (no API log). Removed the summary tidbits from the log viewer (#13). Misc: fix per-icon health tooltips (advance math matched to the renderer) (#2); paused miners show blue hashboard icons, healthy stays green (#19); state-aware Pause/Resume in the right-click menu (#20); export opens a column-picker dialog (#6) and the default filename carries a UTC timestamp (#5); the scan status bar says "Scan Paused" / "Scan Stopped" and no longer overwrites Stop with paused (#17); the bench badge shows the weighted-average microbench delta vs the previous release (#1). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6
84 lines
3.5 KiB
Rust
84 lines
3.5 KiB
Rust
//! Fetch a miner's log for the "View log (API)" viewer (round 12 #12, reworked
|
|
//! round 19 #11-16).
|
|
//!
|
|
//! The log is fetched through asic-rs's per-backend `read_logs()` API, which
|
|
//! knows each firmware's real transport (Antminer/Z15 + BixBit stock web,
|
|
//! Braiins gRPC/journal, VNish and ePIC HTTP, ...). This replaced the GUI's
|
|
//! narrow three-way curl fetch, whose stock `/cgi-bin/log.cgi` `else` branch
|
|
//! failed on every firmware that does not serve that CGI (Braiins, LuxOS, Z15,
|
|
//! BixBit).
|
|
//!
|
|
//! WhatsMiner is the exception: its btminer log is not exposed over the API, and
|
|
//! asic-rs has no `read_logs` for it, so the viewer falls back to the active
|
|
//! fault codes (get_error_code on :4028, unauthenticated). LuxOS likewise has no
|
|
//! asic-rs log API and reports the log as unavailable.
|
|
|
|
/// Cap on the log text we keep for display (bytes); a miner's freshest lines are
|
|
/// at the tail, so we keep the tail.
|
|
const MAX_LOG_BYTES: usize = 256 * 1024;
|
|
|
|
/// A fetched log for the viewer.
|
|
pub struct LogScan {
|
|
/// The (possibly tail-trimmed) log text.
|
|
pub text: String,
|
|
}
|
|
|
|
/// Fetch one miner's log. `brand` is the make ("Antminer"/"Whatsminer"/...);
|
|
/// `timeout_secs` is the per-miner identification timeout. Returns `Err` only
|
|
/// when no log could be read.
|
|
pub fn scan_log(ip: &str, brand: &str, timeout_secs: u64) -> Result<LogScan, String> {
|
|
// WhatsMiner's real log is not exposed over its API and asic-rs has no
|
|
// read_logs for it, so show the active fault codes instead of failing.
|
|
if brand.eq_ignore_ascii_case("whatsminer") {
|
|
let resp = crate::access_probe::whatsminer_get_error_code(ip)
|
|
.ok_or_else(|| "WhatsMiner did not answer get_error_code on :4028".to_string())?;
|
|
return Ok(LogScan { text: tail(&resp, MAX_LOG_BYTES) });
|
|
}
|
|
let text = crate::scan::fetch_log(ip, timeout_secs)?;
|
|
if text.trim().is_empty() {
|
|
return Err("the miner returned an empty log".to_string());
|
|
}
|
|
Ok(LogScan { text: tail(&text, MAX_LOG_BYTES) })
|
|
}
|
|
|
|
/// Keep the last `max` bytes of `s` (a log's tail is the freshest), on a line
|
|
/// boundary, with a marker when trimmed.
|
|
fn tail(s: &str, max: usize) -> String {
|
|
if s.len() <= max {
|
|
return s.to_string();
|
|
}
|
|
// Nudge the cut forward to a UTF-8 char boundary first: a raw byte offset can
|
|
// land inside a multi-byte character and slicing there would panic (round 18
|
|
// #12; miner logs are not guaranteed pure ASCII).
|
|
let mut start = s.len() - max;
|
|
while start < s.len() && !s.is_char_boundary(start) {
|
|
start += 1;
|
|
}
|
|
// then advance to the next line boundary so we don't cut a line in half
|
|
let start = s[start..].find('\n').map(|i| start + i + 1).unwrap_or(start);
|
|
format!("[... earlier log trimmed ...]\n{}", &s[start..])
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn tail_does_not_panic_mid_multibyte_char() {
|
|
// A byte-offset cut can land inside a multi-byte character; tail must nudge
|
|
// to a char boundary rather than panic (round 18 #12).
|
|
let s = "\u{00e9}".repeat(200); // 400 bytes of 2-byte chars, no newlines
|
|
let out = tail(&s, 101); // cut at an odd offset -> inside a char
|
|
assert!(out.starts_with("[... earlier log trimmed ...]"));
|
|
assert!(out.len() < s.len());
|
|
}
|
|
|
|
#[test]
|
|
fn tail_trims_on_line_boundary() {
|
|
let log = "aaaa\nbbbb\ncccc\n";
|
|
let t = tail(log, 6);
|
|
assert!(t.starts_with("[... earlier log trimmed ...]"), "{t}");
|
|
assert!(t.ends_with("cccc\n"));
|
|
}
|
|
}
|