1package disk 2 3import ( 4 "context" 5 "encoding/json" 6 7 "github.com/shirou/gopsutil/v3/internal/common" 8) 9 10var invoke common.Invoker = common.Invoke{} 11 12type UsageStat struct { 13 Path string `json:"path"` 14 Fstype string `json:"fstype"` 15 Total uint64 `json:"total"` 16 Free uint64 `json:"free"` 17 Used uint64 `json:"used"` 18 UsedPercent float64 `json:"usedPercent"` 19 InodesTotal uint64 `json:"inodesTotal"` 20 InodesUsed uint64 `json:"inodesUsed"` 21 InodesFree uint64 `json:"inodesFree"` 22 InodesUsedPercent float64 `json:"inodesUsedPercent"` 23} 24 25type PartitionStat struct { 26 Device string `json:"device"` 27 Mountpoint string `json:"mountpoint"` 28 Fstype string `json:"fstype"` 29 Opts []string `json:"opts"` 30} 31 32type IOCountersStat struct { 33 ReadCount uint64 `json:"readCount"` 34 MergedReadCount uint64 `json:"mergedReadCount"` 35 WriteCount uint64 `json:"writeCount"` 36 MergedWriteCount uint64 `json:"mergedWriteCount"` 37 ReadBytes uint64 `json:"readBytes"` 38 WriteBytes uint64 `json:"writeBytes"` 39 ReadTime uint64 `json:"readTime"` 40 WriteTime uint64 `json:"writeTime"` 41 IopsInProgress uint64 `json:"iopsInProgress"` 42 IoTime uint64 `json:"ioTime"` 43 WeightedIO uint64 `json:"weightedIO"` 44 Name string `json:"name"` 45 SerialNumber string `json:"serialNumber"` 46 Label string `json:"label"` 47} 48 49func (d UsageStat) String() string { 50 s, _ := json.Marshal(d) 51 return string(s) 52} 53 54func (d PartitionStat) String() string { 55 s, _ := json.Marshal(d) 56 return string(s) 57} 58 59func (d IOCountersStat) String() string { 60 s, _ := json.Marshal(d) 61 return string(s) 62} 63 64// Usage returns a file system usage. path is a filesystem path such 65// as "/", not device file path like "/dev/vda1". If you want to use 66// a return value of disk.Partitions, use "Mountpoint" not "Device". 67func Usage(path string) (*UsageStat, error) { 68 return UsageWithContext(context.Background(), path) 69} 70 71// Partitions returns disk partitions. If all is false, returns 72// physical devices only (e.g. hard disks, cd-rom drives, USB keys) 73// and ignore all others (e.g. memory partitions such as /dev/shm) 74// 75// 'all' argument is ignored for BSD, see: https://github.com/giampaolo/psutil/issues/906 76func Partitions(all bool) ([]PartitionStat, error) { 77 return PartitionsWithContext(context.Background(), all) 78} 79 80func IOCounters(names ...string) (map[string]IOCountersStat, error) { 81 return IOCountersWithContext(context.Background(), names...) 82} 83 84// SerialNumber returns Serial Number of given device or empty string 85// on error. Name of device is expected, eg. /dev/sda 86func SerialNumber(name string) (string, error) { 87 return SerialNumberWithContext(context.Background(), name) 88} 89 90// Label returns label of given device or empty string on error. 91// Name of device is expected, eg. /dev/sda 92// Supports label based on devicemapper name 93// See https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-block-dm 94func Label(name string) (string, error) { 95 return LabelWithContext(context.Background(), name) 96} 97