Health
c.Health calls the API's Health group. Health check endpoints for liveness,
readiness, and detailed status.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
Liveness(ctx) | *Response[HealthResponse] | Liveness probe. | |
Ready(ctx) | *Response[ReadyResponse] | Readiness probe. | |
Status(ctx, params) | *Response[StatusResponse] | health:read | System status and component health. |
Liveness
func (s *HealthService) Liveness(
ctx context.Context,
) (*Response[HealthResponse], error)
Liveness probe.
Returns 200 if the process is alive. No checks performed.
It sends GET /api/health, and needs no permission.
The examples of the method's definition:
Liveness probe, go run health.go liveness:
resp, err := c.Health.Liveness(ctx)
Ready
func (s *HealthService) Ready(
ctx context.Context,
) (*Response[ReadyResponse], error)
Readiness probe.
Returns 200 when the service is ready to accept traffic.
It sends GET /api/health/ready, and needs no permission.
The examples of the method's definition:
Readiness probe, go run health.go ready:
resp, err := c.Health.Ready(ctx)
Status
func (s *HealthService) Status(
ctx context.Context,
params HealthStatusParams,
) (*Response[StatusResponse], error)
System status and component health.
Returns per-component health status with system metrics. Requires authentication.
It sends GET /api/health/status, and needs the permission health:read.
The examples of the method's definition:
System status and component health, go run health.go status:
resp, err := c.Health.Status(ctx, client.HealthStatusParams{})
System status and component health, with --component agent,
go run health.go status-2:
resp, err := c.Health.Status(ctx, client.HealthStatusParams{Component: types.ComponentType("agent")})
Types
The fields of each type are the properties of its schema in the API's spec.
AgentDetail
| Field | Type | Description |
|---|---|---|
Hostname | string | Agent hostname. |
Labels | string | Formatted label string. |
Registered | string | Time since last heartbeat registration. |
AgentStats
| Field | Type | Description |
|---|---|---|
Agents | []AgentDetail | Per-agent registration details. |
Ready | int | Number of agents with Ready status. |
Total | int | Total number of registered agents. |
Check
| Field | Type | Description |
|---|---|---|
Error | string | Why the check failed. Absent when it is ok. |
Name | string | What was checked, such as nats. |
Status | string | ok, or error. |
ComponentEntry
| Field | Type | Description |
|---|---|---|
Address | string | Listen address of a sub-component, such as :8080. |
Age | string | Time since component started. |
Components | []ComponentEntry | The sub-components of the component, such as its api and its metrics server, sorted by name. |
Conditions | []ConditionType | Active conditions. |
CPUPercent | float64 | Process CPU usage percentage. |
Hostname | string | Component hostname. |
MemBytes | int64 | Process RSS memory in bytes. |
Status | string | Component status. |
Type | string | Component type (agent, controller, nats), or the name of a sub-component, such as api. |
URL | string | Where a person opens a sub-component, from its url config key. |
Version | string | Build version of the component's binary. |
ComponentType
ComponentType is the type of a part of osapi that reports its health.
A string, one of controller, nats, agent.
ConditionType
A condition that an agent or a component evaluates.
A string, one of MemoryPressure, HighLoad, DiskPressure, DrainStuck,
ConsumersUnavailable, ProcessMemoryPressure, ProcessHighCPU.
HealthResponse
| Field | Type | Description |
|---|---|---|
Status | string | Health status. |
JobStats
| Field | Type | Description |
|---|---|---|
Completed | int | Number of completed jobs. |
DLQ | int | Number of jobs in the dead letter queue. |
Failed | int | Number of failed jobs. |
Processing | int | Number of jobs currently processing. |
Submitted | int | Number of jobs that no agent has taken. |
Total | int | Total number of jobs. |
KVBucketInfo
| Field | Type | Description |
|---|---|---|
Bytes | int | Total bytes in the bucket. |
Keys | int | Number of keys in the bucket. |
Name | string | KV bucket name. |
NATSInfo
| Field | Type | Description |
|---|---|---|
URL | string | Connected NATS server URL. |
Version | string | NATS server version. |
ObjectStoreInfo
| Field | Type | Description |
|---|---|---|
Name | string | Object Store bucket name. |
Size | int | Total bytes in the store. |
ReadyResponse
| Field | Type | Description |
|---|---|---|
Error | string | Error message when not ready. |
Status | string | Readiness status. |
StatusResponse
| Field | Type | Description |
|---|---|---|
Agents | AgentStats | |
Checks | []Check | What the controller that answered checked for this answer: its connection to NATS and to the KV store. |
Consumers | int | Total number of JetStream consumers: the sum of the consumers of each stream. |
Jobs | JobStats | |
KVBuckets | []KVBucketInfo | KV bucket statistics. |
NATS | NATSInfo | |
ObjectStores | []ObjectStoreInfo | Object Store statistics. |
Registry | []ComponentEntry | All registered components with health details, each with its sub-components. |
Status | string | Overall health status. |
Streams | []StreamInfo | JetStream stream statistics. |
Uptime | string | Time since server started. |
Version | string | Application version. |
StreamInfo
| Field | Type | Description |
|---|---|---|
Bytes | int | Total bytes in the stream. |
Consumers | int | Number of consumers on the stream. |
Messages | int | Number of messages in the stream. |
Name | string | Stream name. |
Example
examples/sdk/client/health.go
runs each example of this page. With no argument, it lists them.