organizing and refactoring
This commit is contained in:
parent
13b5474cd8
commit
6f159d4728
20 changed files with 832 additions and 488 deletions
40
agent/disk/disk_linux.go
Normal file
40
agent/disk/disk_linux.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package disk
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
d "github.com/shirou/gopsutil/v3/disk"
|
||||
trmm "github.com/wh1te909/trmm-shared"
|
||||
"github.com/amidaware/rmmagent/agent/utils"
|
||||
)
|
||||
|
||||
func GetDisks() []trmm.Disk {
|
||||
ret := make([]trmm.Disk, 0)
|
||||
partitions, err := d.Partitions(false)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, p := range partitions {
|
||||
if strings.Contains(p.Device, "dev/loop") {
|
||||
continue
|
||||
}
|
||||
usage, err := d.Usage(p.Mountpoint)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
d := trmm.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
|
||||
}
|
||||
14
agent/disk/disk_linux_test.go
Normal file
14
agent/disk/disk_linux_test.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package disk
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetDisks(t *testing.T) {
|
||||
disks := GetDisks()
|
||||
if len(disks) == 0 {
|
||||
t.Fatalf("Could not get disks on linux system.")
|
||||
}
|
||||
|
||||
t.Logf("Got %d disks on linux system", len(disks))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue