package cpustats

import "github.com/hashicorp/nomad/client/lib/cpustats"

Package cpustats provides utilities for tracking CPU usage statistics.

Index

Types

type Compute

type Compute struct {
	TotalCompute hw.MHz `json:"tc"`
	NumCores     int    `json:"nc"`
}

Compute is the cpu related fields of a numa.Topology needed for computing performance / utilization of tasks.

Note that this is serialized and passed to executor.Executor as a CLI argument and so we use small json field names to minimize ps spam.

type Tracker

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

A Tracker keeps track of one aspect of CPU utilization (i.e. one of system, user, or total time).

func New

func New(c Compute) *Tracker

New creates a fresh Tracker with no data.

func (*Tracker) Percent

func (t *Tracker) Percent(cpuTime float64) float64

Percent calculates the CPU usage percentage based on the current CPU usage and the previous CPU usage where usage is given as a time in nanoseconds spent using the CPU.

func (*Tracker) TicksConsumed

func (t *Tracker) TicksConsumed(percent float64) float64

TicksConsumed calculates the total bandwidth consumed by the process across all system CPU cores (not just the ones available to Nomad or this particular process.

Source Files

stats.go

Version
v1.10.0 (latest)
Published
Apr 9, 2025
Platform
linux/amd64
Imports
3 packages
Last checked
2 days ago

Tools for package owners.