Skip to content

sysinfo

stable

Reads live system information including CPU, memory, disks, networks, processes, and OS details from the host machine.

use plugin sysinfo::{cpu, memory, os, …}
13 functions Systems
/ filter jk navigate Esc clear
Functions (13)
  1. cpu Per-core CPU name, usage, frequency, brand
  2. memory RAM and swap totals, used, and free bytes
  3. os OS name, kernel version, and CPU architecture
  4. disks Mounted disks with space and filesystem info
  5. networks Network interfaces with traffic counters
  6. processes Running processes with PID, CPU, and memory
  7. components Hardware temperature sensors
  8. hostname Machine hostname string
  9. cpu_count Total logical CPU count
  10. physical_core_count Physical (non-hyperthreaded) core count
  11. global_cpu_usage Aggregate CPU usage percentage
  12. uptime System uptime in seconds
  13. boot_time Unix timestamp of last system boot

Overview

sysinfo is a read-only window into the host machine: it samples live CPU, memory, disk, network, process, and OS state at the moment you call it. Every function is a static method on the sysinfo class (imported with use plugin sysinfo::{sysinfo}), so there are no handles to manage and nothing to refresh manually — each call takes a fresh snapshot and returns plain table, string, int, or float values you can read like ordinary data.

The richer queries (cpu, disks, networks, processes, components) return a table of entries keyed by a 1-based index, where each entry is itself a table of fields. The flat queries (os, memory) return a single field table, and the scalar helpers (hostname, cpu_count, uptime, …) return one value directly. Sizes are in bytes, frequencies in MHz, usage and temperature as percentages and Celsius. Use it for dashboards, health checks, diagnostics, or any tool that needs to report on the machine it runs on.

Common patterns

Print a one-line machine summary by combining the OS, CPU, and memory queries:

use plugin sysinfo::{sysinfo}

let os = sysinfo.os()
let gb = 1024 * 1024 * 1024
print("{os["name"]} {os["os_version"]} ({os["cpu_arch"]})")
print("{sysinfo.cpu_count()} logical CPUs, {sysinfo.global_cpu_usage()}% busy")
print("RAM: {sysinfo.memory()["used_memory"] / gb} / {sysinfo.memory()["total_memory"] / gb} GB")

Walk the disks and flag any volume that is running low on free space:

use plugin sysinfo::{sysinfo}

let gb = 1073741824
for _, disk in sysinfo.disks() {
    let free_gb = disk["available_space"] / gb
    if free_gb < 10 {
        print("LOW: {disk["mount_point"]} only {free_gb} GB free")
    }
}

Find the heaviest processes by walking the process snapshot:

use plugin sysinfo::{sysinfo}

let mb = 1024 * 1024
for _, p in sysinfo.processes() {
    if p["memory"] / mb > 500 {
        print("{p["name"]} (pid {p["pid"]}): {p["memory"] / mb} MB, {p["cpu_usage"]}% cpu")
    }
}

Per-core CPU name, usage, frequency, brand

Returns a table where each entry describes one logical CPU core with fields name, usage (percent), frequency (MHz), vendor_id, and brand.

use plugin sysinfo::{sysinfo}

let cores = sysinfo.cpu()
for i, core in cores {
    print("Core {i}: {core["brand"]} @ {core["frequency"]} MHz, usage={core["usage"]}%")
}

Report just the vendor and model of the first core:

use plugin sysinfo::{sysinfo}

let first = sysinfo.cpu()[1]
print("{first["vendor_id"]} — {first["brand"]}")

RAM and swap totals, used, and free bytes

Returns memory statistics in bytes: total_memory, used_memory, free_memory, available_memory, total_swap, used_swap.

use plugin sysinfo::{sysinfo}

let mem = sysinfo.memory()
let gb = 1024 * 1024 * 1024
print("RAM: {mem["used_memory"] / gb} / {mem["total_memory"] / gb} GB")

Compute a free-memory percentage and check swap pressure:

use plugin sysinfo::{sysinfo}

let mem = sysinfo.memory()
let pct_free = mem["available_memory"] * 100 / mem["total_memory"]
print("{pct_free}% memory available, {mem["used_swap"]} bytes of swap in use")

OS name, kernel version, and CPU architecture

Returns OS information: name, kernel_version, os_version, long_os_version, host_name, cpu_arch.

use plugin sysinfo::{sysinfo}

let info = sysinfo.os()
print("{info["name"]} {info["os_version"]} ({info["cpu_arch"]})")

Mounted disks with space and filesystem info

Returns a table of mounted disks. Each entry has name, mount_point, total_space, available_space, file_system, and is_removable.

use plugin sysinfo::{sysinfo}

let disks = sysinfo.disks()
for _, disk in disks {
    let gb = 1073741824
    print("{disk["mount_point"]}: {disk["available_space"] / gb} GB free")
}

Network interfaces with traffic counters

Returns a table of network interfaces. Each entry has name, received, transmitted, total_received, total_transmitted, packets_received, and packets_transmitted (all in bytes/packets since last refresh).

use plugin sysinfo::{sysinfo}

let nets = sysinfo.networks()
for _, iface in nets {
    print("{iface["name"]}: rx={iface["total_received"]} tx={iface["total_transmitted"]}")
}

Sum total traffic across every interface in megabytes:

use plugin sysinfo::{sysinfo}

let mb = 1024 * 1024
let rx = 0
let tx = 0
for _, iface in sysinfo.networks() {
    rx = rx + iface["total_received"]
    tx = tx + iface["total_transmitted"]
}
print("total rx={rx / mb} MB, tx={tx / mb} MB")

Running processes with PID, CPU, and memory

Returns a snapshot of running processes. Each entry has pid, name, cpu_usage (percent), memory (bytes), and status.

use plugin sysinfo::{sysinfo}

let procs = sysinfo.processes()
for _, p in procs {
    if p["cpu_usage"] > 10.0 {
        print("{p["name"]} (pid {p["pid"]}): {p["cpu_usage"]}% cpu")
    }
}

Hardware temperature sensors

Returns hardware temperature sensors. Each entry has label, temperature (Celsius), and max (Celsius).

use plugin sysinfo::{sysinfo}

let sensors = sysinfo.components()
for _, c in sensors {
    print("{c["label"]}: {c["temperature"]}°C (max {c["max"]}°C)")
}

Machine hostname string

Returns the machine's hostname as a string.

use plugin sysinfo::{sysinfo}

print(sysinfo.hostname())

Total logical CPU count

Returns the total number of logical CPUs (includes hyperthreading).

use plugin sysinfo::{sysinfo}

print("logical CPUs: {sysinfo.cpu_count()}")

Physical (non-hyperthreaded) core count

Returns the number of physical CPU cores (excludes hyperthreading). Returns 0 if not detectable.

use plugin sysinfo::{sysinfo}

print("physical cores: {sysinfo.physical_core_count()}")

Aggregate CPU usage percentage

Returns the aggregate CPU usage across all cores as a percentage (0.0–100.0).

use plugin sysinfo::{sysinfo}

let usage = sysinfo.global_cpu_usage()
print("CPU: {usage}%")

System uptime in seconds

Returns system uptime in seconds since the last boot.

use plugin sysinfo::{sysinfo}

let secs = sysinfo.uptime()
print("up {secs / 3600} hours")

Break the uptime down into days, hours, and minutes:

use plugin sysinfo::{sysinfo}

let secs = sysinfo.uptime()
let days = secs / 86400
let hours = (secs % 86400) / 3600
let mins = (secs % 3600) / 60
print("up {days}d {hours}h {mins}m")

Unix timestamp of last system boot

Returns the Unix timestamp (seconds since epoch) when the system was last booted.

use plugin sysinfo::{sysinfo}

print("booted at unix time: {sysinfo.boot_time()}")
enespt-br