diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-14 00:12:54 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-14 00:12:54 +0200 |
| commit | 5e416d613f61cfc16277d343e30c3c8a00b21b35 (patch) | |
| tree | d73b06932e9806c21f4ff7a8bf3f985b361f82cf /internal/app/store.go | |
| parent | 956f84321860bd8e318545564474037cbd3b6fd9 (diff) | |
remove version and some refactoring
Diffstat (limited to 'internal/app/store.go')
| -rw-r--r-- | internal/app/store.go | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/internal/app/store.go b/internal/app/store.go index 424bb17..9e046a4 100644 --- a/internal/app/store.go +++ b/internal/app/store.go @@ -26,18 +26,7 @@ func NewStore() *Store { return &Store{hosts: make(map[string]*hostData)} } -func (s *Store) getOrCreate(host string) *hostData { - if s.hosts[host] == nil { - s.hosts[host] = &hostData{ - mem: make(map[string]int64), - net: make(map[string]stats.NetStamp), - cpu: make(map[string]collector.CPULine), - } - } - return s.hosts[host] -} - -// SetLoadAvg implements collector.StatsStore. +// SetLoadAvg sets the load average for the given host. func (s *Store) SetLoadAvg(host, load1, load5, load15 string) { s.mu.Lock() defer s.mu.Unlock() @@ -45,7 +34,7 @@ func (s *Store) SetLoadAvg(host, load1, load5, load15 string) { d.load1, d.load5, d.load15 = load1, load5, load15 } -// SetCPU implements collector.StatsStore. +// SetCPU sets the CPU line for the given host and CPU name. func (s *Store) SetCPU(host, name string, line collector.CPULine) { s.mu.Lock() defer s.mu.Unlock() @@ -53,7 +42,7 @@ func (s *Store) SetCPU(host, name string, line collector.CPULine) { d.cpu[name] = line } -// SetMem implements collector.StatsStore. +// SetMem sets a meminfo key/value for the given host. func (s *Store) SetMem(host, key string, value int64) { s.mu.Lock() defer s.mu.Unlock() @@ -61,7 +50,7 @@ func (s *Store) SetMem(host, key string, value int64) { d.mem[key] = value } -// SetNet implements collector.StatsStore. +// SetNet sets the network stamp for the given host and interface. func (s *Store) SetNet(host, iface string, net collector.NetLine, stamp float64) { s.mu.Lock() defer s.mu.Unlock() @@ -69,7 +58,7 @@ func (s *Store) SetNet(host, iface string, net collector.NetLine, stamp float64) d.net[iface] = stats.NetStamp{B: net.B, Tb: net.Tb, Stamp: stamp} } -// Snapshot returns a copy of current stats for all hosts (for display). +// Snapshot returns a copy of current stats for all hosts for the display. func (s *Store) Snapshot() map[string]*stats.HostStats { s.mu.RLock() defer s.mu.RUnlock() @@ -99,5 +88,16 @@ func (s *Store) Snapshot() map[string]*stats.HostStats { return out } +func (s *Store) getOrCreate(host string) *hostData { + if s.hosts[host] == nil { + s.hosts[host] = &hostData{ + mem: make(map[string]int64), + net: make(map[string]stats.NetStamp), + cpu: make(map[string]collector.CPULine), + } + } + return s.hosts[host] +} + var _ stats.Source = (*Store)(nil) var _ collector.StatsStore = (*Store)(nil) |
