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/stats | |
| parent | bbc91e8764bd83c4497f2ddac86bb8947a91765c (diff) | |
Refactor display iteration/state and harden collector runtime
Diffstat (limited to 'internal/stats')
| -rw-r--r-- | internal/stats/stats.go | 6 | ||||
| -rw-r--r-- | internal/stats/types.go | 46 |
2 files changed, 47 insertions, 5 deletions
diff --git a/internal/stats/stats.go b/internal/stats/stats.go index 463268f..cc99483 100644 --- a/internal/stats/stats.go +++ b/internal/stats/stats.go @@ -1,9 +1,5 @@ package stats -import ( - "codeberg.org/snonux/loadbars/internal/collector" -) - // NetStamp holds network stats and timestamp for delta calculation. type NetStamp struct { B int64 @@ -24,7 +20,7 @@ type HostStats struct { LoadAvg1, LoadAvg5, LoadAvg15 string Mem map[string]int64 Net map[string]NetStamp - CPU map[string]collector.CPULine + CPU map[string]CPULine Disk map[string]DiskStamp } diff --git a/internal/stats/types.go b/internal/stats/types.go new file mode 100644 index 0000000..4094d2d --- /dev/null +++ b/internal/stats/types.go @@ -0,0 +1,46 @@ +package stats + +// 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 +} |
