Skip to main content

System facts

Agents collect system facts automatically. A fact is a typed property of the host that the agent runs on. The agent publishes the facts to a NATS KV bucket. Facts are used in two features: the agent get output, and fact references (@fact.*), which put live system values in job parameters.

What the agent collects​

The agent collects the facts with gohai every 60 seconds: its kernel, hostname, cpu, init, package_mgr, network and virtualization collectors. agent.facts.interval sets this. The agent stores the facts in the agent-facts KV bucket, with a 5-minute TTL.

FactDescriptionExample value
ArchitectureCPU architecture, as uname -m prints itx86_64, arm64
Kernel VersionOS kernel version string6.8.0-51-generic
FQDNFully qualified domain nameweb-01.example.com
CPU CountNumber of logical CPUs8
Service ManagerInit systemsystemd, launchd
Package ManagerSystem package managerapt, brew
InterfacesNetwork interfaces with IPv4, IPv6, MAC and familyRefer to below
Primary InterfaceInterface name of the default routeeth0, en0
RoutesIP routing table entriesRefer to below

Network interfaces​

Each interface entry has:

  • Name: the interface name, for example eth0 or en0
  • IPv4: the IPv4 address, if it has one
  • IPv6: the IPv6 address, if it has one
  • MAC: the hardware address
  • Family: inet, inet6 or dual

The list has only interfaces that are up and that are not loopback interfaces.

Routes​

Each route entry has:

  • Destination: the target network. The default route is 0.0.0.0
  • Gateway: the next-hop address
  • Interface: the name of the outgoing interface
  • Mask: the CIDR mask, for example /24. The default route is /0
  • Metric: the route metric (Linux only)

The list has only IPv4 routes, on Linux and on macOS.

Fact references (@fact.*)​

Fact references put live system values in job parameters. When an agent processes a job, it replaces each @fact.* token in the request data with the value from its cached facts. The CLI and the API send the @fact.* string as it is. The agent resolves it before it runs the operation.

Available references​

ReferenceResolves toExample value
@fact.hostnameThe hostname of the agentweb-01
@fact.archCPU architecturex86_64
@fact.kernelKernel version6.8.0-51-generic
@fact.fqdnFully qualified hostnameweb-01.example.com
@fact.interface.primaryThe default route interfaceeth0
@fact.custom.<key>A custom fact value(user-defined)

Usage examples​

Get the DNS configuration of the primary network interface:

osapi client node dns get \
--interface-name @fact.interface.primary

Print the hostname on the remote host:

osapi client node command exec \
--command echo --args "@fact.hostname"

Use more than one reference in one command:

osapi client node command exec \
--command echo \
--args "@fact.interface.primary on @fact.hostname"

Use fact references with a broadcast target:

osapi client node command exec \
--command ip --args "addr,show,dev,@fact.interface.primary" \
--target _all

How it works​

  1. The CLI sends the @fact.* string in the job request data.
  2. The API server publishes the job to NATS without a change.
  3. The agent receives the job and looks for @fact.* tokens in the request data.
  4. The agent resolves each token from its local cached facts.
  5. The agent gives the resolved data to the provider, which runs the operation.

The agent resolves the references. Thus fact references work with broadcast (_all) and with label targets: each agent puts in its own values. For example, @fact.interface.primary is eth0 on one host and en0 on a different host.

If a fact is not available, the job fails with an error that names the reference that the agent could not resolve. For example, the agent did not collect facts yet, or the fact key does not exist.

Supported contexts​

Fact references work in all string values of an API request that goes to an agent. The agent resolves all @fact.* tokens before it gives the data to the provider. No endpoint needs special code. If a field accepts a string, it accepts a fact reference.

This includes:

  • Single strings: --interface @fact.interface.primary
  • Arrays: --servers "1.1.1.1,@fact.custom.dns_server" resolves the fact and keeps the IP address as it is
  • Nested maps: the agent resolves references in JSON objects at all levels
  • All domains: commands, DNS, sysctl, services, packages and the other domains
# Fact reference in an array field
osapi client node dns update \
--servers 1.1.1.1 --servers @fact.custom.backup_dns \
--interface-name @fact.interface.primary

# Each agent resolves its own facts, so broadcast works:
# web-01 might resolve @fact.interface.primary to "eth0"
# web-02 might resolve it to "ens3"

The agent does not change values that are not strings, for example numbers and booleans.

See the facts​

Use agent get to see all the facts of one agent:

osapi client agent get --hostname web-01

The output has the architecture, kernel, FQDN, CPUs, service manager, package manager, network interfaces and routes. Use --json to get all the structured data.

Configuration​

KeyTypeDefaultEnvironmentDescription
agent.facts.intervalstring60sOSAPI_AGENT_FACTS_INTERVALHow often the agent collects and publishes facts.
nats.facts.bucketstringagent-factsOSAPI_NATS_FACTS_BUCKETKV bucket for agent facts entries.
nats.facts.ttlstring5mOSAPI_NATS_FACTS_TTLTTL for facts entries (Go duration).
nats.facts.storagestringfileOSAPI_NATS_FACTS_STORAGEStorage backend: 'file' or 'memory'.
nats.facts.replicasint1OSAPI_NATS_FACTS_REPLICASNumber of KV replicas.

Refer to Configuration for all the settings.

Platform support​

gohai collects the facts, with one call to these collectors, on each Linux family and on macOS: Fedora, RHEL and Arch get the same facts as Debian. A feature that is not supported on a family still reports skipped.

Factgohai collectorLinux readsmacOS reads
Architecturekerneluname -muname -m
Kernel Versionkerneluname -runame -r
FQDNhostnamehostname -s, then DNShostname -s, then DNS
CPU Countcpu/proc/cpuinfosysctl hw.logicalcpu
Service Managerinitthe init processlaunchd
Package Managerpackage_mgrthe manager of the family on PATHbrew, port
Interfacesnetwork/sys/class/net, ip addrifconfig
Primary Interfacenetworkip routenetstat -rn
Routesnetworkip routenetstat -rn
ContainerizedvirtualizationOhai's container cascadeOhai's cascade

A collector error does not stop the agent. If a collector fails, the agent still publishes the facts that it collected. Thus @fact.interface.primary can be unavailable when route collection fails, but @fact.hostname and @fact.arch still work.