What the NanoKVM-Go is doing, sampled each second: the share of the CPU in use, the memory in use, the SoC temperature, the traffic of each network interface, the load average and the time since it started. The process keeps the last five minutes for graphs, and sends each sample to its subscribers.
NanoKVMGo.Metrics.current()
#=> %{
#=> cpu: %{total: 12.5, cores: [10.0, 15.0]},
#=> memory: %{used: 251_658_240, total: 510_390_272, percent: 49.3},
#=> temperature: 71.3,
#=> network: %{"wlan0" => %{down: 1200.0, up: 310.5}},
#=> load: [0.08, 0.03, 0.01],
#=> uptime: 33_432
#=> }
:ok = NanoKVMGo.Metrics.subscribe()
receive do
{NanoKVMGo.Metrics, sample} -> sample
endCPU and memory are in percent, the temperature in degrees Celsius (nil
without the sensor), network traffic in bytes per second each way (down
received, up sent, the loopback left out), the uptime in seconds. The
first sample comes a second after the start: the CPU's share is measured
between two readings.
Options
:name- the name to register,NanoKVMGo.Metricsby default:interval- milliseconds between samples, 1000 by default:history- how many samples to keep, 300 by default:root- the root of the file system with procfs and sysfs,"/"by default:clock- a function that gives the time in milliseconds, which the traffic is measured against, the monotonic time by default
Summary
Types
The samples kept, oldest first: CPU and memory in percent, temperatures, and the traffic of each interface. An interface that came later has fewer.
A message to subscribers: each sample.
One sample, see the module documentation.
Functions
Returns a specification to start this module under a supervisor.
The last sample, nil before the first.
The samples kept, oldest first.
Starts the process. See the module documentation for the options.
Sends each sample to the caller, as {NanoKVMGo.Metrics, sample}, until it
unsubscribes or exits.
Stops the samples to the caller.
Types
@type history() :: %{ cpu: [float()], memory: [float()], temperature: [float() | nil], network: %{required(String.t()) => %{down: [float()], up: [float()]}} }
The samples kept, oldest first: CPU and memory in percent, temperatures, and the traffic of each interface. An interface that came later has fewer.
@type message() :: {NanoKVMGo.Metrics, sample()}
A message to subscribers: each sample.
@type option() :: {:name, GenServer.name()} | {:interval, pos_integer()} | {:history, pos_integer()} | {:root, Path.t()} | {:clock, (-> integer())}
@type sample() :: %{ cpu: %{total: float(), cores: [float()]}, memory: %{used: non_neg_integer(), total: non_neg_integer(), percent: float()}, temperature: float() | nil, network: %{required(String.t()) => %{down: float(), up: float()}}, load: [float()], uptime: non_neg_integer() | nil }
One sample, see the module documentation.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec current(GenServer.server()) :: sample() | nil
The last sample, nil before the first.
@spec history(GenServer.server()) :: history()
The samples kept, oldest first.
@spec start_link([option()]) :: GenServer.on_start()
Starts the process. See the module documentation for the options.
@spec subscribe(GenServer.server()) :: :ok
Sends each sample to the caller, as {NanoKVMGo.Metrics, sample}, until it
unsubscribes or exits.
@spec unsubscribe(GenServer.server()) :: :ok
Stops the samples to the caller.