clistat

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixDefault = 1.0
	PrefixKibi    = 1024.0
	PrefixMebi    = PrefixKibi * 1024.0
	PrefixGibi    = PrefixMebi * 1024.0
	PrefixTebi    = PrefixGibi * 1024.0
)
View Source
const (
	// 9223372036854771712 is the highest positive signed 64-bit integer (263-1),
	// rounded down to multiples of 4096 (2^12), the most common page size on x86 systems.
	// This is used by docker to indicate no memory limit.
	UnlimitedMemory int64 = 9223372036854771712
)

Variables

View Source
var (
	PrefixHumanKibi = "Ki"
	PrefixHumanMebi = "Mi"
	PrefixHumanGibi = "Gi"
	PrefixHumanTebi = "Ti"
)

Functions

func IsContainerized

func IsContainerized(fs afero.Fs) (ok bool, err error)

IsContainerized returns whether the host is containerized. This is adapted from https://github.com/elastic/go-sysinfo/tree/main/providers/linux/container.go#L31 with modifications to support Sysbox containers. On non-Linux platforms, it always returns false.

Types

type Option

type Option func(*Statter)

func WithFS

func WithFS(fs afero.Fs) Option

WithFS sets the fs for the statter.

func WithSampleInterval

func WithSampleInterval(d time.Duration) Option

WithSampleInterval sets the sample interval for the statter.

type Prefix

type Prefix float64

Prefix is a scale multiplier for a result. Used when creating a human-readable representation.

func ParsePrefix

func ParsePrefix(s string) Prefix

func (*Prefix) String

func (s *Prefix) String() string

type Result

type Result struct {
	Total  *float64 `json:"total"`
	Unit   string   `json:"unit"`
	Used   float64  `json:"used"`
	Prefix Prefix   `json:"-"`
}

Result is a generic result type for a statistic. Total is the total amount of the resource available. It is nil if the resource is not a finite quantity. Unit is the unit of the resource. Used is the amount of the resource used.

func (*Result) String

func (r *Result) String() string

String returns a human-readable representation of the result.

type Statter

type Statter struct {
	// contains filtered or unexported fields
}

Statter is a system statistics collector. It is a thin wrapper around the elastic/go-sysinfo library.

func New

func New(opts ...Option) (*Statter, error)

func (*Statter) ContainerCPU

func (s *Statter) ContainerCPU() (*Result, error)

ContainerCPU returns the CPU usage of the container cgroup. This is calculated as difference of two samples of the CPU usage of the container cgroup. The total is read from the relevant path in /sys/fs/cgroup. If there is no limit set, the total is assumed to be the number of host cores multiplied by the CFS period. If the system is not containerized, this always returns nil.

func (*Statter) ContainerMemory

func (s *Statter) ContainerMemory(p Prefix) (*Result, error)

ContainerMemory returns the memory usage of the container cgroup. If the system is not containerized, this always returns nil.

func (*Statter) Disk

func (*Statter) Disk(p Prefix, path string) (*Result, error)

Disk returns the disk usage of the given path. If path is empty, it returns the usage of the root directory.

func (*Statter) HostCPU

func (s *Statter) HostCPU() (*Result, error)

HostCPU returns the CPU usage of the host. This is calculated by taking two samples of CPU usage and calculating the difference. Total will always be equal to the number of cores. Used will be an estimate of the number of cores used during the sample interval. This is calculated by taking the difference between the total and idle HostCPU time and scaling it by the number of cores. Units are in "cores".

func (*Statter) HostMemory

func (s *Statter) HostMemory(p Prefix) (*Result, error)

HostMemory returns the memory usage of the host, in gigabytes.

Jump to

Keyboard shortcuts

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