samplerserverv1alpha1

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package samplerserverv1alpha1 defines the MetricsNodeSampler API.

The sampler scrapes cgroup metrics from the node filesystem and serves an aggregated view over a GRPC interface.

Example MetricsNodeSampler

requiredSamples: 30 # start serving aggregated metrics after we have this many samplers for a container
pbPort: 8080 # bind this port for protocol-buffer GRPC requests
restPort: 8090 # bind this port for rest GRPC requests
buffer: # store 15 minutes worth of samples in the buffer
  size: 900 # store 900 samples
  pollsPerMinute: 60 # sample every 1 seconds
reader:
  containerCacheSyncIntervalSeconds: 10 # look for new containers every 10 seconds
  cpuPaths: # look for cpu metrics under these paths
  - sys/fs/cgroup/cpuacct
  - sys/fs/cgroup/cpu,cpuacct
  memoryPaths: # look for memory metrics under these paths
  - sys/fs/cgroup/memory

The sampler reads the following metrics from cgroupfs

cpuacct.usage: reports the total CPU time (in nanoseconds) consumed by all tasks in this cgroup
cpu.stat:
  nr_periods – number of periods that any thread in the cgroup was runnable
  nr_throttled – number of runnable periods in which the application used its entire quota and was throttled
  throttled_time – sum total amount of time individual threads within the cgroup were throttled
memory.stat:
  total_cache : The amount of memory used by the processes of this control group that can be associated precisely with a block on a block device.
  total_rss : The amount of memory that doesn’t correspond to anything on disk: stacks, heaps, and anonymous memory maps.
oom_control:
  oom-kill : OOM Kill counter
  memory.failcnt: reports the number of times that the memory limit has reached the value set in memory.limit_in_bytes.

Index

Constants

View Source
const (
	// CGroupV1 is set for cgroups v1.
	CGroupV1 CGroupVersion = "v1"

	// CGroupV2 is set for cgroups v2.
	CGroupV2 CGroupVersion = "v2"

	// DefaultPollsPerMinute is the default number polls to perform per minute.
	DefaultPollsPerMinute = 60

	// DefaultSampleBufferSize is the default number of samples to keep.  The cache will have samples
	// over a duration of DefaultPollSeconds*DefaultSampleBufferSize (in seconds).
	DefaultSampleBufferSize = 900

	DefaultPBPort   = 8080
	DefaultRestPort = 8090

	DefaultPushFrequency            = "1m"
	DefaultCheckCreatedPodFrequency = "6s"

	CPUUsageSourceFilenameV1      = "cpuacct.usage"
	CPUThrottlingSourceFilenameV1 = "cpu.stat"
	MemoryUsageSourceFilenameV1   = "memory.stat"
	MemoryOOMKillFilenameV1       = "memory.oom_control"
	MemoryOOMFilenameV1           = "memory.failcnt"

	CPUUsageSourceFilenameV2  = "cpu.stat"
	MemoryOOMEventsFilenameV2 = "memory.events"
	MemoryCurrentFilenameV2   = "memory.current"
)

Variables

