func jsonDiskInfo() []byte { type DiskStat struct { Partition disk.DiskPartitionStat Usage disk.DiskUsageStat Counters disk.DiskIOCountersStat } var disks []DiskStat partitions, _ := disk.DiskPartitions(false) c := &DiskStat{} IOCounters, _ := disk.DiskIOCounters() for _, singleDisk := range partitions { if !strings.HasPrefix(singleDisk.Device, "/") { continue } usage, _ := disk.DiskUsage(singleDisk.Mountpoint) c.Partition = singleDisk c.Usage = *usage c.Counters = IOCounters[strings.Split(singleDisk.Device, "/")[2]] disks = append(disks, *c) } jsonPartitions, _ := json.Marshal(disks) return jsonPartitions }
func (s *systemPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) { m, err := disk.DiskIOCounters() if err == internal.NotImplementedError { return nil, nil } return m, err }
// Run gathers disk IO information from gopsutil. func (d *DiskIO) Run() error { data, err := gopsutil_disk.DiskIOCounters() if err != nil { return err } d.Data = data return nil }
func main() { diskIOCounters, err := disk.DiskIOCounters() if err != nil { log.Panicln(err) } for name, IOInfo := range diskIOCounters { log.Println("Name: ", name) log.Println("IOInfo: ", IOInfo.String()) } }
func json_diskIOCounters(w http.ResponseWriter, r *http.Request) { diskinfo, _ := disk.DiskIOCounters() b, _ := json.Marshal(diskinfo) w.Header().Set("Content-Type", "application/json") fmt.Fprintf(w, string(b)) }