Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions disk/disk_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
42 changes: 42 additions & 0 deletions disk/disk_aix_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,55 @@

package disk

/*
#include <unistd.h>
*/
import "C"

import (
"context"
"fmt"

"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() {
Expand Down
4 changes: 4 additions & 0 deletions disk/disk_aix_nocgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down