raw

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package raw fetches raw system-level metrics as they are presented by the operating system

Package raw fetches raw system-level metrics as they are presented by the operating system

Index

Constants

View Source
const (
	CgroupV1 = "1"
	CgroupV2 = "2"
)
View Source
const (
	CgroupSystemd = "systemd"
	CgroupGroupfs = "cgroupfs"
)

Variables

View Source
var (
	ErrInvalidProcStatNumCPUFields = errors.New("invalid number of cpu fields")
	ErrInvalidProcStatFormat       = errors.New("invalid stat format. Error trying to parse the '/proc/stat' file")
)

Functions

func CanAccessDir added in v1.3.0

func CanAccessDir(dir string) bool

CanAccessDir returns true if the the dir is accessible.

func DetectHostRoot added in v1.3.0

func DetectHostRoot(hostRoot string, pathExists func(string) bool) (string, error)

DetectHostRoot returns a path that is located on the hostRoot folder of the host and the `/host` folder on the integrations. If they existed in both hostRoot and /host, returns the /host path, assuming the integration is running in a container

func ParseStatFileContentUint64 added in v1.6.0

func ParseStatFileContentUint64(filePath string) (uint64, error)

Gets uint64 parsed content of single value cgroup stat file This func has been extracted from utils.go on the cgroup repo since is unexported

Types

type Blkio

type Blkio struct {
	IoServiceBytesRecursive []BlkioEntry
	IoServicedRecursive     []BlkioEntry
}

Blkio stores multiple entries of the Block I/O stats

type BlkioEntry

type BlkioEntry struct {
	Op    string
	Value uint64
}

BlkioEntry stores basic information of a simple blkio operation

type CPU

type CPU struct {
	TotalUsage        uint64
	UsageInUsermode   uint64
	UsageInKernelmode uint64
	PercpuUsage       []uint64
	ThrottledPeriods  uint64
	ThrottledTimeNS   uint64
	SystemUsage       uint64
	OnlineCPUs        uint
	Shares            uint64
}

CPU usage snapshot

func (*CPU) OnlineCPUsWithFallback added in v1.7.0

func (c *CPU) OnlineCPUsWithFallback() int

OnlineCPUsWithFallback gets onlineCPUs value falling back to percpuUsage length in case OnlineCPUs is not defined

type CachedInfoDockerClient added in v1.7.0

type CachedInfoDockerClient struct {
	DockerClient
	// contains filtered or unexported fields
}

CachedInfoDockerClient Wraps a DockerClient indefinitely caching Info method first call.

func NewCachedInfoDockerClient added in v1.7.0

func NewCachedInfoDockerClient(c DockerClient) *CachedInfoDockerClient

NewCachedInfoDockerClient returns a client wrapper using the provided one.

func (*CachedInfoDockerClient) Info added in v1.7.0

type CgroupInfo added in v1.7.0

type CgroupInfo struct {
	Version string
	Driver  string
}

func GetCgroupInfo added in v1.7.0

func GetCgroupInfo(ctx context.Context, informer DockerInformer) (*CgroupInfo, error)

type CgroupV1Detector added in v1.7.0

type CgroupV1Detector interface {
	Paths(hostRoot string, pid int) (CgroupsV1PathGetter, error)
}

type CgroupV1PathParser added in v1.7.0

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

func NewCgroupV1PathParser added in v1.7.0

func NewCgroupV1PathParser() *CgroupV1PathParser

func (*CgroupV1PathParser) Paths added in v1.7.0

func (cgd *CgroupV1PathParser) Paths(hostRoot string, pid int) (CgroupsV1PathGetter, error)

type CgroupV2Detector added in v1.7.0

type CgroupV2Detector interface {
	Paths(hostRoot string, pid int) (CgroupV2PathGetter, error)
}

type CgroupV2PathGetter added in v1.7.0

type CgroupV2PathGetter interface {
	// contains filtered or unexported methods
}

type CgroupV2PathParser added in v1.7.0

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

func NewCgroupV2PathParser added in v1.7.0

func NewCgroupV2PathParser() *CgroupV2PathParser

func (*CgroupV2PathParser) Paths added in v1.7.0

func (cgd *CgroupV2PathParser) Paths(hostRoot string, pid int) (CgroupV2PathGetter, error)

type CgroupsV1Fetcher added in v1.7.0

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

CgroupsV1Fetcher fetches the metrics that can be found in cgroups (v1) file system

func NewCgroupsV1Fetcher added in v1.7.0

func NewCgroupsV1Fetcher(
	hostRoot string,
	cgroupDetector CgroupV1Detector,
	systemCPUReader SystemCPUReader,
	networkStatsGetter NetworkStatsGetter,
) (*CgroupsV1Fetcher, error)

func (*CgroupsV1Fetcher) Fetch added in v1.7.0

Fetch get the metrics that can be found in cgroups file system: TODO: populate also network from libcgroups

type CgroupsV1PathGetter added in v1.7.0

type CgroupsV1PathGetter interface {
	// contains filtered or unexported methods
}

type CgroupsV2Fetcher added in v1.7.0

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

CgroupsV2Fetcher fetches the metrics that can be found in cgroups (v2) file system

func NewCgroupsV2Fetcher added in v1.7.0

func NewCgroupsV2Fetcher(
	hostRoot string,
	cgroupDriver string,
	cgroupDetector CgroupV2Detector,
	systemCPUReader SystemCPUReader,
	networkStatsGetter NetworkStatsGetter,
) (*CgroupsV2Fetcher, error)

NewCgroupsV2Fetcher creates a new cgroups data fetcher.

func (*CgroupsV2Fetcher) Fetch added in v1.7.0

Fetch get the metrics that can be found in cgroups v2 file system Unlike v1, cgroup v2 has only single hierarchy.

type DockerClient added in v1.7.0

type DockerClient interface {
	DockerInspector
	ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
}

DockerClient defines the required methods to query docker.

type DockerInformer added in v1.7.0

type DockerInformer interface {
	Info(ctx context.Context) (types.Info, error)
}

Infomer implements a way to get system-wide information regarding to docker.

type DockerInspector added in v1.7.0

type DockerInspector interface {
	DockerInformer
	ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
}

DockerInspector includes `Informer` and a method to inspect a specific container.

type Fetcher

type Fetcher interface {
	Fetch(types.ContainerJSON) (Metrics, error)
}

Fetcher is the minimal abstraction of any raw metrics fetcher implementation

func NewCgroupsFetcher added in v1.3.0

func NewCgroupsFetcher(
	hostRoot string,
	cgroupInfo *CgroupInfo,
	systemCPUReader SystemCPUReader,
	networkStatsGetter NetworkStatsGetter,
) (Fetcher, error)

NewCgroupsFetcher creates the proper metrics fetcher for the used cgroups version.

type Memory

type Memory struct {
	UsageLimit        uint64
	Cache             uint64
	RSS               uint64
	SwapUsage         uint64
	FuzzUsage         uint64
	KernelMemoryUsage uint64
	SwapLimit         uint64
	SoftLimit         uint64
}

Memory usage snapshot

type Metrics

type Metrics struct {
	Time        time.Time
	ContainerID string
	Memory      Memory
	Network     Network
	CPU         CPU
	Pids        Pids
	Blkio       Blkio
}

Metrics holds containers raw metric values as they are extracted from the system

type NetDevNetworkStatsGetter added in v1.7.0

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

func NewNetDevNetworkStatsGetter added in v1.7.0

func NewNetDevNetworkStatsGetter() *NetDevNetworkStatsGetter

func (*NetDevNetworkStatsGetter) GetForContainer added in v1.7.0

func (cd *NetDevNetworkStatsGetter) GetForContainer(hostRoot, pid, containerID string) (Network, error)

type Network

type Network struct {
	RxBytes   int64
	RxDropped int64
	RxErrors  int64
	RxPackets int64
	TxBytes   int64
	TxDropped int64
	TxErrors  int64
	TxPackets int64
}

Network transmission and receive metrics

type NetworkStatsGetter added in v1.7.0

type NetworkStatsGetter interface {
	GetForContainer(hostRoot, pid, containerID string) (Network, error)
}

type Pids

type Pids struct {
	Current uint64
	Limit   uint64
}

Pids inside the container

type PosixSystemCPUReader added in v1.7.0

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

func NewPosixSystemCPUReader added in v1.7.0

func NewPosixSystemCPUReader() PosixSystemCPUReader

func (PosixSystemCPUReader) ReadUsage added in v1.7.0

func (r PosixSystemCPUReader) ReadUsage() (uint64, error)

ReadUsage returns the host system's cpu usage in nanoseconds. An error is returned if the format of the underlying file does not match.

Uses /proc/stat defined by POSIX. Looks for the cpu statistics line and then sums up the first seven fields provided. See `man 5 proc` for details on specific field information.

type SystemCPUReader added in v1.7.0

type SystemCPUReader interface {
	ReadUsage() (uint64, error)
}

type V2MountPoint added in v1.7.0

type V2MountPoint string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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