[agent-go] [status] basically accomplished the status module
This commit is contained in:
47
agent-go/status/Disk.go
Normal file
47
agent-go/status/Disk.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user