Resource Metrics
Resource Metrics
The built-in resource_metrics plugin collects central processing unit (CPU),
memory, process, disk, network, and graphics processing unit (GPU) data. It can
collect on a timer and emit metric marks. A mark is an event that subscribers
can record. Your program can also call collect() for a fresh snapshot. A
snapshot is a set of readings taken at one time.
The plugin is configured through the standard plugin host. Use the same
resource_metrics component in plugins.toml or in a plugin configuration
object. For setup and activation details, refer to
Initialize.
Enable the Component
This example enables every category and starts polling every 5 seconds:
Replace / with an absolute path on your system, or use [] when you do not
need filesystem capacity data. The example uses the default values for most
fields; showing them makes each option clear.
The component and polling have separate switches:
components[].enabledactivates the plugin.components.config.polling.enabledstarts or stops periodic collection.components.config.polling.interval_millissets the delay between polls.
Polling is disabled by default. Its default interval is 5,000 milliseconds.
The interval must be greater than zero even when polling is disabled. Each
category is enabled by default. A disabled category is null in the snapshot.
For a ready collection target, the first poll starts when the component
activates. Later polls wait for the configured interval.
Each poll reads current values and running totals. Some values, such as total system memory, can stay the same across many polls. Relay still includes them so each snapshot stands on its own. Relay also checks for devices and processes on each poll. Global scope can query many processes, so collection can take longer. Increase the interval or turn off process input/output (I/O) and GPU process metrics if you do not need them.
Relay keeps the Linux process clock rate and its NVIDIA Management Library (NVML) connection between polls. If NVML is unavailable, Relay tries to find it again after one minute. Relay checks capacity, limits, and device lists on each poll so it can detect changes.
On macOS, GPU sampling runs the system ioreg utility to read driver
diagnostics. Disable the GPU category or its process group if you do not need
those readings.
You can activate the component with polling disabled and call the on-demand collection API. On-demand collection does not require polling to be enabled.
Configuration Fields
All fields use snake_case in plugin configuration. Missing fields use the
defaults below. Unknown fields and invalid values are rejected during
validation.
Measurement Scope
measurement_scope defaults to runtime_default. A scope is the process or
system resources included in a reading. This setting chooses that scope.
The default depends on where the plugin runs. The CLI uses global to measure
system resources visible to Relay. Embedded Rust, Python, and Node.js APIs use
process_tree, rooted at the current process ID.
Set global, application_process, or process_tree to choose a scope. When
you choose process_tree, the CLI measures its launched agent and children.
Embedded APIs measure the tree rooted at their current process.
Polling
These fields control when the plugin collects a snapshot:
Categories
These fields control which measurements each snapshot includes:
Every path in filesystem_paths must be absolute and non-empty. GPU selectors
and network interface names must not be blank. A device index is matched as a
decimal string, such as "0"; not every backend provides an index. Device
identifiers come from the GPU backend and can differ between systems.
Linux AMD and Intel Direct Rendering Manager (DRM) devices do not report an index through this collector. Select them by identifier. macOS registry identifiers can change after a restart. Read a current snapshot before you set a fixed selector.
Turning off disk.enabled disables both disk subgroups. Turning off
process_io keeps filesystem capacity data active. Turning off either GPU
measurement group does not turn off the other group. Network readings are
system-wide in every collection mode. They do not measure an agent process.
Snapshot Shape
Refer to Snapshot Shape.
CPU Category
Refer to CPU Category.
Memory Category
Refer to Memory Category.
Process Category
Refer to Process Category.
Disk Category
Refer to Disk Category.
Network Category
Refer to Network Category.
GPU Category
Refer to GPU Category.
Configure Units
Every available measurement contains a value and a unit. Relay collects in
consistent base units, then applies your chosen output units. Missing unit
settings keep the defaults. Unit names use snake_case in every API.
For typed unit APIs, conversions, and numeric representation, refer to Configure Units.
This example sets different units for individual measurements:
The following table lists the allowed units for each measurement family:
A unit choice for one field applies to every record of that kind, such as every filesystem or GPU device. System and interface network readings have separate choices. Counts, including packets, errors, processes, and disk operations, keep their named units.
If you change a unit after an OpenTelemetry metrics exporter has received that metric, restart the exporter before collecting again. The exporter keeps the first unit registered for each metric name.
Platform and Collection-Mode Compatibility
Refer to Platform and Collection-Mode Compatibility.
GPU Vendor Support in Every Collection Mode
Refer to GPU Vendor Support in Every Collection Mode.
Limits That Apply to Every Mode
Refer to Limits That Apply to Every Mode.
Polling Marks and Scope Behavior
When the component and polling are enabled, each poll collects one snapshot and
emits a nemo.relay.resource_metrics mark. The CLI pauses process-tree polls
until it has a launched process to measure. The mark uses Relay’s reserved
nemo.relay.metric_measurements schema. An enabled Agent Trajectory
Observability Format (ATOF) subscriber writes the mark through the usual event
path. An enabled OpenTelemetry metrics pipeline exports available measurements
as metrics. Refer to
ATOF
and OpenTelemetry for exporter
configuration.
Each mark includes nemo.relay.resource.sample_count with value 1 and unit
events. This records the poll even when the selected categories have no
available measurements on the host.
The same selected-scope sample is copied under each active explicit Agent
scope. A custom scope does not receive a copy. If there are no active Agent
scopes, Relay emits one mark under the runtime root. Copies have the same
measurements and timestamp. They help each trace see the sample; they do not
represent separate per-agent resource use and must not be added together.
Agent scope start and end events only update the list of active scopes. They do not trigger an extra sample. Each copy goes through the target scope’s subscriber and sanitizer settings.
The CLI uses global scope by default. Embedded applications use the process tree
rooted at the current process ID by default. This can include child processes
that the host application started for other work. In the CLI, explicitly
selecting process_tree measures the launched agent process and its active
descendants. The runtime chooses the process ID; plugin configuration does not.
Collect One Snapshot
Activate the resource_metrics component before collecting. Polling can stay
disabled, and on-demand collection does not emit a polling mark. Await the
result; the first sample has no consumption_rate. Rust requires a Tokio
runtime, and Python requires an active async event loop.
After a Unix fork, start a new executable and activate the component there.
Cancelling the wait does not stop an in-flight query or its baseline update.
For the full execution and return-value contract, refer to
Collect One Snapshot.
Each example activates the plugin, collects one snapshot, and closes the activation. Polling stays disabled by default. Choose your language:
Rust
Python
Node.js
Add these dependencies to your project’s Cargo.toml:
Save the following code as src/main.rs, then run cargo run:
Expected outcome: Collection returns a snapshot with a collection timestamp
and category fields. Measurements vary by operating system, permissions, and
available drivers. Unavailable measurements remain unavailable (None in
Python, null in Node.js, and None in Rust). The first CPU consumption-rate
reading is unavailable.
For binding-specific timestamps and large integer values, refer to Collect One Snapshot.
For plugin configuration files, precedence, and CLI editing, refer to Configure.
Diagnostic Memory Context
Successful resource collections can retain one memory-only sample for
diagnostic memory inspection.
In the existing component configuration, set memory_inspection.enabled
(default true) and memory_inspection.stale_after_millis (default 30000, which
must be positive). This policy does not enable the component,
polling, or diagnostic collection. Reading the sample does not schedule collection
or reload configuration. Disabling the memory category also disables this sample.
For example, extend an existing resource component definition:
The sample preserves target and sample identity, process coverage, units, and numeric precision. Runtime or target changes invalidate it. Storage supports a fixed set of memory fields and eight limit-event slots. If metadata exceeds those limits, the status reports unavailable capacity and keeps a valid older sample.
Diagnostic pages and restricted component identities never enter resource marks or exporter events. The existing resource API and its serialization stay the same.