View Source
var (
	// DefaultMetricsReaderCPUPathsV1 is the default paths for reading cpu metrics on cgroupv1
	DefaultMetricsReaderCPUPathsV1 = []MetricsFilepath{
		MetricsFilepath(filepath.Join("sys", "fs", "cgroup", "cpu,cpuacct")),
		MetricsFilepath(filepath.Join("sys", "fs", "cgroup", "cpuacct")),
		MetricsFilepath(filepath.Join("sys", "fs", "cgroup", "cpu")),
	}

	// DefaultMetricsReaderMemoryPathsV1 is the default paths for reading memory metrics on cgroupv1
	DefaultMetricsReaderMemoryPathsV1 = []MetricsFilepath{
		MetricsFilepath(filepath.Join("sys", "fs", "cgroup", "memory")),
	}

	// DefaultMetricsReaderUnifiedPathV2 is the single unified path for reading all metrics on cgroupv2
	// On v2, the file tree is unified and we do not need to look for cpu/memory in subdirectories
	DefaultMetricsReaderUnifiedPathV2 = []MetricsFilepath{
		MetricsFilepath(filepath.Join("sys", "fs", "cgroup")),
	}

	// DefaultContainerCacheSyncInterval is how frequently to sync the list of known containers.
	DefaultContainerCacheSyncIntervalSeconds = pointer.Float32(10)
)
View Source
var (
	// Transformations to cgroup -> pod mapping
	DefaultContainerSuffix = []string{".slice", ".scope"}
	DefaultContainerPrefix = []string{"cri-containerd-"}
	DefaultPodSuffix       = []string{".slice", ".scope"}
	DefaultPodPrefix       = []string{"kubelet-kubepods-burstable-pod", "kubelet-kubepods-besteffort-pod", "kubelet-kubepods-pod", "pod"}
	DefaultReplacements    = map[string]string{
		"_": "-",
	}
	DefaultParentDirectories = []string{
		"kubelet-kubepods-besteffort.slice", "kubelet-kubepods-burstable.slice", "kubelet-kubepods.slice", "kubelet.slice",
	}
)

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// Size is the max number of containerd scrapes to store
	// Older samples will be expired when the max is reached.
	// +optional
	Size int `json:"size" yaml:"size"`

	// PollsPerMinute is how frequently to read container metrics from containerd
	// +optional
	PollsPerMinute int `json:"pollsPerMinute" yaml:"pollsPerMinute"`
}

Buffer configures the window of buffered metric samples.

type CGroupVersion

type CGroupVersion string

CGroupVersion is the version of cgroups being used -- either v1 or v2

type DNSSpec added in v0.6.2

type DNSSpec struct {
	PollSeconds int `json:"pollSeconds" yaml:"pollSeconds"`
}

type MetricsFilepath

type MetricsFilepath string

MetricsFilepath is a filepath to walk for metrics -- e.g. /sys/fs/cgroup/cpuacct/kubelet/kubepods

type MetricsNodeSampler

type MetricsNodeSampler struct {
	Buffer Buffer `json:"buffer" yaml:"buffer"`
	Reader Reader `json:"reader" yaml:"reader"`

	// PBPort is the port to bind for the protocol buffer endpoint
	PBPort int `json:"pbPort" yaml:"pbPort"`

	// RestPort is the port to bind for the REST endpoint
	RestPort int `json:"restPort" yaml:"restPort"`

	// Address is used by tests to bind to localhost
	Address string `json:"address,omitempty" yaml:"address,omitempty"`

	SendPushMetricsRetryCount int `json:"sendPushMetricsRetryCount" yaml:"sendPushMetricsRetryCount"`

	DEPRECATED_PushService   string `json:"pushAddress" yaml:"pushAddress"` // TODO: Remove this
	PushHeadlessService      string `json:"pushHeadlessService" yaml:"pushHeadlessService"`
	PushHeadlessServicePort  int    `json:"pushHeadlessServicePort" yaml:"pushHeadlessServicePort"`
	PushFrequency            string `json:"pushFrequencyDuration" yaml:"pushFrequencyDuration"`
	CheckCreatedPodFrequency string `json:"checkCreatedPodFrequencyDuration" yaml:"checkCreatedPodFrequencyDuration"`

	ExitOnConfigChange bool `json:"exitOnConfigChange" yaml:"exitOnConfigChange"`

	// UseCadvisorMonitor bool
	UseCadvisorMonitor bool `json:"useCadvisorMonitor" yaml:"useContainerMonitor"`
	// Cadvisor configurations.
	CadvisorProtocol string `json:"cadvisorProtocol" yaml:"cadvisorProtocol"`
	CadvisorPort     string `json:"cadvisorPort" yaml:"cadvisorPort"`
	CadvisorPath     string `json:"cadvisorPath" yaml:"cadvisorPath"`
	CadvisorToken    string `json:"cadvisorToken" yaml:"cadvisorToken"`

	// UseContainerMonitor enables container monitor metrics from containerd
	UseContainerMonitor bool `json:"useContainerMonitor" yaml:"useContainerMonitor"`

	// ContainerdAddress specifies the address for connecting to containerd
	// Default: /run/containerd/containerd.sock
	ContainerdAddress string `json:"containerdAddress" yaml:"containerdAddress"`

	// ContainerdNamespace specifies which containerd namespace to collect metrics for
	// Default: default
	ContainerdNamespace string `json:"containerdNamespace" yaml:"containerdNamespace"`

	DNSSpec DNSSpec `json:"dnsSpec" yaml:"dnsSpec"`
}

