shirou_gopsutil/disk/disk.go

83 lines
2.5 KiB
Go
Raw Normal View History

2014-12-30 21:09:05 +08:00
package disk
2014-04-18 15:34:47 +08:00
import (
"context"
"encoding/json"
"github.com/shirou/gopsutil/internal/common"
)
var invoke common.Invoker = common.Invoke{}
type UsageStat struct {
2014-08-26 21:17:35 +08:00
Path string `json:"path"`
Fstype string `json:"fstype"`
2014-08-26 21:17:35 +08:00
Total uint64 `json:"total"`
Free uint64 `json:"free"`
Used uint64 `json:"used"`
UsedPercent float64 `json:"usedPercent"`
InodesTotal uint64 `json:"inodesTotal"`
InodesUsed uint64 `json:"inodesUsed"`
InodesFree uint64 `json:"inodesFree"`
InodesUsedPercent float64 `json:"inodesUsedPercent"`
2014-04-18 15:34:47 +08:00
}
type PartitionStat struct {
2014-04-20 00:53:34 +08:00
Device string `json:"device"`
Mountpoint string `json:"mountpoint"`
Fstype string `json:"fstype"`
Opts string `json:"opts"`
}
type IOCountersStat struct {
ReadCount uint64 `json:"readCount"`
MergedReadCount uint64 `json:"mergedReadCount"`
WriteCount uint64 `json:"writeCount"`
MergedWriteCount uint64 `json:"mergedWriteCount"`
ReadBytes uint64 `json:"readBytes"`
WriteBytes uint64 `json:"writeBytes"`
ReadTime uint64 `json:"readTime"`
WriteTime uint64 `json:"writeTime"`
IopsInProgress uint64 `json:"iopsInProgress"`
IoTime uint64 `json:"ioTime"`
WeightedIO uint64 `json:"weightedIO"`
Name string `json:"name"`
SerialNumber string `json:"serialNumber"`
Label string `json:"label"`
2014-04-18 15:34:47 +08:00
}
func (d UsageStat) String() string {
s, _ := json.Marshal(d)
return string(s)
}
func (d PartitionStat) String() string {
s, _ := json.Marshal(d)
return string(s)
}
func (d IOCountersStat) String() string {
s, _ := json.Marshal(d)
return string(s)
}
// Usage returns a file system usage. path is a filesystem path such
// as "/", not device file path like "/dev/vda1". If you want to use
// a return value of disk.Partitions, use "Mountpoint" not "Device".
func Usage(path string) (*UsageStat, error) {
return UsageWithContext(context.Background(), path)
}
// Partitions returns disk partitions. If all is false, returns
// physical devices only (e.g. hard disks, cd-rom drives, USB keys)
// and ignore all others (e.g. memory partitions such as /dev/shm)
//
// 'all' argument is ignored for BSD, see: https://github.com/giampaolo/psutil/issues/906
func Partitions(all bool) ([]PartitionStat, error) {
return PartitionsWithContext(context.Background(), all)
}
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
return IOCountersWithContext(context.Background(), names...)
}