diff --git a/disk/disk_aix.go b/disk/disk_aix.go index 1ef178904d..a32b0517fe 100644 --- a/disk/disk_aix.go +++ b/disk/disk_aix.go @@ -11,10 +11,6 @@ import ( "github.com/shirou/gopsutil/v4/internal/common" ) -func IOCountersWithContext(_ context.Context, _ ...string) (map[string]IOCountersStat, error) { - return nil, common.ErrNotImplementedError -} - func LabelWithContext(_ context.Context, _ string) (string, error) { return "", common.ErrNotImplementedError } diff --git a/disk/disk_aix_cgo.go b/disk/disk_aix_cgo.go index 1522004173..700d13739c 100644 --- a/disk/disk_aix_cgo.go +++ b/disk/disk_aix_cgo.go @@ -3,6 +3,11 @@ package disk +/* +#include +*/ +import "C" + import ( "context" "fmt" @@ -10,6 +15,43 @@ import ( "github.com/power-devops/perfstat" ) +func IOCountersWithContext(_ context.Context, names ...string) (map[string]IOCountersStat, error) { + disks, err := perfstat.DiskStat() + if err != nil { + return nil, err + } + + nameSet := make(map[string]bool, len(names)) + for _, n := range names { + nameSet[n] = true + } + + clkTck := uint64(C.sysconf(C._SC_CLK_TCK)) + + ret := make(map[string]IOCountersStat, len(disks)) + for _, d := range disks { + if len(nameSet) > 0 && !nameSet[d.Name] { + continue + } + + ret[d.Name] = IOCountersStat{ + Name: d.Name, + ReadCount: uint64(d.XRate), + WriteCount: uint64(d.Xfers - d.XRate), + ReadBytes: uint64(d.Rblks) * uint64(d.BSize), + WriteBytes: uint64(d.Wblks) * uint64(d.BSize), + // perfstat Rserv, Wserv, and WqTime are in nanoseconds; + // IOCountersStat expects milliseconds. + ReadTime: uint64(d.Rserv) / 1_000_000, + WriteTime: uint64(d.Wserv) / 1_000_000, + IoTime: uint64(d.Time) * 1000 / clkTck, // d.Time is in kernel ticks; convert to ms + WeightedIO: uint64(d.WqTime) / 1_000_000, + IopsInProgress: uint64(d.QDepth), + } + } + return ret, nil +} + var FSType map[int]string func init() { diff --git a/disk/disk_aix_nocgo.go b/disk/disk_aix_nocgo.go index 75b651ab23..4fe1258c8a 100644 --- a/disk/disk_aix_nocgo.go +++ b/disk/disk_aix_nocgo.go @@ -26,6 +26,10 @@ var ( } ) +func IOCountersWithContext(_ context.Context, _ ...string) (map[string]IOCountersStat, error) { + return nil, common.ErrNotImplementedError +} + func PartitionsWithContext(ctx context.Context, _ bool) ([]PartitionStat, error) { var ret []PartitionStat