Skip to main content

Memory

c.Memory calls the API's Memory group. Get the memory usage of target hosts.

Methods​

MethodReturnsPermissionDescription
Get(ctx, hostname)*Response[Collection[MemoryEntry]]memory:readGet the memory usage of the host.

Get​

func (s *MemoryService) Get(
ctx context.Context,
hostname string,
) (*Response[Collection[MemoryEntry]], error)

Get the memory usage of the host.

Reads the total, the free and the used memory, in bytes. Used is the total less what is available, which includes the cache, as free(1) reports it.

It sends GET /api/node/{hostname}/memory, and needs the permission memory:read.

The examples of the method's definition:

A host with 8 GiB, 2 GiB of it free, go run memory.go get:

resp, err := c.Memory.Get(ctx, target)

Types​

The fields of each type are the properties of its schema in the API's spec.

MemoryEntry​

FieldTypeDescription
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
MemoryUsage
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

RowStatus​

What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

A string, one of ok, failed, skipped, timeout.

Usage​

FieldTypeDescription
FreeintFree memory in bytes.
TotalintTotal memory in bytes.
UsedintUsed memory in bytes: the total less what is available.

Example​

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