diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-02 12:41:08 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-02 12:41:08 +0200 |
| commit | d0b9bc84aed1898a06a9d6fc3b82beee407d3cde (patch) | |
| tree | 7bb343960ee912d77dbc9f7720cd8cdd1f0172ea /internal/collector | |
| parent | bbc91e8764bd83c4497f2ddac86bb8947a91765c (diff) | |
Refactor display iteration/state and harden collector runtime
Diffstat (limited to 'internal/collector')
| -rw-r--r-- | internal/collector/collector.go | 5 | ||||
| -rw-r--r-- | internal/collector/types.go | 52 |
2 files changed, 11 insertions, 46 deletions
diff --git a/internal/collector/collector.go b/internal/collector/collector.go index 5c99347..9ee7e02 100644 --- a/internal/collector/collector.go +++ b/internal/collector/collector.go @@ -5,6 +5,7 @@ import ( "bytes" "context" "fmt" + "os" "os/exec" "strings" "time" @@ -163,8 +164,8 @@ func isLocal(h string) bool { // getLocalScript returns the appropriate script for the local OS func getLocalScript() []byte { - // Check if /proc exists (Linux/Unix) - if _, err := exec.Command("test", "-d", "/proc").CombinedOutput(); err == nil { + // Check if /proc exists (Linux/Unix). + if st, err := os.Stat("/proc"); err == nil && st.IsDir() { return LinuxScript } // /proc not found - unsupported OS for local stats gathering diff --git a/internal/collector/types.go b/internal/collector/types.go index 6d1ecf0..3fac47b 100644 --- a/internal/collector/types.go +++ b/internal/collector/types.go @@ -1,46 +1,10 @@ package collector -// CPULine is one line of /proc/stat: cpu name + counters (user, nice, system, idle, ...). -type CPULine struct { - Name string - User, Nice, System, Idle, Iowait, IRQ, SoftIRQ, Steal, Guest, GuestNice int64 -} - -// Total returns sum of all CPU counters. -func (c CPULine) Total() int64 { - return c.User + c.Nice + c.System + c.Idle + c.Iowait + c.IRQ + c.SoftIRQ + c.Steal + c.Guest + c.GuestNice -} - -// MemLine is one key from /proc/meminfo (e.g. MemTotal, MemFree). -type MemLine struct { - Key string - Value int64 -} - -// NetLine is one interface line: iface and key=value pairs (b, tb, p, tp, e, te, d, td). -type NetLine struct { - Iface string - B int64 // rx bytes - Tb int64 // tx bytes - P int64 - Tp int64 - E int64 - Te int64 - D int64 - Td int64 -} - -// LoadAvg is 1/5/15 min load average. -type LoadAvg struct { - Load1, Load5, Load15 string -} - -// DiskLine is one device from /proc/diskstats with cumulative counters. -type DiskLine struct { - Device string - SectorsRead int64 // cumulative sectors read (each sector = 512 bytes) - SectorsWrite int64 // cumulative sectors written - ReadTicks int64 // cumulative ms spent reading - WriteTicks int64 // cumulative ms spent writing - IoTicks int64 // cumulative ms the device had I/O in progress -} +import "codeberg.org/snonux/loadbars/internal/stats" + +// Collector parsing uses the shared stats protocol types. +type CPULine = stats.CPULine +type MemLine = stats.MemLine +type NetLine = stats.NetLine +type LoadAvg = stats.LoadAvg +type DiskLine = stats.DiskLine |
