[agent-go] [status] basically accomplished the status module

This commit is contained in:
zeaslity
2023-04-14 10:04:58 +08:00
parent 9909593545
commit e50ba14c13
6 changed files with 105 additions and 10 deletions

47
agent-go/status/Disk.go Normal file
View File

@@ -0,0 +1,47 @@
package status
import (
"fmt"
"github.com/shirou/gopsutil/v3/disk"
"runtime"
"time"
)
type DiskStatus struct {
Total uint64
Used uint64
LogicalDisk []disk.PartitionStat
}
func GetDiskStatus() *DiskStatus {
var ds *DiskStatus
// Get disk usage
du, _ := disk.Usage("/")
ds.Total = du.Total
ds.Used = du.Used
// Get logical disk info for Linux systems
if runtime.GOOS == "linux" {
ld, _ := disk.Partitions(true)
ds.LogicalDisk = ld
}
return ds
}
func CalculateDiskIO() {
// Get initial disk IO counters
counters1, _ := disk.IOCounters()
time.Sleep(time.Second)
// Get disk IO counters after 1 second
counters2, _ := disk.IOCounters()
for device, counter1 := range counters1 {
counter2 := counters2[device]
readSpeed := float64(counter2.ReadBytes-counter1.ReadBytes) / 1024
writeSpeed := float64(counter2.WriteBytes-counter1.WriteBytes) / 1024
fmt.Printf("%v: read %vKB/s, write %vKB/s\n", device, readSpeed, writeSpeed)
}
}