Memory
c.Memory calls the API's Memory group. Get the memory usage of target hosts.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
Get(ctx, hostname) | *Response[Collection[MemoryEntry]] | memory:read | Get 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
| Field | Type | Description |
|---|---|---|
Error | string | Error message if the agent failed. |
Hostname | string | Hostname of the agent that produced this result. |
Memory | Usage | |
Status | 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. |
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
| Field | Type | Description |
|---|---|---|
Free | int | Free memory in bytes. |
Total | int | Total memory in bytes. |
Used | int | Used 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.