cpuutil

package
v0.0.0-...-2d83fc9 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2017 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

Package cpuutil handles processing of CPU (kernel) utilization information. This information is calculated using the difference between two CPU (kernel) stats snapshots, /proc/stat, and represented as a percentage. The time elapsed between the two snapshots is stored in the TimeDelta field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTicker

func NewTicker(d time.Duration) (joe.Tocker, error)

NewTicker returns a new Ticker containing a Data channel that delivers the data at intervals and an error channel that delivers any errors encountered. Stop the ticker to signal the ticker to stop running. Stopping the ticker does not close the Data channel; call Close to close both the ticker and the data channel.

Types

type CPUUtil

type CPUUtil struct {
	Timestamp int64 `json:"timestamp"`
	// the time since the prior snapshot; the window that the utilization covers.
	TimeDelta int64 `json:"time_delta"`
	// time since last reboot, in seconds
	BTimeDelta int32 `json:"btime_delta"`
	// context switches since last snapshot
	CtxtDelta int64 `json:"ctxt_delta"`
	// current number of Processes
	Processes int32 `json:"processes"`
	// cpu specific utilization information
	CPU []Utilization `json:"cpu"`
}

CPUUtil holds information about cpu, kernel, utilization. The first CPU entry aggregates the numbers found in all of the other CPU[n] entries. Utilization is calculated using the difference between the current and prior /proc/stat snapshot.

func Get

func Get() (*CPUUtil, error)

Get returns the current cpu utilization using the package's global Profiler. The Profiler is instantiated lazily. If the profiler doesn't already exist, the first usage information will not be useful due to minimal time elapsing between the initial and second snapshots used for usage calculations; the results of the first call should be discarded.

type Profiler

type Profiler struct {
	*stats.Profiler
	// contains filtered or unexported fields
}

Profiler is used to process the /proc/stats file and calculate Utilization information.

func NewProfiler

func NewProfiler() (prof *Profiler, err error)

Returns an initialized Profiler; ready to use. Upon creation, a /proc/stat snapshot is taken so that any Get() will return valid information.

func (*Profiler) Get

func (prof *Profiler) Get() (u *CPUUtil, err error)

Get returns the cpu utilization. Utilization calculations requires two snapshots. This func gets the current snapshot of /proc/stat and calculates the utilization using the difference between the current snapshot and the prior one. The current snapshot is stored and for use as the prior snapshot on the next Get call. If ongoing utilitzation information is desired, the Ticker should be used; it's better suited for ongoing utilization information.

type Ticker

type Ticker struct {
	*joe.Ticker
	Data chan *CPUUtil
	*Profiler
}

Ticker delivers the system's CPU utilization information at intervals.

func (*Ticker) Close

func (t *Ticker) Close()

Close closes the ticker resources.

func (*Ticker) Run

func (t *Ticker) Run()

Run runs the ticker.

type Utilization

type Utilization struct {
	ID     string  `json:"id"`
	Usage  float32 `json:"usage"`
	User   float32 `json:"user"`
	Nice   float32 `json:"nice"`
	System float32 `json:"system"`
	Idle   float32 `json:"idle"`
	IOWait float32 `json:"io_wait"`
}

Utilization holds kernel utilization information, as percentages, for a CPU.

Directories

Path Synopsis
Package cpuutil handles Flatbuffer based processing of CPU (kernel) utilization information.
Package cpuutil handles Flatbuffer based processing of CPU (kernel) utilization information.
Package cpuutil handles JSON based processing of CPU (kernel) utilization information.
Package cpuutil handles JSON based processing of CPU (kernel) utilization information.

Jump to

Keyboard shortcuts

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