Documentation ¶
Overview ¶
Package cpuusage library that monitors real time CPU usage (total and per-core) (linux only)
Installation:
go get github.com/simulatedsimian/cpuusage
Example:
// display the cpu usage once per second u := cpuusage.Usage{} for { err := u.Measure() if err != nil { // handle error.... } fmt.Printf("Overall %%: %d Per Core %%: %v\n", u.Overall, u.Cores) time.Sleep(1 * time.Second) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Usage ¶
type Usage struct { // Overall is the combined cpu usage of all cores in the system Overall int // Cores is a slice of ints holding the usage of each core (physical or virtual) in the system Cores []int // contains filtered or unexported fields }
Usage struct holds the overall cpu usage and the per-core usage resulting from the last call to Measure(). Each usage is an int in the range 0..100 representing the percentage cpu utilisation
func (*Usage) Measure ¶
Measure reads the /proc/stat file and extracts the cpu usage information, writing it into the Usage struct. The first call to Measure gives the usage since the system was booted, with subsequent calls giving the usage during the period of time from the previous call to the current one.
Click to show internal directories.
Click to hide internal directories.