cputhrottle

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package cputhrottle measures how much the CPU limit of a container holds it back: the share of the CFS periods in which the container was throttled, over a sliding window of a few minutes, from the cpu.stat of its cgroup (v2).

Index

Constants

View Source
const (
	// WindowSpan is how far back the ratio looks.
	WindowSpan = 5 * time.Minute
	// MinPeriods is the fewest periods in a window a ratio is reported for: the counters only run while the container is
	// busy, and a few periods say nothing.
	MinPeriods = 30
	// Step is the granularity of the reported percent: a smaller change is not news.
	Step = 10
	// AlertPercent is the share above which a container counts as starved by its limit.
	AlertPercent = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Stat

type Stat struct{ Periods, Throttled uint64 }

Stat is the throttling counters of a cgroup: periods elapsed with a quota in force, and how many of them throttled.

func ParseStat

func ParseStat(sc *bufio.Scanner) (Stat, error)

ParseStat reads the counters from the lines of a cpu.stat. A cgroup without a CPU limit has no such counters.

func ReadStat

func ReadStat(dir string) (Stat, error)

ReadStat reads nr_periods and nr_throttled from the cpu.stat of the cgroup directory (cgroup v2).

type Window

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

Window keeps the samples of one container for WindowSpan.

func (*Window) Add

func (w *Window) Add(at time.Time, s Stat)

Add records the counters read at the given time. Counters that went back mean a new container: the history is dropped.

func (*Window) Percent

func (w *Window) Percent() (percent int32, covered time.Duration, ok bool)

Percent is the share of throttled periods (0..100, rounded to Step) over the window and the time the window covers. ok is false while there are fewer than MinPeriods periods in it.

Jump to

Keyboard shortcuts

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