github.com/qxnw/lib4go@v0.0.0-20180426074627-c80c7e84b925/sysinfo/net/net.go (about)

     1  package net
     2  
     3  import "github.com/shirou/gopsutil/net"
     4  
     5  // Useage Total总量,Idle空闲,Used使用率,Collercter总量,使用量
     6  type Useage struct {
     7  	BytesRecv uint64 `json:"recv"`
     8  	BytesSent uint64 `json:"send"`
     9  	Name      string `json:"name"`
    10  }
    11  
    12  // GetInfo 获取磁盘使用信息
    13  func GetInfo() (useages []*Useage, err error) {
    14  	nv, err := net.IOCounters(false)
    15  	if err != nil {
    16  		return
    17  	}
    18  	useages = make([]*Useage, 0, len(nv))
    19  	for _, status := range nv {
    20  		useage := &Useage{BytesRecv: status.BytesRecv, BytesSent: status.BytesSent, Name: status.Name}
    21  		useages = append(useages, useage)
    22  	}
    23  	return
    24  }