Created
May 13, 2019 20:13
-
-
Save tonylambiris/86c39693e214a926757c47fc0c9d03ba to your computer and use it in GitHub Desktop.
Gets a list of disk devices and IO utilization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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