1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 20:15:07 +00:00

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.
This commit is contained in:
Noah Qin
2026-03-04 02:59:01 +08:00
committed by GitHub
parent 68430737cf
commit fbaf5e7c91

View File

@@ -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)