mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-29 13:49:21 +08:00
[disk] move without context functions to disk.go.
This commit is contained in:
parent
cf222ab258
commit
1f733a99dc
21
disk/disk.go
21
disk/disk.go
@ -1,6 +1,7 @@
|
|||||||
package disk
|
package disk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
@ -59,3 +60,23 @@ func (d IOCountersStat) String() string {
|
|||||||
s, _ := json.Marshal(d)
|
s, _ := json.Marshal(d)
|
||||||
return string(s)
|
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...)
|
||||||
|
}
|
||||||
|
@ -9,10 +9,6 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Partitions(all bool) ([]PartitionStat, error) {
|
|
||||||
return PartitionsWithContext(context.Background(), all)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartitionsWithContext returns disk partition.
|
// PartitionsWithContext returns disk partition.
|
||||||
// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906
|
// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906
|
||||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||||
|
@ -17,10 +17,6 @@ import (
|
|||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
var buf [C.NDRIVE]C.DriveStats
|
var buf [C.NDRIVE]C.DriveStats
|
||||||
n, err := C.readdrivestat(&buf[0], C.int(len(buf)))
|
n, err := C.readdrivestat(&buf[0], C.int(len(buf)))
|
||||||
|
@ -9,10 +9,6 @@ import (
|
|||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
@ -8,26 +8,14 @@ import (
|
|||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func Partitions(all bool) ([]PartitionStat, error) {
|
|
||||||
return PartitionsWithContext(context.Background(), all)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||||
return []PartitionStat{}, common.ErrNotImplementedError
|
return []PartitionStat{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func Usage(path string) (*UsageStat, error) {
|
|
||||||
return UsageWithContext(context.Background(), path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
@ -13,10 +13,6 @@ import (
|
|||||||
"github.com/shirou/gopsutil/internal/common"
|
"github.com/shirou/gopsutil/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Partitions(all bool) ([]PartitionStat, error) {
|
|
||||||
return PartitionsWithContext(context.Background(), all)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartitionsWithContext returns disk partition.
|
// PartitionsWithContext returns disk partition.
|
||||||
// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906
|
// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906
|
||||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||||
@ -97,10 +93,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
// statinfo->devinfo->devstat
|
// statinfo->devinfo->devstat
|
||||||
// /usr/include/devinfo.h
|
// /usr/include/devinfo.h
|
||||||
|
@ -218,13 +218,6 @@ var fsTypeMap = map[int64]string{
|
|||||||
ZFS_SUPER_MAGIC: "zfs", /* 0x2FC12FC1 local */
|
ZFS_SUPER_MAGIC: "zfs", /* 0x2FC12FC1 local */
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
|
||||||
func Partitions(all bool) ([]PartitionStat, error) {
|
|
||||||
return PartitionsWithContext(context.Background(), all)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||||
useMounts := false
|
useMounts := false
|
||||||
|
|
||||||
@ -354,10 +347,6 @@ func getFileSystems() ([]string, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
filename := common.HostProc("diskstats")
|
filename := common.HostProc("diskstats")
|
||||||
lines, err := common.ReadLines(filename)
|
lines, err := common.ReadLines(filename)
|
||||||
|
@ -11,12 +11,6 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Partitions(all bool) ([]PartitionStat, error) {
|
|
||||||
return PartitionsWithContext(context.Background(), all)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartitionsWithContext returns disk partition.
|
|
||||||
// 'all' argument is ignored, see: https://github.com/giampaolo/psutil/issues/906
|
|
||||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||||
var ret []PartitionStat
|
var ret []PartitionStat
|
||||||
|
|
||||||
@ -74,10 +68,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
ret := make(map[string]IOCountersStat)
|
ret := make(map[string]IOCountersStat)
|
||||||
|
|
||||||
@ -130,10 +120,6 @@ func parseDiskstats(buf []byte) (Diskstats, error) {
|
|||||||
return ds, nil
|
return ds, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Usage(path string) (*UsageStat, error) {
|
|
||||||
return UsageWithContext(context.Background(), path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
||||||
stat := unix.Statfs_t{}
|
stat := unix.Statfs_t{}
|
||||||
err := unix.Statfs(path, &stat)
|
err := unix.Statfs(path, &stat)
|
||||||
|
@ -38,10 +38,6 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Partitions(all bool) ([]PartitionStat, error) {
|
|
||||||
return PartitionsWithContext(context.Background(), all)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||||
ret := make([]PartitionStat, 0, _DEFAULT_NUM_MOUNTS)
|
ret := make([]PartitionStat, 0, _DEFAULT_NUM_MOUNTS)
|
||||||
|
|
||||||
@ -83,18 +79,10 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|||||||
return ret, err
|
return ret, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func Usage(path string) (*UsageStat, error) {
|
|
||||||
return UsageWithContext(context.Background(), path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
||||||
statvfs := unix.Statvfs_t{}
|
statvfs := unix.Statvfs_t{}
|
||||||
if err := unix.Statvfs(path, &statvfs); err != nil {
|
if err := unix.Statvfs(path, &statvfs); err != nil {
|
||||||
|
@ -9,13 +9,6 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
||||||
stat := unix.Statfs_t{}
|
stat := unix.Statfs_t{}
|
||||||
err := unix.Statfs(path, &stat)
|
err := unix.Statfs(path, &stat)
|
||||||
|
@ -43,10 +43,6 @@ type diskPerformance struct {
|
|||||||
alignmentPadding uint32 // necessary for 32bit support, see https://github.com/elastic/beats/pull/16553
|
alignmentPadding uint32 // necessary for 32bit support, see https://github.com/elastic/beats/pull/16553
|
||||||
}
|
}
|
||||||
|
|
||||||
func Usage(path string) (*UsageStat, error) {
|
|
||||||
return UsageWithContext(context.Background(), path)
|
|
||||||
}
|
|
||||||
|
|
||||||
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
||||||
lpFreeBytesAvailable := int64(0)
|
lpFreeBytesAvailable := int64(0)
|
||||||
lpTotalNumberOfBytes := int64(0)
|
lpTotalNumberOfBytes := int64(0)
|
||||||
@ -73,10 +69,6 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Partitions(all bool) ([]PartitionStat, error) {
|
|
||||||
return PartitionsWithContext(context.Background(), all)
|
|
||||||
}
|
|
||||||
|
|
||||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||||
var ret []PartitionStat
|
var ret []PartitionStat
|
||||||
lpBuffer := make([]byte, 254)
|
lpBuffer := make([]byte, 254)
|
||||||
@ -139,10 +131,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func IOCounters(names ...string) (map[string]IOCountersStat, error) {
|
|
||||||
return IOCountersWithContext(context.Background(), names...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||||
// https://github.com/giampaolo/psutil/blob/544e9daa4f66a9f80d7bf6c7886d693ee42f0a13/psutil/arch/windows/disk.c#L83
|
// https://github.com/giampaolo/psutil/blob/544e9daa4f66a9f80d7bf6c7886d693ee42f0a13/psutil/arch/windows/disk.c#L83
|
||||||
drivemap := make(map[string]IOCountersStat, 0)
|
drivemap := make(map[string]IOCountersStat, 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user