feat(agent): host collector for /proc loadavg, meminfo, uptime

This commit is contained in:
Carsten 2026-04-21 22:08:04 +02:00
parent e4db0beac6
commit ce828084c8
5 changed files with 152 additions and 0 deletions

1
agent/test/fixtures/proc/loadavg vendored Normal file
View file

@ -0,0 +1 @@
0.42 0.55 0.31 3/512 12345

7
agent/test/fixtures/proc/meminfo vendored Normal file
View file

@ -0,0 +1,7 @@
MemTotal: 16384000 kB
MemFree: 2048000 kB
MemAvailable: 8192000 kB
Buffers: 256000 kB
Cached: 4096000 kB
SwapTotal: 4194304 kB
SwapFree: 4194304 kB

1
agent/test/fixtures/proc/uptime vendored Normal file
View file

@ -0,0 +1 @@
123456.78 987654.32

View file

@ -0,0 +1,37 @@
defmodule ProxmoxAgent.Collectors.HostTest do
use ExUnit.Case, async: true
alias ProxmoxAgent.Collectors.Host
@proc Path.expand("../../fixtures/proc", __DIR__)
test "collects load average" do
sample = Host.collect(proc_dir: @proc)
assert sample.load1 == 0.42
assert sample.load5 == 0.55
assert sample.load15 == 0.31
end
test "collects memory in bytes" do
sample = Host.collect(proc_dir: @proc)
assert sample.mem_total_bytes == 16_384_000 * 1024
assert sample.mem_available_bytes == 8_192_000 * 1024
assert sample.mem_used_bytes == sample.mem_total_bytes - sample.mem_available_bytes
end
test "collects uptime seconds" do
sample = Host.collect(proc_dir: @proc)
assert sample.uptime_seconds == 123_456
end
test "includes hostname string" do
sample = Host.collect(proc_dir: @proc)
assert is_binary(sample.hostname)
assert sample.hostname != ""
end
test "missing proc files yield :errors field, not a crash" do
sample = Host.collect(proc_dir: "/nonexistent/path/xyz")
assert sample.errors != []
end
end