Created
June 11, 2019 09:00
-
-
Save plutov/997ff3d06b90edd2aef036e09bbbc3ef to your computer and use it in GitHub Desktop.
wails-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package sys | |
import ( | |
"math" | |
"time" | |
"github.com/shirou/gopsutil/cpu" | |
"github.com/wailsapp/wails" | |
) | |
// Stats . | |
type Stats struct { | |
log *wails.CustomLogger | |
} | |
// CPUUsage . | |
type CPUUsage struct { | |
Average int `json:"avg"` | |
} | |
// WailsInit . | |
func (s *Stats) WailsInit(runtime *wails.Runtime) error { | |
s.log = runtime.Log.New("Stats") | |
return nil | |
} | |
// GetCPUUsage . | |
func (s *Stats) GetCPUUsage() *CPUUsage { | |
percent, err := cpu.Percent(1*time.Second, false) | |
if err != nil { | |
s.log.Errorf("unable to get cpu stats: %s", err.Error()) | |
return nil | |
} | |
return &CPUUsage{ | |
Average: int(math.Round(percent[0])), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment