added load average calculations and moved the testing from main to their own cli commands
This commit is contained in:
1 parent
8c931aa3d8
commit
b1d4f3565d
7 files changed
+271
-26
No files matched your search
@@ -5,6 +5,10 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
loadaverage "rpi5-health/internal/load_average"
|
||||
"rpi5-health/internal/memory"
|
||||
"rpi5-health/internal/processor"
|
||||
"rpi5-health/internal/uptime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -30,6 +34,28 @@ func Listen() {
|
||||
switch text {
|
||||
case "exit":
|
||||
return
|
||||
case "meminfo":
|
||||
memInfo, _ := memory.GetRamInformation()
|
||||
|
||||
const GB = 1024 * 1024 * 1024
|
||||
|
||||
fmt.Printf("Total memory: %.2fGB\n", float64(memInfo.SystemMemory)/GB)
|
||||
fmt.Printf("Available memory: %.2fGB\n", float64(memInfo.AvailableMemory)/GB)
|
||||
fmt.Printf("Used memory: %.2fGB\n", float64(memInfo.GetUsedMemory())/GB)
|
||||
case "cpuinfo":
|
||||
_, kernel, usage, idle := processor.GetCPUInformation().Usage()
|
||||
|
||||
fmt.Printf("Total time spent idling: %.2f%%\n", idle)
|
||||
fmt.Printf("Total time spent in kernel mode: %.2f%%\n", kernel)
|
||||
fmt.Printf("Total time spent in user mode: %.2f%%\n", usage)
|
||||
case "uptime":
|
||||
uptime, _ := uptime.GetUptimeInformation()
|
||||
|
||||
fmt.Printf("Total uptime: %s\n", uptime.FormatSeconds())
|
||||
case "loadavg":
|
||||
loadAvg, _ := loadaverage.GetLoadAverage()
|
||||
|
||||
fmt.Printf("Load average: L1: %.2f | L5: %.2f | L15: %.2f\n", loadAvg.Load1, loadAvg.Load5, loadAvg.Load15)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user