Documentation ¶
Index ¶
Constants ¶
const ( PrefixDefault = 1.0 PrefixKibi = 1024.0 PrefixMebi = PrefixKibi * 1024.0 PrefixGibi = PrefixMebi * 1024.0 PrefixTebi = PrefixGibi * 1024.0 )
Variables ¶
var ( PrefixHumanKibi = "Ki" PrefixHumanMebi = "Mi" PrefixHumanGibi = "Gi" PrefixHumanTebi = "Ti" )
Functions ¶
func IsContainerized ¶
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 WithSampleInterval ¶
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 ¶
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.
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 (*Statter) ContainerCPU ¶
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 ¶
ContainerMemory returns the memory usage of the container cgroup. If the system is not containerized, this always returns nil.
func (*Statter) Disk ¶
Disk returns the disk usage of the given path. If path is empty, it returns the usage of the root directory.
func (*Statter) HostCPU ¶
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".