disk

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 disk is the disk behavior: the usage of the host's local filesystems.

Index

Constants

This section is empty.

Variables

View Source
var Behavior = behavior.Register(behavior.Define(
	"disk", "Get the disk 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.Runs("df"),
	behavior.RunsOnPlatform(behavior.PlatformLinux, "lsblk"),
	behavior.RunsOnPlatform(behavior.PlatformDarwin, "mount"),
	behavior.RunsIfPresent("zfs"),
	behavior.Read("get", Get).
		Describe("Get the disk usage of the host").
		Explain("Reads the size, the used space and the free space of each local "+
			"filesystem, in bytes: the mounts of /proc/mounts on Linux and of mount on "+
			"macOS, with their sizes from df. Local is ext4, xfs and btrfs on Linux, and "+
			"apfs and hfs on macOS. Network and special filesystems are left out.").
		Example("A host with one local filesystem", GetInput{},
			Entry{
				Disks: []Disk{
					{Name: "/", Total: 52428800000, Used: 20971520000, Free: 31457280000},
				},
			},
			behavior.Exists("/proc/mounts", "/dev/sda1 / ext4 rw,relatime 0 0\ntmpfs /run tmpfs rw 0 0\n"),
			behavior.Prints("df -akP",
				"Filesystem 1024-blocks Used Available Capacity Mounted on\n"+
					"/dev/sda1 51200000 20480000 30720000 40% /\n"+
					"tmpfs 1024 0 1024 0% /run\n"),
			behavior.Prints("mount", "/dev/disk3s1 on / (apfs, local, journaled)\n"+
				"devfs on /dev (devfs, local, nobrowse)\n"),
			behavior.Prints("df -ki",
				"Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on\n"+
					"/dev/disk3s1 51200000 20480000 30720000 40% 100 200 1% /\n"),
		),
))

Behavior is the disk definition.

Functions

This section is empty.

Types

type Disk

type Disk struct {
	Name  string `json:"name"  doc:"Where the filesystem is mounted"`
	Total int    `json:"total" doc:"The size of the filesystem in bytes" render:"bytes"`
	Used  int    `json:"used"  doc:"The bytes in use"                    render:"bytes"`
	Free  int    `json:"free"  doc:"The bytes free to use"               render:"bytes"`
}

Disk is one mounted filesystem and its usage, in bytes.

type Entry

type Entry struct {
	Disks []Disk `json:"disks" doc:"Each local filesystem"`
}

Entry is the usage of each local filesystem of the host.

func Get

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

Get is the usage of each local filesystem of the host.

type GetInput

type GetInput struct{}

GetInput is get's input, which has none.

type Provider

type Provider interface {
	Disks(ctx context.Context) ([]Disk, error)
}

Provider is what each platform implements: the local filesystems.

Directories

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

Jump to

Keyboard shortcuts

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