MetricsNodeSampler configures a metrics-node-sampler.

func (*MetricsNodeSampler) Default

func (s *MetricsNodeSampler) Default()

type NodeAggregationLevel

type NodeAggregationLevel string
const (
	NodeAggregationLevelPodsAll        NodeAggregationLevel = "kubelet/kubepods"
	NodeAggregationLevelPodsBestEffort NodeAggregationLevel = "kubelet/kubepods/besteffort"
	NodeAggregationLevelPodsBurstable  NodeAggregationLevel = "kubelet/kubepods/burstable"
	NodeAggregationLevelPodsGuaranteed NodeAggregationLevel = "kubelet/kubepods/guaranteed"
)

type Reader

type Reader struct {
	// CGroupVersion defines which version of cgroups to use
	CGroupVersion CGroupVersion `json:"cgroupVersion" yaml:"cgroupVersion"`

	// CPUPath defines where to read cpu metrics from.  Defaults to cpuacct/kubepods.
	CPUPaths []MetricsFilepath `json:"cpuPaths" yaml:"cpuPaths"`

	// MemoryPath defines where to read memory metrics from.  Defaults to memory/kubepods.
	MemoryPaths []MetricsFilepath `json:"memoryPaths" yaml:"memoryPaths"`

	PodPrefix             []string          `json:"podPrefix,omitempty" yaml:"podPrefix,omitempty"`
	PodSuffix             []string          `json:"podSuffix,omitempty" yaml:"podSuffix,omitempty"`
	ContainerPrefix       []string          `json:"containerPrefix,omitempty" yaml:"containerPrefix,omitempty"`
	ContainerSuffix       []string          `json:"containerSuffix,omitempty" yaml:"containerSuffix,omitempty"`
	PodReplacements       map[string]string `json:"podReplacements,omitempty" yaml:"podReplacements,omitempty"`
	ContainerReplacements map[string]string `json:"containerReplacements,omitempty" yaml:"containerReplacements,omitempty"`
	ParentDirectories     []string          `json:"parents,omitempty" yaml:"parents,omitempty"`

	NodeAggregationLevelGlobs []NodeAggregationLevel `json:"nodeAggregationLevelGlobs" yaml:"nodeAggregationLevelGlobs"`

	// ContainerCacheSyncInterval defines how frequently to sync the list of containers.  Defaults to 1 minute.
	ContainerCacheSyncIntervalSeconds *float32 `json:"containerCacheSyncIntervalSeconds" yaml:"containerCacheSyncIntervalSeconds"`

	// MinCPUCoresSampleValue is the minimum number of cpu cores / sec a sample must have to be considered valid.
	// Invalid samples are dropped from responses.
	MinCPUCoresSampleValue float64 `json:"minCPUCoresSampleValue" yaml:"minCPUCoresSampleValue"`
	// MaxCPUCoresSampleValue is the maximum number of cpu cores / sec a sample may have to be considered valid.
	// Invalid samples are dropped from responses.
	MaxCPUCoresSampleValue float64 `json:"maxCPUCoresSampleValue" yaml:"maxCPUCoresSampleValue"`

	// MinCPUCoresNanoSec is defaulted from MinCPUCoresSampleValue
	MinCPUCoresNanoSec int64 `json:"minCPUCoresNanoSec" yaml:"minCPUCoresNanoSec"`
	// MaxCPUCoresNanoSec is defaulted from MaxCPUCoresSampleValue
	MaxCPUCoresNanoSec uint64 `json:"maxCPUCoresNanoSec" yaml:"maxCPUCoresNanoSec"`

	// DropFirstValue if true will drop the first sample value so the average
	// by computing the last-first values more closely matches the average
	// by computing the average of the individual samples.
	DropFirstValue *bool `json:"dropFirstValue,omitempty" yaml:"dropFirstValue,omitempty"`
}

Reader configures how a single sample of cgroup metrics are read from the filesystem.

Jump to

Keyboard shortcuts

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