cpu

package
v0.0.50-alpha.107 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoCFSLimit = errors.New("no CPU CFS limit")

ErrNoCFSLimit indicates no CPU CFS limit is set

Functions

func ParseUintList

func ParseUintList(val string) (map[int]bool, error)

ParseUintList parses CPU list strings like "0-2,4,6-8"

func ReadStat

func ReadStat(stat *Stat)

ReadStat reads current CPU usage

Example

ExampleReadStat shows how to use ReadStat

stat := &Stat{}
ReadStat(stat)
fmt.Printf("CPU usage: %.1f%%\n", float64(stat.Usage)/10.0)

//	// Output: CPU usage: 100.0%

Types

type CPU

type CPU interface {
	// Get CPU usage rate, returned value is 1000 times the actual usage rate (e.g., 50.5% returns 505)
	Usage() (u uint64, e error)
	// Get CPU information
	Info() Info
}

CPU defines CPU statistics interface

func NewPsutilCPU

func NewPsutilCPU(interval time.Duration) (CPU, error)

NewPsutilCPU creates a new CPU monitor based on gopsutil

type CgroupCPU

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

CgroupCPU implements CPU monitoring based on cgroup

func NewCgroupCPU

func NewCgroupCPU() (*CgroupCPU, error)

NewCgroupCPU creates a cgroup-based CPU monitoring instance

func (*CgroupCPU) Info

func (c *CgroupCPU) Info() Info

Info gets CPU information

func (*CgroupCPU) Usage

func (c *CgroupCPU) Usage() (uint64, error)

Usage calculates current CPU usage percentage

type Info

type Info struct {
	Frequency uint64  // CPU frequency (Hz)
	Quota     float64 // CPU quota (if limited)
	Cores     int     // Logical core count
}

Info CPU information structure

func GetInfo

func GetInfo() Info

GetInfo gets CPU information

type PsutilCPU

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

PsutilCPU implements CPU monitoring using gopsutil library

func (*PsutilCPU) Info

func (pc *PsutilCPU) Info() Info

Info returns CPU information

func (*PsutilCPU) Usage

func (pc *PsutilCPU) Usage() (uint64, error)

Usage returns current CPU usage percentage (0-1000)

type Stat

type Stat struct {
	Usage uint64 // CPU usage rate multiplied by 1000
}

Stat CPU usage statistics

Jump to

Keyboard shortcuts

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