-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.go
182 lines (152 loc) · 3.58 KB
/
app.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package main
import (
"context"
"fmt"
"log"
"strings"
"time"
"github.com/jaypipes/ghw"
. "github.com/klauspost/cpuid/v2"
"github.com/shirou/gopsutil/v3/cpu"
"github.com/shirou/gopsutil/v3/mem"
"golang.org/x/sys/windows/registry"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
// Greet returns a greeting for the given name
func (a *App) Install() string {
return InstallChoco()
}
func (a *App) OsInfo() ([]string, error) {
return getWindowsVersion(), nil
}
func (a *App) Memory() string {
return getMemory()
}
func (a *App) CpuInfo() []string {
return getCpuInfo()
}
func (a *App) CpuFreq() []float64 {
i, _ := cpu.Percent(1*time.Second, true)
return i
}
func (a *App) GpuInfo() []string {
m := []string{}
gpu, err := ghw.GPU()
if err != nil {
fmt.Printf("Error getting GPU info: %v", err)
}
fmt.Printf("%v\n", gpu)
for _, card := range gpu.GraphicsCards {
m = append(m, card.DeviceInfo.Product.Name)
}
return m
}
func getMemory() string {
memory, err := ghw.Memory()
if err != nil {
fmt.Printf("Error getting memory info: %v", err)
}
return memory.String()
}
func getWindowsVersion() []string {
a := []string{}
k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE)
if err != nil {
log.Fatal(err)
}
defer k.Close()
cv, _, err := k.GetStringValue("CurrentVersion")
if err != nil {
log.Fatal(err)
}
a = append(a, cv)
pn, _, err := k.GetStringValue("ProductName")
if err != nil {
log.Fatal(err)
}
a = append(a, pn)
maj, _, err := k.GetIntegerValue("CurrentMajorVersionNumber")
if err != nil {
log.Fatal(err)
}
a = append(a, fmt.Sprintf("%d", maj))
min, _, err := k.GetIntegerValue("CurrentMinorVersionNumber")
if err != nil {
log.Fatal(err)
}
a = append(a, fmt.Sprintf("%d", min))
cb, _, err := k.GetStringValue("CurrentBuild")
if err != nil {
log.Fatal(err)
}
a = append(a, cb)
return a
}
func getCpuInfo() []string {
a := []string{}
a = append(a, CPU.BrandName)
a = append(a, fmt.Sprintf("%d", CPU.PhysicalCores))
a = append(a, fmt.Sprintf("%d", CPU.ThreadsPerCore))
a = append(a, fmt.Sprintf("%d", CPU.LogicalCores))
a = append(a, fmt.Sprintf("%d", CPU.PhysicalCores))
a = append(a, fmt.Sprintf("%d", CPU.Family))
a = append(a, strings.Join(CPU.FeatureSet(), ","))
a = append(a, fmt.Sprintf("%d", CPU.CacheLine))
a = append(a, fmt.Sprintf("%d", CPU.Cache.L1D))
a = append(a, fmt.Sprintf("%d", CPU.Cache.L1I))
a = append(a, fmt.Sprintf("%d", CPU.Cache.L2))
a = append(a, fmt.Sprintf("%d", CPU.Cache.L3))
a = append(a, fmt.Sprintf("%d", CPU.Hz))
a = append(a, fmt.Sprintf("%d", CPU.BoostFreq))
if CPU.Supports(SSE, SSE2) {
a = append(a, "SSE")
}
return a
}
func (a *App) GetCPUFrequencies() []float64 {
info, err := cpu.Info()
if err != nil {
fmt.Println("Error:", err)
}
var freqs []float64
for _, i := range info {
if i.Mhz > 0 {
freqs = append(freqs, i.Mhz)
}
}
if len(freqs) == 0 {
fmt.Println("No CPU frequencies found")
} else {
return freqs
}
return freqs
}
func (a *App) GetMemUsage() []any {
v, _ := mem.VirtualMemory()
return []any{v, v, v, v.UsedPercent}
}
func (a *App) GetStorage() []any {
c := []any{}
block, err := ghw.Block()
if err != nil {
return c
}
for _, disk := range block.Disks {
for _, part := range disk.Partitions {
c = append(c, part)
}
}
return c
}