summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Magefile.go96
-rw-r--r--NOTICE34
-rw-r--r--README.md15
-rw-r--r--cmd/loadbars/main.go13
-rw-r--r--go.mod8
-rw-r--r--go.sum2
-rw-r--r--internal/app/app.go6
-rw-r--r--internal/app/store.go4
-rw-r--r--internal/collector/collector.go2
-rw-r--r--internal/config/config.go2
-rw-r--r--internal/display/display.go8
-rw-r--r--internal/stats/stats.go2
-rwxr-xr-xloadbars-gobin3847840 -> 0 bytes
14 files changed, 165 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index 6e5aea8..e9293f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
.serena/
+/loadbars
diff --git a/Magefile.go b/Magefile.go
new file mode 100644
index 0000000..119f0b8
--- /dev/null
+++ b/Magefile.go
@@ -0,0 +1,96 @@
+//go:build mage
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "path/filepath"
+
+ "github.com/magefile/mage/mg"
+ "github.com/magefile/mage/sh"
+)
+
+const (
+ binaryName = "loadbars"
+ shareName = "loadbars"
+)
+
+// Default sets the default target (build).
+func Default() { mg.Deps(Build) }
+
+// Build compiles the loadbars binary.
+func Build() error {
+ return sh.RunV("go", "build", "-o", binaryName, "./cmd/loadbars")
+}
+
+// Test runs the test suite.
+func Test() error {
+ return sh.RunV("go", "test", "./...")
+}
+
+// Install builds and installs the binary, script, and NOTICE under DESTDIR.
+// Usage: DESTDIR=/tmp/install mage install (or mage install for DESTDIR empty)
+func Install() error {
+ mg.Deps(Build)
+ dest := getDestDir()
+ binDir := filepath.Join(dest, "usr", "bin")
+ shareDir := filepath.Join(dest, "usr", "share", shareName)
+ scriptsDir := filepath.Join(shareDir, "scripts")
+ if err := os.MkdirAll(binDir, 0755); err != nil {
+ return fmt.Errorf("mkdir %s: %w", binDir, err)
+ }
+ if err := os.MkdirAll(scriptsDir, 0755); err != nil {
+ return fmt.Errorf("mkdir %s: %w", scriptsDir, err)
+ }
+ if err := sh.Copy(filepath.Join(binDir, binaryName), binaryName); err != nil {
+ return fmt.Errorf("copy binary: %w", err)
+ }
+ if err := sh.Copy(filepath.Join(scriptsDir, "loadbars-remote.sh"), "scripts/loadbars-remote.sh"); err != nil {
+ return fmt.Errorf("copy script: %w", err)
+ }
+ if err := sh.Copy(filepath.Join(shareDir, "NOTICE"), "NOTICE"); err != nil {
+ return fmt.Errorf("copy NOTICE: %w", err)
+ }
+ fmt.Printf("Installed to %s (binary: %s/usr/bin/%s)\n", dest, dest, binaryName)
+ return nil
+}
+
+// Uninstall removes files installed by Install from DESTDIR.
+func Uninstall() error {
+ return deinstall()
+}
+
+// Deinstall is an alias for Uninstall.
+func Deinstall() error {
+ return deinstall()
+}
+
+func deinstall() error {
+ dest := getDestDir()
+ if dest == "" {
+ return fmt.Errorf("DESTDIR must be set to uninstall (e.g. DESTDIR=/tmp/install mage uninstall)")
+ }
+ paths := []string{
+ filepath.Join(dest, "usr", "bin", binaryName),
+ filepath.Join(dest, "usr", "share", shareName, "scripts", "loadbars-remote.sh"),
+ filepath.Join(dest, "usr", "share", shareName, "NOTICE"),
+ }
+ for _, p := range paths {
+ if err := os.Remove(p); err != nil && !os.IsNotExist(err) {
+ return fmt.Errorf("remove %s: %w", p, err)
+ }
+ }
+ // Remove empty dirs
+ _ = os.Remove(filepath.Join(dest, "usr", "share", shareName, "scripts"))
+ _ = os.Remove(filepath.Join(dest, "usr", "share", shareName))
+ fmt.Printf("Uninstalled from %s\n", dest)
+ return nil
+}
+
+func getDestDir() string {
+ if d := os.Getenv("DESTDIR"); d != "" {
+ return filepath.Clean(d)
+ }
+ return ""
+}
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..c900be5
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,34 @@
+Loadbars - real-time server load monitoring
+Copyright (c) 2010-2026 Paul Buetow <loadbars@dev.buetow.org>
+
+This product includes software developed by third parties:
+
+----------------------------------------------------------------------
+go-sdl2 (github.com/veandco/go-sdl2)
+----------------------------------------------------------------------
+Copyright (c) 2013, Go-SDL2 Authors
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of Go-SDL2 nor the names of its contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.md b/README.md
index c1cc2d5..c0f90dd 100644
--- a/README.md
+++ b/README.md
@@ -38,17 +38,18 @@ loadbars servername{01..50}.example.com --showcores 1
Loadbars is a small script that can be used to observe CPU loads of several remote servers at once in real time. It connects with SSH (using SSH public/private key auth) to several servers at once and vizualizes all server CPUs and memory statistics right next each other (either summarized or each core separately). Loadbars is not a tool for collecting CPU loads and drawing graphs for later analysis. However, since such tools require a significant amount of time before producing results, Loadbars lets you observe the current state immediately. Loadbars does not remember or record any load information. It just shows the current CPU usages like top or vmstat does.
-## Go version (loadbars-go)
+## Build and run
-A Go rewrite is available in this repo. Build and run:
+Build the binary:
```bash
-go build -o loadbars-go ./cmd/loadbars
-./loadbars-go --hosts localhost
-# or: just go-build && ./loadbars-go --hosts localhost
+go build -o loadbars ./cmd/loadbars
+./loadbars --hosts localhost
```
-Remote hosts need no Perl: the Go binary pipes `scripts/loadbars-remote.sh` over SSH. Install: `just go-install DESTDIR=/tmp/loadbars`.
+Or use [mage](https://magefile.org): `mage build` (default), `mage test`, `mage install` (set `DESTDIR` for install path), `mage uninstall` / `mage deinstall`.
+
+Remote hosts need no Perl: the binary pipes `scripts/loadbars-remote.sh` over SSH.
## Installation
@@ -133,6 +134,8 @@ will always show all CPU cores. If you press the 'w' hotkey during program execu
See package description or project website.
+The Go build of loadbars links to **go-sdl2** (github.com/veandco/go-sdl2), which is licensed under the **BSD-3-Clause** license. That license is compatible with loadbars' use and does not impose additional restrictions on distribution. The full copyright notice and license text for go-sdl2 are in the [NOTICE](NOTICE) file.
+
## Author
Paul Buetow - <http://buetow.org>
diff --git a/cmd/loadbars/main.go b/cmd/loadbars/main.go
index f4e8985..fc053be 100644
--- a/cmd/loadbars/main.go
+++ b/cmd/loadbars/main.go
@@ -6,10 +6,10 @@ import (
"os"
"strings"
- "github.com/loadbars/loadbars/internal/app"
- "github.com/loadbars/loadbars/internal/config"
- "github.com/loadbars/loadbars/internal/constants"
- "github.com/loadbars/loadbars/internal/version"
+ "codeberg.org/snonux/loadbars/internal/app"
+ "codeberg.org/snonux/loadbars/internal/config"
+ "codeberg.org/snonux/loadbars/internal/constants"
+ "codeberg.org/snonux/loadbars/internal/version"
)
func main() {
@@ -84,10 +84,9 @@ func main() {
os.Exit(constants.Success)
}
+ // No hosts given: run locally without SSH
if len(cfg.Hosts) == 0 {
- fmt.Fprintf(os.Stderr, "loadbars: no hosts specified (use --hosts or --cluster)\n")
- printUsage()
- os.Exit(constants.ENoHost)
+ cfg.Hosts = []string{"localhost"}
}
if err := app.Run(&cfg); err != nil {
diff --git a/go.mod b/go.mod
index 78c31da..62232b6 100644
--- a/go.mod
+++ b/go.mod
@@ -1,5 +1,7 @@
-module github.com/loadbars/loadbars
+module codeberg.org/snonux/loadbars
-go 1.21
+go 1.25
-require github.com/veandco/go-sdl2 v0.4.40 // indirect
+require github.com/veandco/go-sdl2 v0.4.40
+
+require github.com/magefile/mage v1.15.0 // indirect
diff --git a/go.sum b/go.sum
index bc27727..7ac6a77 100644
--- a/go.sum
+++ b/go.sum
@@ -1,2 +1,4 @@
+github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg=
+github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/veandco/go-sdl2 v0.4.40 h1:fZv6wC3zz1Xt167P09gazawnpa0KY5LM7JAvKpX9d/U=
github.com/veandco/go-sdl2 v0.4.40/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=
diff --git a/internal/app/app.go b/internal/app/app.go
index 946e985..4544f0f 100644
--- a/internal/app/app.go
+++ b/internal/app/app.go
@@ -4,9 +4,9 @@ import (
"context"
"sync"
- "github.com/loadbars/loadbars/internal/collector"
- "github.com/loadbars/loadbars/internal/config"
- "github.com/loadbars/loadbars/internal/display"
+ "codeberg.org/snonux/loadbars/internal/collector"
+ "codeberg.org/snonux/loadbars/internal/config"
+ "codeberg.org/snonux/loadbars/internal/display"
)
// Run starts the loadbars application: collectors and display.
diff --git a/internal/app/store.go b/internal/app/store.go
index f9c90ef..424bb17 100644
--- a/internal/app/store.go
+++ b/internal/app/store.go
@@ -3,8 +3,8 @@ package app
import (
"sync"
- "github.com/loadbars/loadbars/internal/collector"
- "github.com/loadbars/loadbars/internal/stats"
+ "codeberg.org/snonux/loadbars/internal/collector"
+ "codeberg.org/snonux/loadbars/internal/stats"
)
// Store holds current stats from all hosts and implements collector.StatsStore.
diff --git a/internal/collector/collector.go b/internal/collector/collector.go
index f2f89de..bdd5ada 100644
--- a/internal/collector/collector.go
+++ b/internal/collector/collector.go
@@ -9,7 +9,7 @@ import (
"strings"
"time"
- "github.com/loadbars/loadbars/internal/config"
+ "codeberg.org/snonux/loadbars/internal/config"
)
// StatsStore is the interface for receiving parsed stats (implemented by app).
diff --git a/internal/config/config.go b/internal/config/config.go
index 7551a10..256484a 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -8,7 +8,7 @@ import (
"strconv"
"strings"
- "github.com/loadbars/loadbars/internal/constants"
+ "codeberg.org/snonux/loadbars/internal/constants"
)
// Config holds all loadbars configuration (file + CLI).
diff --git a/internal/display/display.go b/internal/display/display.go
index 5c06d1d..7627c63 100644
--- a/internal/display/display.go
+++ b/internal/display/display.go
@@ -7,10 +7,10 @@ import (
"sort"
"time"
- "github.com/loadbars/loadbars/internal/collector"
- "github.com/loadbars/loadbars/internal/config"
- "github.com/loadbars/loadbars/internal/constants"
- "github.com/loadbars/loadbars/internal/stats"
+ "codeberg.org/snonux/loadbars/internal/collector"
+ "codeberg.org/snonux/loadbars/internal/config"
+ "codeberg.org/snonux/loadbars/internal/constants"
+ "codeberg.org/snonux/loadbars/internal/stats"
"github.com/veandco/go-sdl2/sdl"
)
diff --git a/internal/stats/stats.go b/internal/stats/stats.go
index b78f2f7..f2ef85b 100644
--- a/internal/stats/stats.go
+++ b/internal/stats/stats.go
@@ -1,7 +1,7 @@
package stats
import (
- "github.com/loadbars/loadbars/internal/collector"
+ "codeberg.org/snonux/loadbars/internal/collector"
)
// NetStamp holds network stats and timestamp for delta calculation.
diff --git a/loadbars-go b/loadbars-go
deleted file mode 100755
index ae47fa8..0000000
--- a/loadbars-go
+++ /dev/null
Binary files differ