chore(agent): log /proc reads, log diagnostics enable, comment trap_exit
Addresses final code review: - Host collector's /proc reads now go through Diagnostics.log_read/3, appearing in commands.log formatted as `$ cat /proc/loadavg` - configure/1 logs an info line on successful enable so the operator has a breadcrumb in the journal - Writer.init/1 documents the deliberate trap_exit omission
This commit is contained in:
parent
2bb901873f
commit
3367b95b91
4 changed files with 34 additions and 3 deletions
|
|
@ -51,13 +51,13 @@ defmodule ProxmoxAgent.Collectors.Host do
|
|||
end
|
||||
|
||||
defp read_loadavg(proc_dir) do
|
||||
body = File.read!(Path.join(proc_dir, "loadavg"))
|
||||
body = read_and_log(Path.join(proc_dir, "loadavg"))
|
||||
[l1, l5, l15 | _] = String.split(body, ~r/\s+/, trim: true)
|
||||
{to_float(l1), to_float(l5), to_float(l15)}
|
||||
end
|
||||
|
||||
defp read_meminfo(proc_dir) do
|
||||
body = File.read!(Path.join(proc_dir, "meminfo"))
|
||||
body = read_and_log(Path.join(proc_dir, "meminfo"))
|
||||
|
||||
parsed =
|
||||
body
|
||||
|
|
@ -76,11 +76,23 @@ defmodule ProxmoxAgent.Collectors.Host do
|
|||
end
|
||||
|
||||
defp read_uptime(proc_dir) do
|
||||
body = File.read!(Path.join(proc_dir, "uptime"))
|
||||
body = read_and_log(Path.join(proc_dir, "uptime"))
|
||||
[secs | _] = String.split(body, " ", trim: true)
|
||||
secs |> to_float() |> trunc()
|
||||
end
|
||||
|
||||
defp read_and_log(path) do
|
||||
start = System.monotonic_time(:microsecond)
|
||||
result = File.read(path)
|
||||
duration_us = System.monotonic_time(:microsecond) - start
|
||||
ProxmoxAgent.Diagnostics.log_read(path, result, duration_us)
|
||||
|
||||
case result do
|
||||
{:ok, body} -> body
|
||||
{:error, reason} -> raise File.Error, reason: reason, action: "read file", path: to_string(path)
|
||||
end
|
||||
end
|
||||
|
||||
defp kb_to_bytes(nil), do: nil
|
||||
|
||||
defp kb_to_bytes(str) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue