disk.go 2.5 KB
Newer Older
S
Shirou WAKAYAMA 已提交
1
package disk
W
WAKAYAMA Shirou 已提交
2

3
import (
4
	"context"
5
	"encoding/json"
6 7

	"github.com/shirou/gopsutil/internal/common"
8 9
)

10
var invoke common.Invoker = common.Invoke{}
11

12
type UsageStat struct {
W
WAKAYAMA Shirou 已提交
13
	Path              string  `json:"path"`
14
	Fstype            string  `json:"fstype"`
W
WAKAYAMA Shirou 已提交
15 16 17
	Total             uint64  `json:"total"`
	Free              uint64  `json:"free"`
	Used              uint64  `json:"used"`
18 19 20 21 22
	UsedPercent       float64 `json:"usedPercent"`
	InodesTotal       uint64  `json:"inodesTotal"`
	InodesUsed        uint64  `json:"inodesUsed"`
	InodesFree        uint64  `json:"inodesFree"`
	InodesUsedPercent float64 `json:"inodesUsedPercent"`
W
WAKAYAMA Shirou 已提交
23 24
}

25
type PartitionStat struct {
26 27 28 29 30 31
	Device     string `json:"device"`
	Mountpoint string `json:"mountpoint"`
	Fstype     string `json:"fstype"`
	Opts       string `json:"opts"`
}

32
type IOCountersStat struct {
33 34 35 36 37 38 39 40 41 42
	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"`
43
	WeightedIO       uint64 `json:"weightedIO"`
44 45
	Name             string `json:"name"`
	SerialNumber     string `json:"serialNumber"`
46
	Label            string `json:"label"`
W
WAKAYAMA Shirou 已提交
47
}
48

49
func (d UsageStat) String() string {
50 51 52 53
	s, _ := json.Marshal(d)
	return string(s)
}

54
func (d PartitionStat) String() string {
55 56 57 58
	s, _ := json.Marshal(d)
	return string(s)
}

59
func (d IOCountersStat) String() string {
60 61 62
	s, _ := json.Marshal(d)
	return string(s)
}
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

// 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...)
}