cpuutil

package
v0.0.0-...-df36a95 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cpuutil handles JSON based 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. Instead of returning a Go struct, it returns JSON serialized bytes. For convenience, a function to deserialize the JSON serialized bytes into a cpuutil.CPUUtil struct is provided.

Note: the package name is cpuutil and not the final element of the import path (json).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deserialize

func Deserialize(p []byte) (*util.CPUUtil, error)

Deserialize takes some JSON serialized bytes and unmarshals them as cpuutil.CPUUtil.

func Get

func Get() (p []byte, err error)

Get returns the current cpu utilization as JSON serialized bytes 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.

func Marshal

func Marshal(ut *util.CPUUtil) ([]byte, error)

Marsha is an alias for Serialize using the package global Profiler.

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.

func Serialize

func Serialize(ut *util.CPUUtil) (p []byte, err error)

Serialize the CPU Utilization as JSON using the package global Profiler.

func Unmarshal

func Unmarshal(p []byte) (*util.CPUUtil, error)

Unmarshal is an alias for Deserialize.

Types

type Profiler

type Profiler struct {
	*util.Profiler
}

Profiler is used to process the /proc/stats file and calculate utilization information, returning the data as JSON serialized bytes.

func NewProfiler

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

Initializes and returns a cpu utlization profiler.

func (*Profiler) Get

func (prof *Profiler) Get() (p []byte, err error)

Get returns the cpu utilization as JSON serialized bytes. 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.

func (*Profiler) Marshal

func (prof *Profiler) Marshal(ut *util.CPUUtil) ([]byte, error)

Marshal is an alias for Serialize

func (*Profiler) Serialize

func (prof *Profiler) Serialize(ut *util.CPUUtil) ([]byte, error)

Serialize cpu Utilization using JSON.

type Ticker

type Ticker struct {
	*joe.Ticker
	Data chan []byte
	*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.

Jump to

Keyboard shortcuts

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