MCPcopy Create free account
hub / github.com/PasarGuard/node / GetSystemStats

Function GetSystemStats

pkg/sysstats/sys.go:13–45  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11)
12
13func GetSystemStats() (*common.SystemStatsResponse, error) {
14 stats := &common.SystemStatsResponse{}
15
16 vm, err := mem.VirtualMemory()
17 if err != nil {
18 return stats, err
19 }
20 stats.MemTotal = vm.Total
21 stats.MemUsed = vm.Used
22
23 cores, err := cpu.Counts(true)
24 if err != nil {
25 return stats, err
26 }
27 stats.CpuCores = uint64(cores)
28
29 percentages, err := cpu.Percent(time.Second, false)
30 if err != nil {
31 return stats, err
32 }
33 if len(percentages) > 0 {
34 stats.CpuUsage = percentages[0]
35 }
36
37 incomingSpeed, outgoingSpeed, err := getBandwidthSpeed()
38 if err != nil {
39 return stats, err
40 }
41 stats.IncomingBandwidthSpeed = incomingSpeed
42 stats.OutgoingBandwidthSpeed = outgoingSpeed
43
44 return stats, nil
45}
46
47// getBandwidthSpeed returns the aggregate incoming (rx) and outgoing (tx)
48// bandwidth in bytes per second, sampled over a 1-second interval.

Callers 1

recordSystemStatsMethod · 0.92

Calls 1

getBandwidthSpeedFunction · 0.85

Tested by

no test coverage detected