Agent
c.Agent calls the API's Agent group. Operations related to agent discovery and
details.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx) | *Response[ListAgentsResponse] | agent:read | List active agents. |
Getconfig(ctx, hostname) | *Response[AgentConfigResponse] | agent:read | Read the config of an agent. |
Setconfig(ctx, hostname, input) | *Response[AgentConfigResponse] | agent:write | Set the config of an agent. |
Facts(ctx) | *Response[FactKeysResponse] | agent:read | List the fact keys. |
Join(ctx, input) | *Response[JoinResponse] | Join an agent with a join token. | |
Get(ctx, hostname) | *Response[AgentInfo] | agent:read | Get agent details. |
Drain(ctx, hostname) | error | agent:write | Drain an agent. |
Undrain(ctx, hostname) | error | agent:write | Undrain an agent. |
List
func (s *AgentService) List(
ctx context.Context,
) (*Response[ListAgentsResponse], error)
List active agents.
Discover all active agents in the fleet.
It sends GET /api/agent, and needs the permission agent:read.
The examples of the method's definition:
List active agents, go run agent.go list:
resp, err := c.Agent.List(ctx)
Getconfig
func (s *AgentService) Getconfig(
ctx context.Context,
hostname string,
) (*Response[AgentConfigResponse], error)
Read the config of an agent.
Returns the config that the controller holds for the agent, with its version.
It sends GET /api/agent/config/{hostname}, and needs the permission
agent:read.
The examples of the method's definition:
Read the config of an agent, go run agent.go getconfig:
resp, err := c.Agent.Getconfig(ctx, "web-01")
Setconfig
func (s *AgentService) Setconfig(
ctx context.Context,
hostname string,
input AgentSetconfigInput,
) (*Response[AgentConfigResponse], error)
Set the config of an agent.
Sets the labels of the agent as the next version of its config. The agent applies them at once: it takes the jobs of the new labels, and no restart is necessary.
It sends PUT /api/agent/config/{hostname}, and needs the permission
agent:write.
The examples of the method's definition:
Set the config of an agent, go run agent.go setconfig:
resp, err := c.Agent.Setconfig(ctx, "web-01", client.AgentSetconfigInput{Labels: map[string]string{
"dc": "east",
"group": "web",
}})
Facts
func (s *AgentService) Facts(
ctx context.Context,
) (*Response[FactKeysResponse], error)
List the fact keys.
Returns the fact keys that an input can refer to as @fact.
It sends GET /api/agent/facts, and needs the permission agent:read.
The examples of the method's definition:
List the fact keys, go run agent.go facts:
resp, err := c.Agent.Facts(ctx)
Join
func (s *AgentService) Join(
ctx context.Context,
input AgentJoinInput,
) (*Response[JoinResponse], error)
Join an agent with a join token.
An agent calls it one time, at its first start, over HTTPS, after it checks the controller's certificate against the fingerprint of its join string. A token that admits admits the machine at once, as admit does, and the admission record names the token. The request is signed with the agent's signing key, which shows that it holds the key that it asks the controller to admit. It needs no bearer token: the join token authorizes it.
It sends POST /api/agent/join, and needs no permission.
Get
func (s *AgentService) Get(
ctx context.Context,
hostname string,
) (*Response[AgentInfo], error)
Get agent details.
Get detailed information about a specific agent by hostname.
It sends GET /api/agent/{hostname}, and needs the permission agent:read.
The examples of the method's definition:
Get agent details, go run agent.go get:
resp, err := c.Agent.Get(ctx, "web-01")
Drain
func (s *AgentService) Drain(
ctx context.Context,
hostname string,
) error
Drain an agent.
Stop the agent from accepting new jobs. In-flight jobs continue to completion.
It sends POST /api/agent/{hostname}/drain, and needs the permission
agent:write.
The examples of the method's definition:
Drain an agent, go run agent.go drain:
err := c.Agent.Drain(ctx, "web-01")
Undrain
func (s *AgentService) Undrain(
ctx context.Context,
hostname string,
) error
Undrain an agent.
Resume accepting jobs on a drained agent.
It sends POST /api/agent/{hostname}/undrain, and needs the permission
agent:write.
The examples of the method's definition:
Undrain an agent, go run agent.go undrain:
err := c.Agent.Undrain(ctx, "web-01")
Types
The fields of each type are the properties of its schema in the API's spec.
AddressFamily
AddressFamily is the IP address family of an interface.
A string, one of inet, inet6, dual.
AgentConfigResponse
| Field | Type | Description |
|---|---|---|
Labels | map[string]string | The labels that the controller gives the agent. |
UpdatedAt | time.Time | When the config last changed. |
Version | int | One more at each change; 0 when nothing was set. |
AgentInfo
| Field | Type | Description |
|---|---|---|
Architecture | string | CPU architecture. |
Conditions | []NodeCondition | The conditions that hold now, such as HighLoad. A condition that does not hold is not in the list. |
ConfigBehind | bool | The agent has not applied the newest config that the controller holds for it yet: it applies it at its next heartbeat, or it cannot reach the controller's config. |
ConfigVersion | int | The version of the controller's config of the agent that the agent applied. Absent when it applied none. |
ConfigWanted | int | The version of the config that the controller holds for the agent. Absent when it holds none. |
CPUCount | int | Number of logical CPUs. |
Facts | map[string]any | Extended facts from additional providers. |
Fingerprint | string | The SHA256 fingerprint of the agent's PKI public key. Empty until the agent loads its keys. |
FQDN | string | Fully qualified domain name. |
Hostname | string | The hostname of the agent. |
Interfaces | []NetworkInterfaceResponse | |
KernelVersion | string | OS kernel version. |
KeyStored | bool | Whether the controller holds this agent's public key, recorded when its enrollment was accepted. False for an agent that has not enrolled since the key store existed, which is what to re-enrol before enabling enforcement. |
Labels | map[string]string | Key-value labels configured on the agent. |
LoadAverage | LoadAverageResponse | The system load averages for 1, 5, and 15 minutes. |
MachineID | string | The permanent machine identifier. |
Memory | MemoryResponse | Memory usage information. |
MissingPrograms | []string | The programs that the agent's behaviors declare and that the host lacks. A behavior fails until its program is installed. |
OSInfo | OSInfoResponse | Operating system information. |
PackageMgr | string | Package manager. |
PrimaryInterface | string | Name of the interface used for the default route. |
RegisteredAt | time.Time | When the agent last refreshed its heartbeat. |
Routes | []RouteResponse | Network routing table entries. |
ServiceMgr | string | Init system. |
StartedAt | time.Time | When the agent process started. |
State | AgentState | The scheduling state of an agent: Ready, Draining, Cordoned or Pending. A drain that the agent has not applied yet is Draining. |
Timeline | []TimelineEvent | Agent state transition history. |
Uptime | string | The system uptime. |
Verified | bool | Whether this agent's registration was signed by its stored key and claims the hostname it enrolled under. Only a verified registration decides where work is routed. True when the controller is not enforcing verification. |
Version | string | The build version of the agent binary. Absent for an agent that does not report it. |
AgentJoinInput
| Field | Type | Description |
|---|---|---|
EncryptionKey | string | The agent's X25519 encryption key, in the nkeys form. |
Hostname | string | The hostname of the host. |
MachineID | string | The machine ID of the host. |
PublicKey | string | The agent's Ed25519 signing key, in base64. |
Signature | string | The signature of the request by the signing key, in base64. |
Token | string | The join token, osapi_jt_ |
AgentSetconfigInput
| Field | Type | Description |
|---|---|---|
Labels | map[string]string | The labels of the agent, as key=value. They replace the labels of the agent's config file with the same keys. Empty removes each. |
AgentState
The scheduling state of an agent: Ready, Draining, Cordoned or Pending. A drain that the agent has not applied yet is Draining.
A string, one of Ready, Draining, Cordoned, Pending.
ConditionType
A condition that an agent or a component evaluates.
A string, one of MemoryPressure, HighLoad, DiskPressure, DrainStuck,
ConsumersUnavailable, ProcessMemoryPressure, ProcessHighCPU.
FactKeyEntry
| Field | Type | Description |
|---|---|---|
Builtin | bool | Whether this is a built-in fact key. |
Description | string | Human-readable description of the fact. |
Key | string | The fact key, such as 'interface.primary'. |
FactKeysResponse
| Field | Type | Description |
|---|---|---|
Items | []FactKeyEntry | Available fact keys for @fact. references. |
TotalItems | int | Total number of fact keys. |
JoinResponse
| Field | Type | Description |
|---|---|---|
ControllerPublicKey | string | The controller's Ed25519 public key, in base64, which the agent keeps and checks each job with. |
ListAgentsResponse
| Field | Type | Description |
|---|---|---|
Items | []AgentInfo | The active agents. |
TotalItems | int | Total number of active agents. |
LoadAverageResponse
The system load averages for 1, 5, and 15 minutes.
| Field | Type | Description |
|---|---|---|
Min15 | float64 | Load average for the last 15 minutes. |
Min1 | float64 | Load average for the last 1 minute. |
Min5 | float64 | Load average for the last 5 minutes. |
MemoryResponse
Memory usage information.
| Field | Type | Description |
|---|---|---|
Free | int | Free memory in bytes. |
Total | int | Total memory in bytes. |
Used | int | Used memory in bytes. |
NetworkInterfaceResponse
| Field | Type | Description |
|---|---|---|
Family | AddressFamily | AddressFamily is the IP address family of an interface. |
IPv4 | string | |
IPv6 | string | |
MAC | string | |
Name | string |
NodeCondition
| Field | Type | Description |
|---|---|---|
LastTransitionTime | time.Time | |
Reason | string | |
Type | ConditionType | A condition that an agent or a component evaluates. |
OSInfoResponse
Operating system information.
| Field | Type | Description |
|---|---|---|
Distribution | string | The name of the Linux distribution. |
Family | string | The platform family that the agent picks providers by, as gohai names it: debian, suse, darwin and so on. A method runs on a host whose family is one of its platforms. |
Version | string | The version of the Linux distribution. |
RouteResponse
A network routing table entry.
| Field | Type | Description |
|---|---|---|
Destination | string | Destination network address. |
Gateway | string | Gateway address. |
Interface | string | Network interface name. |
Mask | string | Network mask in CIDR notation. |
Metric | int | Route metric. |
TimelineEvent
| Field | Type | Description |
|---|---|---|
Error | string | |
Event | string | |
Hostname | string | |
Message | string | |
Timestamp | time.Time |
Example
examples/sdk/client/agent.go
runs each example of this page. With no argument, it lists them.