Skip to content

Instantly share code, notes, and snippets.

@tonylambiris
Created May 13, 2019 20:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonylambiris/86c39693e214a926757c47fc0c9d03ba to your computer and use it in GitHub Desktop.
Save tonylambiris/86c39693e214a926757c47fc0c9d03ba to your computer and use it in GitHub Desktop.
Gets a list of disk devices and IO utilization
package main
import (
"github.com/davecgh/go-spew/spew"
psDisk "github.com/shirou/gopsutil/disk"
"github.com/sirupsen/logrus"
)
func main() {
partitions, err := psDisk.Partitions(false)
if err != nil {
logrus.Fatalf("failed to get disk partitions from gopsutil: %v", err)
}
logrus.Printf("%s", spew.Sdump(partitions))
for _, partition := range partitions {
//if usage, err := psDisk.Usage(partition.Mountpoint); err != nil {
if _, err := psDisk.Usage(partition.Mountpoint); err != nil {
continue
} else {
//logrus.Printf("%s", spew.Sdump(usage))
if counters, err := psDisk.IOCounters(partition.Device); err != nil {
logrus.Errorf("failed to get disk io from gopsutil: %v", err)
} else {
logrus.Printf("%s", spew.Sdump(counters))
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment