Documentation ¶
Overview ¶
Package cpuutil handles Flatbuffer 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 the data as Flatbuffer serialized bytes. For convenience, a function to deserialize the Flatbuffer serialized bytes into a cpuutil.CPUUtil struct is provided.
Note: the package name is cpuutil and not the final element of the import path (flat).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deserialize ¶
Deserialize takes some Flatbuffer serialized bytes and deserializes them as cpuutil.CPUUtil.
func Get ¶
Get returns the current cpu utilization as Flatbuffer 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 NewTicker ¶
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 Profiler ¶
Profiler is used to process the /proc/stats file and calculate utilization information, returning the data as Flatbuffer serialized bytes.
func NewProfiler ¶
Initializes and returns a cpu utilization profiler that uses FlatBuffers.
func (*Profiler) Get ¶
Get returns the cpu utilization as Flatbuffer 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.