updated for unix build
This commit is contained in:
parent
66aca05028
commit
e20edcc9ad
37 changed files with 1001 additions and 257 deletions
42
agent/disk/disk_unix.go
Normal file
42
agent/disk/disk_unix.go
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
d "github.com/shirou/gopsutil/v3/disk"
|
||||
"github.com/amidaware/rmmagent/agent/utils"
|
||||
)
|
||||
|
||||
func GetDisks() ([]Disk, error) {
|
||||
ret := make([]Disk, 0)
|
||||
partitions, err := d.Partitions(false)
|
||||
if err != nil {
|
||||
return []Disk{}, nil
|
||||
}
|
||||
|
||||
for _, p := range partitions {
|
||||
if strings.Contains(p.Device, "dev/loop") {
|
||||
continue
|
||||
}
|
||||
usage, err := d.Usage(p.Mountpoint)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
d := Disk{
|
||||
Device: p.Device,
|
||||
Fstype: p.Fstype,
|
||||
Total: utils.ByteCountSI(usage.Total),
|
||||
Used: utils.ByteCountSI(usage.Used),
|
||||
Free: utils.ByteCountSI(usage.Free),
|
||||
Percent: int(usage.UsedPercent),
|
||||
}
|
||||
|
||||
ret = append(ret, d)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue