示例#1
0
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
}
示例#2
0
文件: ps.go 项目: zooplus/telegraf
func (s *systemPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) {
	m, err := disk.DiskIOCounters()
	if err == internal.NotImplementedError {
		return nil, nil
	}

	return m, err
}
示例#3
0
// 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
}
示例#4
0
文件: diskio.go 项目: upccup/cuplearn
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())
	}
}
示例#5
0
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))
}