Go service (nasmon/) plus nfpm packaging (packaging/), carried over from the home_nas monorepo. Adds rpm packaging alongside the existing deb build (Fedora/RHEL/Rocky dependency names via nfpm overrides, per-format systemd unit path, dpkg+rpm-compatible maintainer scripts) and a Gitea Actions workflow that builds both formats on every push. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
package collect
|
|
|
|
import "testing"
|
|
|
|
func TestParseProcStat(t *testing.T) {
|
|
in := "cpu 100 0 50 800 50 0 0 0 0 0\ncpu0 50 0 25 400 25 0 0 0 0 0\n"
|
|
c, err := parseProcStat([]byte(in))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if c.total != 1000 || c.idle != 850 {
|
|
t.Errorf("total=%d idle=%d", c.total, c.idle)
|
|
}
|
|
if _, err := parseProcStat([]byte("intr 1 2 3\n")); err == nil {
|
|
t.Errorf("expected error without cpu line")
|
|
}
|
|
}
|
|
|
|
func TestParseMeminfo(t *testing.T) {
|
|
in := "MemTotal: 16000000 kB\nMemFree: 1000000 kB\nMemAvailable: 9000000 kB\nSwapTotal: 2000000 kB\nSwapFree: 1500000 kB\n"
|
|
m := parseMeminfo([]byte(in))
|
|
if m.Total != 16000000*1024 || m.Available != 9000000*1024 || m.Used != 7000000*1024 {
|
|
t.Errorf("mem = %+v", m)
|
|
}
|
|
if m.SwapTotal != 2000000*1024 || m.SwapUsed != 500000*1024 {
|
|
t.Errorf("swap = %+v", m)
|
|
}
|
|
}
|
|
|
|
func TestParseArcstats(t *testing.T) {
|
|
in := "13 1 0x01 123 1 2 3\nname type data\nhits 4 1000\nsize 4 4294967296\nc_max 4 8589934592\n"
|
|
size, max := parseArcstats([]byte(in))
|
|
if size != 4294967296 || max != 8589934592 {
|
|
t.Errorf("size=%d max=%d", size, max)
|
|
}
|
|
}
|
|
|
|
func TestCPUTemp(t *testing.T) {
|
|
temps := []Temp{
|
|
{Chip: "nvme", Label: "Composite", C: 41},
|
|
{Chip: "coretemp", Label: "Package id 0", C: 55},
|
|
{Chip: "coretemp", Label: "Core 0", C: 52},
|
|
{Chip: "acpitz", Label: "temp1", C: 27},
|
|
}
|
|
c, ok := CPUTemp(temps)
|
|
if !ok || c != 55 {
|
|
t.Errorf("cpu temp = %v %v", c, ok)
|
|
}
|
|
if _, ok := CPUTemp([]Temp{{Chip: "nvme", Label: "Composite", C: 41}}); ok {
|
|
t.Errorf("nvme must not count as CPU")
|
|
}
|
|
}
|
|
|
|
func TestParseSmbSessions(t *testing.T) {
|
|
in := `{"timestamp": "x", "version": "4.19", "smb_conf": "/etc/samba/smb.conf", "sessions": {"123": {"username": "a"}, "456": {"username": "b"}}}`
|
|
if n := parseSmbSessions([]byte(in)); n != 2 {
|
|
t.Errorf("sessions = %d", n)
|
|
}
|
|
if n := parseSmbSessions([]byte("garbage")); n != 0 {
|
|
t.Errorf("garbage = %d", n)
|
|
}
|
|
}
|