cpu

package
v0.0.0-...-bf74b40 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

cpu will examine /proc/stat to estimate how busy the CPU is. /proc/stat holds data of how much time the CPU has been idle/busy etc. since uptime.

client, err := cpu.NewClient()
// .. handle error
loads, err := client.GetLoads()

loads is a slice of how busy each CPU appears to be. loads[0] will almost certainly be the average over all cpus. All subsequent entries will be for each individual CPU.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client stores one read of the stat file. It is used to estimate CPU load.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new instance of the client

func (*Client) GetLoads

func (c *Client) GetLoads() ([]float64, error)

GetLoads() will perform a read of /proc/stat It will update the internal buffer with the information from said file. It returns how much time the cpus have been busy since the *last* call to get loads as a percentage. The order of the slice is the same as the order of the cpus in /proc/stat. The cpu total will almost certainly be in index 0, all subsequent entries are for the individual cores.

Jump to

Keyboard shortcuts

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