memory

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package memory is the memory behavior: the memory of the host, in bytes.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"memory", "Get the memory usage of target hosts",
	behavior.Node,
	behavior.API,
	behavior.Area(area.Hardware),
	behavior.CLI,
	behavior.Platform(behavior.PlatformLinux, newReader),
	behavior.Platform(behavior.PlatformDarwin, newReader),

	behavior.RunsOnPlatform(behavior.PlatformDarwin, "sysctl", "vm_stat"),
	behavior.Read("get", Get).
		Describe("Get the memory usage of the host").
		Explain("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.").
		Example("A host with 8 GiB, 2 GiB of it free", GetInput{},
			Entry{Memory: Usage{Total: 8589934592, Free: 2147483648, Used: 4294967296}},
			behavior.Exists(
				"/proc/meminfo",
				"MemTotal:        8388608 kB\nMemFree:         2097152 kB\nMemAvailable:    4194304 kB\n",
			),
			behavior.Prints("sysctl -n hw.memsize", "8589934592\n"),
			behavior.Prints("vm_stat", "Mach Virtual Memory Statistics: (page size of 4096 bytes)\n"+
				"Pages free:                              524288.\n"+
				"Pages active:                            786432.\n"+
				"Pages inactive:                          524288.\n"),
		),
))

Behavior is the memory definition.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Memory Usage `json:"memory" doc:"The memory of the host"`
}

Entry is the host's memory.

func Get

func Get(
	ctx context.Context,
	p Provider,
	_ GetInput,
) (Entry, error)

Get is the host's memory.

type GetInput

type GetInput struct{}

GetInput is get's input, which has none.

type Provider

type Provider interface {
	Memory(ctx context.Context) (Usage, error)
}

Provider is what each platform implements: the host's memory.

type Usage

type Usage struct {
	Total int `json:"total" doc:"Total memory in bytes"                                  render:"bytes"`
	Free  int `json:"free"  doc:"Free memory in bytes"                                   render:"bytes"`
	Used  int `json:"used"  doc:"Used memory in bytes: the total less what is available" render:"bytes"`
}

Usage is the total, free and used memory, in bytes.

Directories

Path Synopsis
Package mocks holds the generated double of the memory provider, for the methods' tests.
Package mocks holds the generated double of the memory provider, for the methods' tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL