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