summaryrefslogtreecommitdiff
path: root/internal/app
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-14 00:12:54 +0200
committerPaul Buetow <paul@buetow.org>2026-02-14 00:12:54 +0200
commit5e416d613f61cfc16277d343e30c3c8a00b21b35 (patch)
treed73b06932e9806c21f4ff7a8bf3f985b361f82cf /internal/app
parent956f84321860bd8e318545564474037cbd3b6fd9 (diff)
remove version and some refactoring
Diffstat (limited to 'internal/app')
-rw-r--r--internal/app/app.go3
-rw-r--r--internal/app/script.go29
-rw-r--r--internal/app/store.go32
3 files changed, 17 insertions, 47 deletions
diff --git a/internal/app/app.go b/internal/app/app.go
index 4544f0f..c18dc30 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -15,7 +15,6 @@ func Run(cfg *config.Config) error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
- scriptPath := ScriptPath()
store := NewStore()
var wg sync.WaitGroup
@@ -24,7 +23,7 @@ func Run(cfg *config.Config) error {
wg.Add(1)
go func() {
defer wg.Done()
- _ = collector.Run(ctx, h, cfg, store, scriptPath)
+ _ = collector.Run(ctx, h, cfg, store)
}()
}
diff --git a/internal/app/script.go b/internal/app/script.go
deleted file mode 100644
index 2701cb2..0000000
--- a/internal/app/script.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package app
-
-import (
- "os"
- "path/filepath"
-)
-
-// ScriptPath returns the path to the loadbars-remote.sh script.
-// It looks for scripts/loadbars-remote.sh relative to the executable, then current dir.
-func ScriptPath() string {
- exe, err := os.Executable()
- if err == nil {
- dir := filepath.Dir(exe)
- // When installed: exe is /usr/bin/loadbars, script might be /usr/share/loadbars/scripts/
- for _, sub := range []string{"scripts/loadbars-remote.sh", "../scripts/loadbars-remote.sh", "../../scripts/loadbars-remote.sh"} {
- p := filepath.Join(dir, sub)
- if _, err := os.Stat(p); err == nil {
- return p
- }
- }
- }
- // Development: run from repo root
- if p, err := filepath.Abs("scripts/loadbars-remote.sh"); err == nil {
- if _, err := os.Stat(p); err == nil {
- return p
- }
- }
- return "scripts/loadbars-remote.sh"
-}
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)