Skip to main content

Agent

c.Agent calls the API's Agent group. Operations related to agent discovery and details.

Methods​

MethodReturnsPermissionDescription
List(ctx)*Response[ListAgentsResponse]agent:readList active agents.
Getconfig(ctx, hostname)*Response[AgentConfigResponse]agent:readRead the config of an agent.
Setconfig(ctx, hostname, input)*Response[AgentConfigResponse]agent:writeSet the config of an agent.
Facts(ctx)*Response[FactKeysResponse]agent:readList the fact keys.
Join(ctx, input)*Response[JoinResponse]Join an agent with a join token.
Get(ctx, hostname)*Response[AgentInfo]agent:readGet agent details.
Drain(ctx, hostname)erroragent:writeDrain an agent.
Undrain(ctx, hostname)erroragent:writeUndrain 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.: the built-in keys and the custom keys that agents register.

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​

FieldTypeDescription
Labelsmap[string]stringThe labels that the controller gives the agent.
UpdatedAttime.TimeWhen the config last changed.
VersionintOne more at each change; 0 when nothing was set.

AgentInfo​

FieldTypeDescription
ArchitecturestringCPU architecture.
Conditions[]NodeConditionThe conditions that hold now, such as HighLoad. A condition that does not hold is not in the list.
ConfigBehindboolThe 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.
ConfigVersionintThe version of the controller's config of the agent that the agent applied. Absent when it applied none.
ConfigWantedintThe version of the config that the controller holds for the agent. Absent when it holds none.
CPUCountintNumber of logical CPUs.
Factsmap[string]anyExtended facts from additional providers.
FingerprintstringThe SHA256 fingerprint of the agent's PKI public key. Empty until the agent loads its keys.
FQDNstringFully qualified domain name.
HostnamestringThe hostname of the agent.
Interfaces[]NetworkInterfaceResponse
KernelVersionstringOS kernel version.
KeyStoredboolWhether 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.
Labelsmap[string]stringKey-value labels configured on the agent.
LoadAverageLoadAverageResponseThe system load averages for 1, 5, and 15 minutes.
MachineIDstringThe permanent machine identifier.
MemoryMemoryResponseMemory usage information.
MissingPrograms[]stringThe programs that the agent's behaviors declare and that the host lacks. A behavior fails until its program is installed.
OSInfoOSInfoResponseOperating system information.
PackageMgrstringPackage manager.
PrimaryInterfacestringName of the interface used for the default route.
RegisteredAttime.TimeWhen the agent last refreshed its heartbeat.
Routes[]RouteResponseNetwork routing table entries.
ServiceMgrstringInit system.
StartedAttime.TimeWhen the agent process started.
StateAgentStateThe scheduling state of an agent: Ready, Draining, Cordoned or Pending. A drain that the agent has not applied yet is Draining.
Timeline[]TimelineEventAgent state transition history.
UptimestringThe system uptime.
VerifiedboolWhether 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.
VersionstringThe build version of the agent binary. Absent for an agent that does not report it.

AgentJoinInput​

FieldTypeDescription
EncryptionKeystringThe agent's X25519 encryption key, in the nkeys form.
HostnamestringThe hostname of the host.
MachineIDstringThe machine ID of the host.
PublicKeystringThe agent's Ed25519 signing key, in base64.
SignaturestringThe signature of the request by the signing key, in base64.
TokenstringThe join token, osapi_jt_., from osapi controller join token create. A secret: a reference, secret:///, or the value.

AgentSetconfigInput​

FieldTypeDescription
Labelsmap[string]stringThe 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​

FieldTypeDescription
BuiltinboolWhether this is a built-in fact key.
DescriptionstringHuman-readable description of the fact.
KeystringThe fact key, such as 'interface.primary'.

FactKeysResponse​

FieldTypeDescription
Items[]FactKeyEntryAvailable fact keys for @fact. references.
TotalItemsintTotal number of fact keys.

JoinResponse​

FieldTypeDescription
ControllerPublicKeystringThe controller's Ed25519 public key, in base64, which the agent keeps and checks each job with.

ListAgentsResponse​

FieldTypeDescription
Items[]AgentInfoThe active agents.
TotalItemsintTotal number of active agents.

LoadAverageResponse​

The system load averages for 1, 5, and 15 minutes.

FieldTypeDescription
Min15float64Load average for the last 15 minutes.
Min1float64Load average for the last 1 minute.
Min5float64Load average for the last 5 minutes.

MemoryResponse​

Memory usage information.

FieldTypeDescription
FreeintFree memory in bytes.
TotalintTotal memory in bytes.
UsedintUsed memory in bytes.

NetworkInterfaceResponse​

FieldTypeDescription
FamilyAddressFamilyAddressFamily is the IP address family of an interface.
IPv4string
IPv6string
MACstring
Namestring

NodeCondition​

FieldTypeDescription
LastTransitionTimetime.Time
Reasonstring
TypeConditionTypeA condition that an agent or a component evaluates.

OSInfoResponse​

Operating system information.

FieldTypeDescription
DistributionstringThe name of the Linux distribution.
FamilystringThe 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.
VersionstringThe version of the Linux distribution.

RouteResponse​

A network routing table entry.

FieldTypeDescription
DestinationstringDestination network address.
GatewaystringGateway address.
InterfacestringNetwork interface name.
MaskstringNetwork mask in CIDR notation.
MetricintRoute metric.

TimelineEvent​

FieldTypeDescription
Errorstring
Eventstring
Hostnamestring
Messagestring
Timestamptime.Time

Example​

examples/sdk/client/agent.go runs each example of this page. With no argument, it lists them.