ExmonLib
ExmonLib is an Elixir library that provides functionality to extract system metrics and monitoring data from the host system. It collects information about CPU, RAM, disks, filesystem, and uptime.
Compatible with Linux only.
Installation
The package can be installed by adding exmon_lib to your list of dependencies in mix.exs:
def deps do
[
{:exmon_lib, "~> 0.1.0"}
]
endUsage
Basic Usage
To extract all system metrics at once:
# Get all metrics
metrics = ExmonLib.extract()
# The result is a map with hostname as key
%{
"hostname" => %{
cpu: %{...},
ram: %{...},
disks: %{...},
fs: %{...},
uptime: %{...}
}
}Accessing Specific Metrics
You can access specific metrics from the result:
metrics = ExmonLib.extract()
hostname = Map.keys(metrics) |> List.first()
# Get CPU metrics
cpu_metrics = metrics[hostname][:cpu]
cpu_usage_percent = cpu_metrics[:percent]
# Get RAM metrics
ram_metrics = metrics[hostname][:ram]
free_memory = ram_metrics[:free]
total_memory = ram_metrics[:total]
# Get disk metrics
disk_metrics = metrics[hostname][:disks]
# Get filesystem metrics
fs_metrics = metrics[hostname][:fs]
# Get uptime information
uptime_metrics = metrics[hostname][:uptime]Available Metrics
CPU Metrics
The CPU metrics include:
percent: CPU usage percentageuser,nice,system,idle,iowait,irq,softirq,steal: Raw CPU countersload_1,load_5,load_15: System load averages for 1, 5, and 15 minutes
RAM Metrics
Memory usage information including:
total: Total memoryfree: Free memoryused: Used memorybuffers,cached: Memory used for buffers and cache
Disk Metrics
Physical disk statistics for each disk in the system.
Filesystem Metrics
Filesystem usage data for each mounted filesystem.
Uptime Metrics
System uptime information.
Requirements
- Elixir ~> 1.18
-
Linux-based operating system (metrics are collected from
/procfilesystem)
Documentation
Documentation can be generated with ExDoc.
TODO
- [ ] Tests
- [ ] Network stats
- [ ] Error handling
- [ ] Code cleaning