| |
package main
import (
"fmt"
"github.com/shirou/gopsutil/disk"
)
func main() {
partitions, err := disk.Partitions(false)
if err != nil {
fmt.Printf("Failed to get disk partitions: %v", err)
return
}
for _, partition := range partitions {
usage, err := disk.Usage(partition.Mountpoint)
if err != nil {
fmt.Printf("Failed to get disk usage for %s: %v", partition.Mountpoint, err)
continue
}
fmt.Printf("Mountpoint: %s\n", partition.Mountpoint)
fmt.Printf("Total disk space: %d bytes\n", usage.Total)
fmt.Printf("Used disk space: %d bytes\n", usage.Used)
fmt.Printf("Free disk space: %d bytes\n", usage.Free)
fmt.Printf("Usage percentage: %.2f%%\n", usage.UsedPercent)
fmt.Println()
}
}