nmbrs_host/lib.rs
1// Copyright 2024-2026 Jonathan Shook
2// SPDX-License-Identifier: Apache-2.0
3
4//! Readings of the host nmbrs runs on (SRD-118 ยง9).
5//!
6//! The session sampler (`sysmon=`) and the `host` adapter both read
7//! the host through this crate, so each subsystem is read and parsed
8//! in one place.
9//!
10//! - [`category`]: the subsystems' names and what each needs of this
11//! host.
12//! - [`cpu`], [`mem`], [`disk`], [`net`], [`pressure`], [`process`],
13//! [`cgroup`]: each subsystem's counters, the parser of its files,
14//! and the arithmetic between two readings.
15//! - [`snapshot`]: one reading of chosen categories, as named measures.
16//! - [`du`]: the disk space a directory takes.
17//!
18//! The parsers take text, so the arithmetic is tested on fixtures;
19//! only the `read_*` functions, the watchers of a process or a control
20//! group, and the directory walk touch the filesystem.
21
22pub mod category;
23pub mod cgroup;
24pub mod cpu;
25pub mod disk;
26pub mod du;
27pub mod mem;
28pub mod net;
29pub mod pressure;
30pub mod process;
31pub mod snapshot;
32
33/// True when `name` can name a watched process or control group: one
34/// or more letters, digits, `_` and `-`. The name becomes a label
35/// value.
36pub(crate) fn is_subject_name(name: &str) -> bool {
37 !name.is_empty()
38 && name
39 .chars()
40 .all(|c| c.is_ascii_alphanumeric() || c == '_' || c == '-')
41}