-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
81 lines (67 loc) · 1.54 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"github.com/shirou/gopsutil/mem"
"log"
"math"
"strconv"
"time"
"github.com/shirou/gopsutil/cpu"
"github.com/getlantern/systray"
)
func main() {
systray.Run(onReady, onExit)
}
func onReady() {
model,numberOfCore,frequency,cacheSize:=getInfo()
go func() {
var result string
for {
result = getData()
systray.SetTitle(result)
}
}()
systray.AddMenuItem(fmt.Sprintf("CPU : %s",model),"Cpu Model")
systray.AddMenuItem(fmt.Sprintf("Cores : %74s",strconv.Itoa(int(numberOfCore))),"Number of core")
systray.AddMenuItem(fmt.Sprintf("Frequency : %70s",strconv.Itoa(frequency)),"Frequency CPU")
systray.AddMenuItem(fmt.Sprintf("CPU Cache : %71s",strconv.Itoa(int(cacheSize))),"CPU Cache")
systray.AddSeparator()
mQuit := systray.AddMenuItem("Quit", "Quits this app")
go func() {
for {
select {
case <-mQuit.ClickedCh:
systray.Quit()
return
}
}
}()
}
func onExit(){
}
func getMemoryUsage()int{
memory,err:=mem.VirtualMemory()
if err!=nil{
log.Fatal(err)
}
return int(math.Ceil(memory.UsedPercent))
}
func getCpuUsage()int{
percent,err:=cpu.Percent(time.Second,false)
if err!=nil{
log.Fatal(err)
}
return int(math.Ceil(percent[0]))
}
func getData()(string){
cpuData:="Cpu: "+strconv.Itoa(getCpuUsage())+"% "
memoryData:="Mem: "+strconv.Itoa(getMemoryUsage())+"% "
return cpuData+memoryData
}
func getInfo()(string,int32,int,int32){
info,err:=cpu.Info()
if err!=nil{
log.Fatal(err)
}
return info[0].ModelName,info[0].Cores,int(info[0].Mhz),info[0].CacheSize
}