From fbaf5e7c9139e628a520c97b17699624c392a223 Mon Sep 17 00:00:00 2001 From: Noah Qin <105060587+imnotnoahhh@users.noreply.github.com> Date: Wed, 4 Mar 2026 02:59:01 +0800 Subject: [PATCH] fix(status): enable network data in JSON mode (#532) Network rate calculation requires two samples to compute the delta. In JSON mode, the collector was only called once, causing the network field to always return nil. This change adds a second collection call with a 1-second interval, allowing the network rates to be calculated properly. --- cmd/status/main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/status/main.go b/cmd/status/main.go index 900238c..b7eeb01 100644 --- a/cmd/status/main.go +++ b/cmd/status/main.go @@ -212,6 +212,14 @@ func animTickWithSpeed(cpuUsage float64) tea.Cmd { // runJSONMode collects metrics once and outputs as JSON. func runJSONMode() { collector := NewCollector() + + // First collection initializes network state (returns nil for network) + _, _ = collector.Collect() + + // Wait 1 second for network rate calculation + time.Sleep(1 * time.Second) + + // Second collection has actual network data data, err := collector.Collect() if err != nil { fmt.Fprintf(os.Stderr, "error collecting metrics: %v\n", err)