pyfsr.cli.appliance.host

pyfsr appliance host — OS-level resource metrics (mem / swap / load / RSS / disk).

Typed wrappers over free / ps / /proc/loadavg / df so callers get structured values instead of awk-ing command output. None of these need sudo.

The headline call is snapshot(), which gathers mem, swap, load, per-pattern process RSS, and (optionally) disk in one SSH round-trip and returns a typed HostSnapshot — the parsing every troubleshooting script otherwise re-implements lives here, tested once.

Attributes

Classes

MemInfo

Memory + swap, in MB (parsed from free -m).

LoadAvg

1/5/15-minute load averages (from /proc/loadavg).

ProcRss

Aggregate resident memory for processes whose command line matches pattern.

DiskUsage

Filesystem usage for a path, in MB (from df -Pm).

HostSnapshot

One consistent sample of host resources (see snapshot()).

Functions

meminfo(→ MemInfo)

Memory + swap usage in MB.

loadavg(→ LoadAvg)

1/5/15-minute load averages.

process_rss(→ ProcRss)

Summed/peak RSS (MB) and count for processes whose command line matches pattern.

disk(→ DiskUsage)

Filesystem usage (MB) for path.

snapshot(→ HostSnapshot)

One consistent sample of mem, swap, load, per-pattern process RSS, and disk.

Module Contents

pyfsr.cli.appliance.host.DEFAULT_PROC_PATTERNS: dict[str, str][source]
class pyfsr.cli.appliance.host.MemInfo[source]

Memory + swap, in MB (parsed from free -m).

total_mb: int[source]
used_mb: int[source]
free_mb: int[source]
swap_total_mb: int[source]
swap_used_mb: int[source]
class pyfsr.cli.appliance.host.LoadAvg[source]

1/5/15-minute load averages (from /proc/loadavg).

load1: float[source]
load5: float[source]
load15: float[source]
class pyfsr.cli.appliance.host.ProcRss[source]

Aggregate resident memory for processes whose command line matches pattern.

pattern: str[source]
count: int[source]
sum_mb: float[source]
peak_mb: float[source]
class pyfsr.cli.appliance.host.DiskUsage[source]

Filesystem usage for a path, in MB (from df -Pm).

path: str[source]
size_mb: int[source]
used_mb: int[source]
avail_mb: int[source]
use_pct: int[source]
class pyfsr.cli.appliance.host.HostSnapshot[source]

One consistent sample of host resources (see snapshot()).

mem: MemInfo[source]
load: LoadAvg[source]
procs: dict[str, ProcRss][source]
disk: DiskUsage | None = None[source]
summary() str[source]

A compact one-line human summary (the fmt() every script hand-rolls).

pyfsr.cli.appliance.host.meminfo(transport: pyfsr.cli.appliance.transport.Transport) MemInfo[source]

Memory + swap usage in MB.

Raises TransportError if the command produced no usable output (a real host always reports a non-zero total).

pyfsr.cli.appliance.host.loadavg(transport: pyfsr.cli.appliance.transport.Transport) LoadAvg[source]

1/5/15-minute load averages.

pyfsr.cli.appliance.host.process_rss(transport: pyfsr.cli.appliance.transport.Transport, pattern: str) ProcRss[source]

Summed/peak RSS (MB) and count for processes whose command line matches pattern.

pattern is a Python regex matched against each process’s full argv (e.g. r"celery\b.*worker"). Far less brittle than the ps | awk '/[c]elery/' one-liners scripts copy around.

pyfsr.cli.appliance.host.disk(transport: pyfsr.cli.appliance.transport.Transport, path: str = '/opt/cyops') DiskUsage[source]

Filesystem usage (MB) for path.

pyfsr.cli.appliance.host.snapshot(transport: pyfsr.cli.appliance.transport.Transport, *, procs: dict[str, str] | None = None, disk_path: str | None = None) HostSnapshot[source]

One consistent sample of mem, swap, load, per-pattern process RSS, and disk.

Gathers everything in a single SSH round-trip (so the numbers are coherent) and returns a typed HostSnapshot. procs maps a label → regex (defaults to DEFAULT_PROC_PATTERNS: celeryd and integrations); pass disk_path to include a filesystem.