cpuusage

package module
v0.0.0-...-c393e52 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: MIT Imports: 4 Imported by: 1

README

cpuusage GoDoc

Go library that monitors real time CPU usage (total and per-core) (linux only)

Installation:

$ go get github.com/simulatedsimian/cpuusage

Example:

import "github.com/simulatedsimian/cpuusage"
   // 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)
}

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

func (u *Usage) Measure() error

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.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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