mirror of https://github.com/shirou/gopsutil
Merge pull request #1205 from mmorel-35/master
enable more linters, report coverage and cache modstags/v3.21.12 v3.21.12
commit
2f8da0a394
@ -1,86 +1,89 @@
|
||||
//go:build aix
|
||||
// +build aix
|
||||
|
||||
package disk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/power-devops/perfstat"
|
||||
"github.com/shirou/gopsutil/v3/internal/common"
|
||||
"github.com/power-devops/perfstat"
|
||||
"github.com/shirou/gopsutil/v3/internal/common"
|
||||
)
|
||||
|
||||
var FSType map[int]string
|
||||
|
||||
func init() {
|
||||
FSType = map[int]string{0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc",
|
||||
16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs",
|
||||
33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
|
||||
39: "ahafs", 40: "sterm-nfs", 41: "asmfs" }
|
||||
FSType = map[int]string{
|
||||
0: "jfs2", 1: "namefs", 2: "nfs", 3: "jfs", 5: "cdrom", 6: "proc",
|
||||
16: "special-fs", 17: "cache-fs", 18: "nfs3", 19: "automount-fs", 20: "pool-fs", 32: "vxfs",
|
||||
33: "veritas-fs", 34: "udfs", 35: "nfs4", 36: "nfs4-pseudo", 37: "smbfs", 38: "mcr-pseudofs",
|
||||
39: "ahafs", 40: "sterm-nfs", 41: "asmfs",
|
||||
}
|
||||
}
|
||||
|
||||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||
f, err := perfstat.FileSystemStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := make([]PartitionStat, len(f))
|
||||
f, err := perfstat.FileSystemStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ret := make([]PartitionStat, len(f))
|
||||
|
||||
for _, fs := range f {
|
||||
fstyp, exists := FSType[fs.FSType]
|
||||
if ! exists {
|
||||
fstyp = "unknown"
|
||||
}
|
||||
info := PartitionStat{
|
||||
Device: fs.Device,
|
||||
Mountpoint: fs.MountPoint,
|
||||
Fstype: fstyp,
|
||||
}
|
||||
ret = append(ret,info)
|
||||
}
|
||||
for _, fs := range f {
|
||||
fstyp, exists := FSType[fs.FSType]
|
||||
if !exists {
|
||||
fstyp = "unknown"
|
||||
}
|
||||
info := PartitionStat{
|
||||
Device: fs.Device,
|
||||
Mountpoint: fs.MountPoint,
|
||||
Fstype: fstyp,
|
||||
}
|
||||
ret = append(ret, info)
|
||||
}
|
||||
|
||||
return ret, err
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func IOCountersWithContext(ctx context.Context, names ...string) (map[string]IOCountersStat, error) {
|
||||
return nil, common.ErrNotImplementedError
|
||||
return nil, common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) {
|
||||
f, err := perfstat.FileSystemStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := perfstat.FileSystemStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
blocksize := uint64(512)
|
||||
for _, fs := range f {
|
||||
if path == fs.MountPoint {
|
||||
fstyp, exists := FSType[fs.FSType]
|
||||
if ! exists {
|
||||
fstyp = "unknown"
|
||||
}
|
||||
info := UsageStat{
|
||||
Path: path,
|
||||
Fstype: fstyp,
|
||||
Total: uint64(fs.TotalBlocks) * blocksize,
|
||||
Free: uint64(fs.FreeBlocks) * blocksize,
|
||||
Used: uint64(fs.TotalBlocks - fs.FreeBlocks) * blocksize,
|
||||
InodesTotal: uint64(fs.TotalInodes),
|
||||
InodesFree: uint64(fs.FreeInodes),
|
||||
InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes),
|
||||
}
|
||||
info.UsedPercent = (float64(info.Used) / float64(info.Total)) * 100.0
|
||||
info.InodesUsedPercent = (float64(info.InodesUsed) / float64(info.InodesTotal)) * 100.0
|
||||
return &info, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("mountpoint %s not found", path)
|
||||
blocksize := uint64(512)
|
||||
for _, fs := range f {
|
||||
if path == fs.MountPoint {
|
||||
fstyp, exists := FSType[fs.FSType]
|
||||
if !exists {
|
||||
fstyp = "unknown"
|
||||
}
|
||||
info := UsageStat{
|
||||
Path: path,
|
||||
Fstype: fstyp,
|
||||
Total: uint64(fs.TotalBlocks) * blocksize,
|
||||
Free: uint64(fs.FreeBlocks) * blocksize,
|
||||
Used: uint64(fs.TotalBlocks-fs.FreeBlocks) * blocksize,
|
||||
InodesTotal: uint64(fs.TotalInodes),
|
||||
InodesFree: uint64(fs.FreeInodes),
|
||||
InodesUsed: uint64(fs.TotalInodes - fs.FreeInodes),
|
||||
}
|
||||
info.UsedPercent = (float64(info.Used) / float64(info.Total)) * 100.0
|
||||
info.InodesUsedPercent = (float64(info.InodesUsed) / float64(info.InodesTotal)) * 100.0
|
||||
return &info, nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("mountpoint %s not found", path)
|
||||
}
|
||||
|
||||
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
||||
func LabelWithContext(ctx context.Context, name string) (string, error) {
|
||||
return "", common.ErrNotImplementedError
|
||||
return "", common.ErrNotImplementedError
|
||||
}
|
||||
|
@ -1,58 +1,59 @@
|
||||
//go:build aix
|
||||
// +build aix
|
||||
|
||||
package mem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"context"
|
||||
|
||||
"github.com/power-devops/perfstat"
|
||||
"github.com/power-devops/perfstat"
|
||||
)
|
||||
|
||||
func VirtualMemory() (*VirtualMemoryStat, error) {
|
||||
return VirtualMemoryWithContext(context.Background())
|
||||
return VirtualMemoryWithContext(context.Background())
|
||||
}
|
||||
|
||||
func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
|
||||
m, err := perfstat.MemoryTotalStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pagesize := uint64(4096)
|
||||
ret := VirtualMemoryStat{
|
||||
Total: uint64(m.RealTotal) * pagesize,
|
||||
Available: uint64(m.RealAvailable) * pagesize,
|
||||
Free: uint64(m.RealFree) * pagesize,
|
||||
Used: uint64(m.RealInUse) * pagesize,
|
||||
UsedPercent: 100 * float64(m.RealInUse) / float64(m.RealTotal),
|
||||
Active: uint64(m.VirtualActive) * pagesize,
|
||||
SwapTotal: uint64(m.PgSpTotal) * pagesize,
|
||||
SwapFree: uint64(m.PgSpFree) * pagesize,
|
||||
}
|
||||
return &ret, nil
|
||||
m, err := perfstat.MemoryTotalStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pagesize := uint64(4096)
|
||||
ret := VirtualMemoryStat{
|
||||
Total: uint64(m.RealTotal) * pagesize,
|
||||
Available: uint64(m.RealAvailable) * pagesize,
|
||||
Free: uint64(m.RealFree) * pagesize,
|
||||
Used: uint64(m.RealInUse) * pagesize,
|
||||
UsedPercent: 100 * float64(m.RealInUse) / float64(m.RealTotal),
|
||||
Active: uint64(m.VirtualActive) * pagesize,
|
||||
SwapTotal: uint64(m.PgSpTotal) * pagesize,
|
||||
SwapFree: uint64(m.PgSpFree) * pagesize,
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
func SwapMemory() (*SwapMemoryStat, error) {
|
||||
return SwapMemoryWithContext(context.Background())
|
||||
return SwapMemoryWithContext(context.Background())
|
||||
}
|
||||
|
||||
func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
|
||||
m, err := perfstat.MemoryTotalStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pagesize := uint64(4096)
|
||||
swapUsed := uint64(m.PgSpTotal - m.PgSpFree - m.PgSpRsvd) * pagesize
|
||||
swapTotal := uint64(m.PgSpTotal) * pagesize
|
||||
ret := SwapMemoryStat{
|
||||
Total: swapTotal,
|
||||
Free: uint64(m.PgSpFree) * pagesize,
|
||||
Used: swapUsed,
|
||||
UsedPercent: float64(100 * swapUsed) / float64(swapTotal),
|
||||
Sin: uint64(m.PgSpIn),
|
||||
Sout: uint64(m.PgSpOut),
|
||||
PgIn: uint64(m.PageIn),
|
||||
PgOut: uint64(m.PageOut),
|
||||
PgFault: uint64(m.PageFaults),
|
||||
}
|
||||
return &ret, nil
|
||||
m, err := perfstat.MemoryTotalStat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pagesize := uint64(4096)
|
||||
swapUsed := uint64(m.PgSpTotal-m.PgSpFree-m.PgSpRsvd) * pagesize
|
||||
swapTotal := uint64(m.PgSpTotal) * pagesize
|
||||
ret := SwapMemoryStat{
|
||||
Total: swapTotal,
|
||||
Free: uint64(m.PgSpFree) * pagesize,
|
||||
Used: swapUsed,
|
||||
UsedPercent: float64(100*swapUsed) / float64(swapTotal),
|
||||
Sin: uint64(m.PgSpIn),
|
||||
Sout: uint64(m.PgSpOut),
|
||||
PgIn: uint64(m.PageIn),
|
||||
PgOut: uint64(m.PageOut),
|
||||
PgFault: uint64(m.PageFaults),
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue