mirror of https://github.com/shirou/gopsutil
Merge branch 'shirou:master' into patch-1
commit
b6c524eda4
@ -1,18 +0,0 @@
|
|||||||
# v2 to v3 changes
|
|
||||||
|
|
||||||
- v3 is in the `v3` directory
|
|
||||||
|
|
||||||
- [process] RLimit is now uint64 ([#364](https://github.com/shirou/gopsutil/issues/364))
|
|
||||||
- [process] Remove process.NetIOCounters ([#429](https://github.com/shirou/gopsutil/issues/429))
|
|
||||||
- [docker] fix typo of memoryLimitInBbytes ([#464](https://github.com/shirou/gopsutil/issues/464))
|
|
||||||
- [mem] VirtualMemoryStat JSON fields capitalization ([#545](https://github.com/shirou/gopsutil/issues/545))
|
|
||||||
- various JSON field name and some of Variable name have been changed. see v3migration.sh
|
|
||||||
- [all] various kind of platform dependent values/constants such as process.GetWin32Proc is now private. see v3migration.sh
|
|
||||||
- [process] process.Status() now returns []string. and status string is "Running", not just "R". defined in process.go. ([#596](https://github.com/shirou/gopsutil/issues/596))
|
|
||||||
- [docker] `CgroupCPU()` now returns `*CgroupCPUStat` with Usage ([#590](https://github.com/shirou/gopsutil/issues/590) and [#581](https://github.com/shirou/gopsutil/issues/581))
|
|
||||||
- [disk] `disk.Opts` is now string[], not string. (related to [#955](https://github.com/shirou/gopsutil/issues/955))
|
|
||||||
- [host] Fixed temperature sensors detection in Linux ([#905](https://github.com/shirou/gopsutil/issues/905))
|
|
||||||
- [disk] `GetDiskSerialNumber()` is now `SerialNumber()` and spread to all platforms
|
|
||||||
- [disk] `GetLabel ()` is now `Label()` and spread to all platform
|
|
||||||
- [net] Change net.InterfaceStat.Addrs to InterfaceAddrList ([#226](https://github.com/shirou/gopsutil/issues/226))
|
|
||||||
- [cpu] Removed windows-specific `ProcInfo()`
|
|
@ -1,106 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"go/ast"
|
|
||||||
"go/format"
|
|
||||||
"go/parser"
|
|
||||||
"go/token"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"golang.org/x/tools/go/ast/astutil"
|
|
||||||
)
|
|
||||||
|
|
||||||
// https://github.com/shirou/gopsutil/issues/429
|
|
||||||
func issue429() error {
|
|
||||||
f := func(filename string) error {
|
|
||||||
fset := token.NewFileSet()
|
|
||||||
expr, err := parser.ParseFile(fset, filename, nil, parser.ParseComments)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
n := astutil.Apply(expr, func(cr *astutil.Cursor) bool {
|
|
||||||
if cr.Name() == "Decls" {
|
|
||||||
switch n := cr.Node().(type) {
|
|
||||||
case *ast.FuncDecl:
|
|
||||||
if n.Name.Name == "NetIOCounters" || n.Name.Name == ("NetIOCountersWithContext") {
|
|
||||||
cr.Delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}, nil)
|
|
||||||
return replace(filename, fset, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
root := "process/"
|
|
||||||
fnames := []string{"process.go", "process_darwin.go", "process_fallback.go", "process_freebsd.go", "process_linux.go", "process_openbsd.go", "process_bsd.go", "process_posix.go", "process_windows.go", "process_test.go"}
|
|
||||||
for _, fname := range fnames {
|
|
||||||
if err := f(root + fname); err != nil {
|
|
||||||
log.Fatalln("run 429:", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func issueRemoveUnusedValue() error {
|
|
||||||
f := func(filename string) error {
|
|
||||||
fset := token.NewFileSet()
|
|
||||||
expr, err := parser.ParseFile(fset, filename, nil, parser.ParseComments)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
n := astutil.Apply(expr, func(cr *astutil.Cursor) bool {
|
|
||||||
if cr.Name() == "Decls" {
|
|
||||||
switch n := cr.Node().(type) {
|
|
||||||
case *ast.GenDecl:
|
|
||||||
if n.Tok != token.TYPE {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
ts := n.Specs[0].(*ast.TypeSpec)
|
|
||||||
if ts.Name.Name == "SystemProcessInformation" {
|
|
||||||
cr.Delete()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}, nil)
|
|
||||||
return replace(filename, fset, n)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := f("process/process_windows.go"); err != nil {
|
|
||||||
log.Fatalln("run 429:", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func replace(filename string, fset *token.FileSet, n ast.Node) error {
|
|
||||||
if err := os.Remove(filename); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fp, err := os.Create(filename)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer fp.Close()
|
|
||||||
if err := format.Node(fp, fset, n); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fp.WriteString("\n")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
flag.Parse()
|
|
||||||
for _, n := range flag.Args() {
|
|
||||||
fmt.Println("issue:" + n)
|
|
||||||
switch n {
|
|
||||||
case "429":
|
|
||||||
issue429()
|
|
||||||
case "issueRemoveUnusedValue":
|
|
||||||
issueRemoveUnusedValue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,171 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
# this scripts is used when migrating v2 to v3.
|
|
||||||
# usage: cd ${GOPATH}/src/github.com/shirou/gopsutil && bash tools/v3migration/v3migration.sh
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd)"
|
|
||||||
ROOT=$(cd "${DIR}"/../.. && pwd)
|
|
||||||
|
|
||||||
|
|
||||||
## 1. refresh
|
|
||||||
cd "${ROOT}"
|
|
||||||
|
|
||||||
/bin/rm -rf v3
|
|
||||||
|
|
||||||
## 2. copy directories
|
|
||||||
# docker is removed, #464 will be fixed
|
|
||||||
mkdir -p v3
|
|
||||||
cp -rp cpu disk docker host internal load mem net process winservices v3
|
|
||||||
cp Makefile v3
|
|
||||||
|
|
||||||
# build migartion tool
|
|
||||||
go build -o v3/v3migration "${DIR}"/v3migration.go
|
|
||||||
|
|
||||||
|
|
||||||
V3DIR=$(cd "${ROOT}"/v3 && pwd)
|
|
||||||
cd "${V3DIR}"
|
|
||||||
|
|
||||||
## 3. mod
|
|
||||||
go mod init
|
|
||||||
|
|
||||||
### change import path
|
|
||||||
find . -name "*.go" -print0 | xargs -0 -I@ sed -i 's|"github.com/shirou/gopsutil/|"github.com/shirou/gopsutil/v3/|g' @
|
|
||||||
|
|
||||||
############ Issues
|
|
||||||
|
|
||||||
# #429 process.NetIOCounters is pointless on Linux
|
|
||||||
./v3migration "$(pwd)" 429
|
|
||||||
sed -i '/NetIOCounters/d' process/process.go
|
|
||||||
sed -i "/github.com\/shirou\/gopsutil\/v3\/net/d" process/process_bsd.go
|
|
||||||
|
|
||||||
|
|
||||||
# #464 CgroupMem : fix typo and wrong file names
|
|
||||||
sed -i 's|memoryLimitInBbytes|memoryLimitInBytes|g' docker/docker.go
|
|
||||||
sed -i 's|memoryLimitInBbytes|memory.limit_in_bytes|g' docker/docker_linux.go
|
|
||||||
sed -i 's|memoryFailcnt|memory.failcnt|g' docker/docker_linux.go
|
|
||||||
|
|
||||||
|
|
||||||
# fix #346
|
|
||||||
sed -i 's/Soft int32/Soft uint64/' process/process.go
|
|
||||||
sed -i 's/Hard int32/Hard uint64/' process/process.go
|
|
||||||
sed -i 's| //TODO too small. needs to be uint64||' process/process.go
|
|
||||||
sed -i 's|limitToInt(val string) (int32, error)|limitToUint(val string) (uint64, error)|' process/process_*.go
|
|
||||||
sed -i 's|limitToInt|limitToUint|' process/process_*.go
|
|
||||||
sed -i 's|return int32(res), nil|return uint64(res), nil|' process/process_*.go
|
|
||||||
sed -i 's|math.MaxInt32|math.MaxUint64|' process/process_*.go
|
|
||||||
|
|
||||||
# fix #545
|
|
||||||
# variable names
|
|
||||||
sed -i 's|WritebackTmp|WriteBackTmp|g' mem/*.go
|
|
||||||
sed -i 's|Writeback|WriteBack|g' mem/*.go
|
|
||||||
sed -i 's|SReclaimable|Sreclaimable|g' mem/*.go
|
|
||||||
sed -i 's|SUnreclaim|Sunreclaim|g' mem/*.go
|
|
||||||
sed -i 's|VMallocTotal|VmallocTotal|g' mem/*.go
|
|
||||||
sed -i 's|VMallocUsed|VmallocUsed|g' mem/*.go
|
|
||||||
sed -i 's|VMallocChunk|VmallocChunk|g' mem/*.go
|
|
||||||
|
|
||||||
# json field name
|
|
||||||
sed -i 's|hostid|hostId|g' host/host.go
|
|
||||||
sed -i 's|hostid|hostId|g' host/host_test.go
|
|
||||||
sed -i 's|sensorTemperature|temperature|g' host/host.go
|
|
||||||
sed -i 's|sensorTemperature|temperature|g' host/host_test.go
|
|
||||||
|
|
||||||
sed -i 's|writeback|writeBack|g' mem/*.go
|
|
||||||
sed -i 's|writeBacktmp|writeBackTmp|g' mem/*.go
|
|
||||||
sed -i 's|pagetables|pageTables|g' mem/*.go
|
|
||||||
sed -i 's|swapcached|swapCached|g' mem/*.go
|
|
||||||
sed -i 's|commitlimit|commitLimit|g' mem/*.go
|
|
||||||
sed -i 's|committedas|committedAS|g' mem/*.go
|
|
||||||
sed -i 's|hightotal|highTotal|g' mem/*.go
|
|
||||||
sed -i 's|highfree|highFree|g' mem/*.go
|
|
||||||
sed -i 's|lowtotal|lowTotal|g' mem/*.go
|
|
||||||
sed -i 's|lowfree|lowFree|g' mem/*.go
|
|
||||||
sed -i 's|swaptotal|swapTotal|g' mem/*.go
|
|
||||||
sed -i 's|swapfree|swapFree|g' mem/*.go
|
|
||||||
sed -i 's|vmalloctotal|vmallocTotal|g' mem/*.go
|
|
||||||
sed -i 's|vmallocused|vmallocUsed|g' mem/*.go
|
|
||||||
sed -i 's|vmallocchunk|vmallocChunk|g' mem/*.go
|
|
||||||
sed -i 's|hugepagestotal|hugePagesTotal|g' mem/*.go
|
|
||||||
sed -i 's|hugepagesfree|hugePagesFree|g' mem/*.go
|
|
||||||
sed -i 's|hugepagesize|hugePageSize|g' mem/*.go
|
|
||||||
sed -i 's|pgin|pgIn|g' mem/*.go
|
|
||||||
sed -i 's|pgout|pgOut|g' mem/*.go
|
|
||||||
sed -i 's|pgfault|pgFault|g' mem/*.go
|
|
||||||
sed -i 's|pgmajfault|pgMajFault|g' mem/*.go
|
|
||||||
|
|
||||||
sed -i 's|hardwareaddr|hardwareAddr|g' net/*.go
|
|
||||||
sed -i 's|conntrackCount|connTrackCount|g' net/*.go
|
|
||||||
sed -i 's|conntrackMax|connTrackMax|g' net/*.go
|
|
||||||
sed -i 's|delete_list|deleteList|g' net/*.go
|
|
||||||
sed -i 's|insert_failed|insertFailed|g' net/*.go
|
|
||||||
sed -i 's|early_drop|earlyDrop|g' net/*.go
|
|
||||||
sed -i 's|expect_create|expectCreate|g' net/*.go
|
|
||||||
sed -i 's|expect_delete|expectDelete|g' net/*.go
|
|
||||||
sed -i 's|search_restart|searchRestart|g' net/*.go
|
|
||||||
sed -i 's|icmp_error|icmpError|g' net/*.go
|
|
||||||
sed -i 's|expect_new|expectNew|g' net/*.go
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# fix no more public API/types/constants defined only for some platforms
|
|
||||||
|
|
||||||
sed -i 's|CTLKern|ctlKern|g' cpu/*.go
|
|
||||||
sed -i 's|CPNice|cpNice|g' cpu/*.go
|
|
||||||
sed -i 's|CPSys|cpSys|g' cpu/*.go
|
|
||||||
sed -i 's|CPIntr|cpIntr|g' cpu/*.go
|
|
||||||
sed -i 's|CPIdle|cpIdle|g' cpu/*.go
|
|
||||||
sed -i 's|CPUStates|cpUStates|g' cpu/*.go
|
|
||||||
sed -i 's|CTLKern|ctlKern|g' cpu/cpu_openbsd.go
|
|
||||||
sed -i 's|CTLHw|ctlHw|g' cpu/cpu_openbsd.go
|
|
||||||
sed -i 's|SMT|sMT|g' cpu/cpu_openbsd.go
|
|
||||||
sed -i 's|KernCptime|kernCptime|g' cpu/cpu_openbsd.go
|
|
||||||
sed -i 's|KernCptime2|kernCptime2|g' cpu/cpu_openbsd.go
|
|
||||||
sed -i 's|Win32_Processor|win32Processor|g' cpu/cpu_windows.go
|
|
||||||
|
|
||||||
sed -i 's|DEVSTAT_NO_DATA|devstat_NO_DATA|g' disk/*.go
|
|
||||||
sed -i 's|DEVSTAT_READ|devstat_READ|g' disk/*.go
|
|
||||||
sed -i 's|DEVSTAT_WRITE|devstat_WRITE|g' disk/*.go
|
|
||||||
sed -i 's|DEVSTAT_FREE|devstat_FREE|g' disk/*.go
|
|
||||||
sed -i 's|Devstat|devstat|g' disk/*.go
|
|
||||||
sed -i 's|Bintime|bintime|g' disk/*.go
|
|
||||||
sed -i 's|SectorSize|sectorSize|g' disk/disk_linux.go
|
|
||||||
sed -i 's|FileFileCompression|fileFileCompression|g' disk/disk_windows.go
|
|
||||||
sed -i 's|FileReadOnlyVolume|fileReadOnlyVolume|g' disk/disk_windows.go
|
|
||||||
|
|
||||||
sed -i 's|USER_PROCESS|user_PROCESS|g' host/host_*.go
|
|
||||||
sed -i 's|LSB|lsbStruct|g' host/host_linux*
|
|
||||||
|
|
||||||
sed -i 's| BcacheStats | bcacheStats |g' mem/*.go
|
|
||||||
|
|
||||||
sed -i 's|TCPStatuses|tcpStatuses|g' net/*.go
|
|
||||||
sed -i 's|CT_ENTRIES|ctENTRIES|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_SEARCHED|ctSEARCHED|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_FOUND|ctFOUND|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_NEW|ctNEW|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_INVALID|ctINVALID|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_IGNORE|ctIGNORE|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_DELETE|ctDELETE|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_DELETE_LIST|ctDELETE_LIST|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_INSERT|ctINSERT|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_INSERT_FAILED|ctINSERT_FAILED|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_DROP|ctDROP|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_EARLY_DROP|ctEARLY_DROP|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_ICMP_ERROR|ctICMP_ERROR|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_EXPECT_NEW|ctEXPECT_NEW|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_EXPECT_CREATE|ctEXPECT_CREATE|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_EXPECT_DELETE|ctEXPECT_DELETE|g' net/net_linux.go
|
|
||||||
sed -i 's|CT_SEARCH_RESTART|ctSEARCH_RESTART|g' net/net_linux.go
|
|
||||||
|
|
||||||
sed -i 's|PageSize|pageSize|g' process/process_*.go
|
|
||||||
sed -i 's|PrioProcess|prioProcess|g' process/process_*.go
|
|
||||||
sed -i 's|ClockTicks|clockTicks|g' process/process_*.go
|
|
||||||
|
|
||||||
|
|
||||||
./v3migration "$(pwd)" issueRemoveUnusedValue
|
|
||||||
|
|
||||||
|
|
||||||
############ SHOULD BE FIXED BY HAND
|
|
@ -1,26 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# see http://www.songmu.jp/riji/entry/2015-01-15-goveralls-multi-package.html
|
|
||||||
|
|
||||||
set -e
|
|
||||||
# cleanup
|
|
||||||
cleanup() {
|
|
||||||
if [ "$tmpprof" != "" ] && [ -f "$tmpprof" ]; then
|
|
||||||
rm -f "$tmpprof"
|
|
||||||
fi
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
trap cleanup INT QUIT TERM EXIT
|
|
||||||
|
|
||||||
# メインの処理
|
|
||||||
prof=${1:-".profile.cov"}
|
|
||||||
echo "mode: count" > "$prof"
|
|
||||||
gopath1=$(echo "$GOPATH" | cut -d: -f1)
|
|
||||||
for pkg in $(go list ./...); do
|
|
||||||
tmpprof="$gopath1/src/$pkg/profile.tmp"
|
|
||||||
go test -covermode=count -coverprofile="$tmpprof" "$pkg"
|
|
||||||
if [ -f "$tmpprof" ]; then
|
|
||||||
tail -n +2 "$tmpprof" >> "$prof"
|
|
||||||
rm "$tmpprof"
|
|
||||||
fi
|
|
||||||
done
|
|
@ -0,0 +1,68 @@
|
|||||||
|
System Model: IBM pSeries (emulated by qemu)
|
||||||
|
Machine Serial Number: Not Available
|
||||||
|
Processor Type: PowerPC_POWER8
|
||||||
|
Processor Implementation Mode: POWER 8
|
||||||
|
Processor Version: PV_8_Compat
|
||||||
|
Number Of Processors: 4
|
||||||
|
Processor Clock Speed: 1000 MHz
|
||||||
|
CPU Type: 64-bit
|
||||||
|
Kernel Type: 64-bit
|
||||||
|
LPAR Info: 0 aix_7200-04-02-2027
|
||||||
|
Memory Size: 4096 MB
|
||||||
|
Good Memory Size: 4096 MB
|
||||||
|
Platform Firmware level: Not Available
|
||||||
|
Firmware Version: SLOF,HEAD
|
||||||
|
Console Login: enable
|
||||||
|
Auto Restart: true
|
||||||
|
Full Core: false
|
||||||
|
NX Crypto Acceleration: Not Capable
|
||||||
|
In-Core Crypto Acceleration: Capable, but not Enabled
|
||||||
|
|
||||||
|
en0
|
||||||
|
Network Information
|
||||||
|
Host Name: aix72-dylan
|
||||||
|
IP Address: 192.168.124.53
|
||||||
|
Sub Netmask:
|
||||||
|
Gateway: 192.168.124.1
|
||||||
|
Name Server:
|
||||||
|
Domain Name:
|
||||||
|
|
||||||
|
Paging Space Information
|
||||||
|
Total Paging Space: 512MB
|
||||||
|
Percent Used: 1%
|
||||||
|
|
||||||
|
Volume Groups Information
|
||||||
|
==============================================================================
|
||||||
|
Active VGs
|
||||||
|
==============================================================================
|
||||||
|
rootvg:
|
||||||
|
PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION
|
||||||
|
hdisk0 active 999 809 199..193..17..200..200
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
INSTALLED RESOURCE LIST
|
||||||
|
|
||||||
|
The following resources are installed on the machine.
|
||||||
|
+/- = Added or deleted from Resource List.
|
||||||
|
* = Diagnostic support not available.
|
||||||
|
|
||||||
|
Model Architecture: chrp
|
||||||
|
Model Implementation: Uni-Processor, PCI bus
|
||||||
|
|
||||||
|
+ sys0 System Object
|
||||||
|
+ sysplanar0 System Planar
|
||||||
|
* vio0 Virtual I/O Bus
|
||||||
|
* ent0 Virtual I/O Ethernet Adapter (l-lan)
|
||||||
|
* vscsi0 Virtual SCSI Client Adapter
|
||||||
|
* cd0 Virtual SCSI Optical Served by VIO Server
|
||||||
|
* vsa0 LPAR Virtual Serial Adapter
|
||||||
|
* vty0 Asynchronous Terminal
|
||||||
|
* pci0 PCI Bus
|
||||||
|
* scsi0 qemu_virtio-scsi-pci:0000:00:02.0 Virtio SCSI Client Adapter (f41a0800)
|
||||||
|
* hdisk0 qemu_virtio-scsi-pci:0000:00:02.0-LW_0 MPIO Other Virtio SCSI Disk Drive
|
||||||
|
+ L2cache0 L2 Cache
|
||||||
|
+ mem0 Memory
|
||||||
|
+ proc0 Processor
|
||||||
|
+ proc1 Processor
|
||||||
|
+ proc2 Processor
|
||||||
|
+ proc3 Processor
|
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
AIX aix72-dylan 2 7 000000000000 05/15/24
|
||||||
|
|
||||||
|
System configuration: lcpu=4 ent=4.00 mode=Capped
|
||||||
|
|
||||||
|
11:19:03 cpu %usr %sys %wio %idle physc %entc
|
||||||
|
11:19:13 0 1 11 0 88 1.00 25.0
|
||||||
|
1 0 0 0 100 1.00 25.0
|
||||||
|
2 0 0 0 100 1.00 25.0
|
||||||
|
3 0 0 0 100 1.00 25.0
|
||||||
|
- 0 3 0 97 4.00 100.0
|
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
AIX aix72-dylan 2 7 000000000000 05/15/24
|
||||||
|
|
||||||
|
System configuration: lcpu=4 ent=4.00 mode=Capped
|
||||||
|
|
||||||
|
11:19:44 %usr %sys %wio %idle physc %entc
|
||||||
|
11:19:54 0 3 0 96 4.00 100.0
|
@ -1,22 +1,50 @@
|
|||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
//go:build aix
|
//go:build aix
|
||||||
// +build aix
|
|
||||||
|
|
||||||
package disk
|
package disk
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/internal/common"
|
"github.com/shirou/gopsutil/v4/internal/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
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 SerialNumberWithContext(ctx context.Context, name string) (string, error) {
|
func LabelWithContext(ctx context.Context, name string) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func LabelWithContext(ctx context.Context, name string) (string, error) {
|
// Using lscfg and a device name, we can get the device information
|
||||||
return "", common.ErrNotImplementedError
|
// This is a pure go implementation, and should be moved to disk_aix_nocgo.go
|
||||||
|
// if a more efficient CGO method is introduced in disk_aix_cgo.go
|
||||||
|
func SerialNumberWithContext(ctx context.Context, name string) (string, error) {
|
||||||
|
// This isn't linux, these aren't actual disk devices
|
||||||
|
if strings.HasPrefix(name, "/dev/") {
|
||||||
|
return "", errors.New("devices on /dev are not physical disks on aix")
|
||||||
|
}
|
||||||
|
out, err := invoke.CommandWithContext(ctx, "lscfg", "-vl", name)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := ""
|
||||||
|
// Kind of inefficient, but it works
|
||||||
|
lines := strings.Split(string(out[:]), "\n")
|
||||||
|
for line := 1; line < len(lines); line++ {
|
||||||
|
v := strings.TrimSpace(lines[line])
|
||||||
|
if strings.HasPrefix(v, "Serial Number...............") {
|
||||||
|
ret = strings.TrimPrefix(v, "Serial Number...............")
|
||||||
|
if ret == "" {
|
||||||
|
return "", errors.New("empty serial for disk")
|
||||||
|
}
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, errors.New("serial entry not found for disk")
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
package gopsutil
|
package gopsutil
|
||||||
|
@ -0,0 +1,196 @@
|
|||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
//go:build aix
|
||||||
|
|
||||||
|
package host
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/shirou/gopsutil/v4/internal/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// from https://www.ibm.com/docs/en/aix/7.2?topic=files-utmph-file
|
||||||
|
const (
|
||||||
|
user_PROCESS = 7
|
||||||
|
)
|
||||||
|
|
||||||
|
func HostIDWithContext(ctx context.Context) (string, error) {
|
||||||
|
out, err := invoke.CommandWithContext(ctx, "uname", "-u")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
// The command always returns an extra newline, so we make use of Split() to get only the first line
|
||||||
|
return strings.Split(string(out[:]), "\n")[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func numProcs(ctx context.Context) (uint64, error) {
|
||||||
|
return 0, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
|
|
||||||
|
func BootTimeWithContext(ctx context.Context) (btime uint64, err error) {
|
||||||
|
ut, err := UptimeWithContext(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if ut <= 0 {
|
||||||
|
return 0, errors.New("Uptime was not set, so cannot calculate boot time from it.")
|
||||||
|
}
|
||||||
|
|
||||||
|
ut = ut * 60
|
||||||
|
return timeSince(ut), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function takes multiple formats of output frmo the uptime
|
||||||
|
// command and converts the data into minutes.
|
||||||
|
// Some examples of uptime output that this command handles:
|
||||||
|
// 11:54AM up 13 mins, 1 user, load average: 2.78, 2.62, 1.79
|
||||||
|
// 12:41PM up 1 hr, 1 user, load average: 2.47, 2.85, 2.83
|
||||||
|
// 07:43PM up 5 hrs, 1 user, load average: 3.27, 2.91, 2.72
|
||||||
|
// 11:18:23 up 83 days, 18:29, 4 users, load average: 0.16, 0.03, 0.01
|
||||||
|
func UptimeWithContext(ctx context.Context) (uint64, error) {
|
||||||
|
out, err := invoke.CommandWithContext(ctx, "uptime")
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert our uptime to a series of fields we can extract
|
||||||
|
ut := strings.Fields(string(out[:]))
|
||||||
|
|
||||||
|
// Convert the second field value to integer
|
||||||
|
var days uint64 = 0
|
||||||
|
var hours uint64 = 0
|
||||||
|
var minutes uint64 = 0
|
||||||
|
if ut[3] == "day," || ut[3] == "days," {
|
||||||
|
days, err = strconv.ParseUint(ut[2], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split field 4 into hours and minutes
|
||||||
|
hm := strings.Split(ut[4], ":")
|
||||||
|
hours, err = strconv.ParseUint(hm[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
minutes, err = strconv.ParseUint(strings.Replace(hm[1], ",", "", -1), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
} else if ut[3] == "hr," || ut[3] == "hrs," {
|
||||||
|
hours, err = strconv.ParseUint(ut[2], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
} else if ut[3] == "mins," {
|
||||||
|
minutes, err = strconv.ParseUint(ut[2], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
} else if _, err := strconv.ParseInt(ut[3], 10, 64); err == nil && strings.Contains(ut[2], ":") {
|
||||||
|
// Split field 2 into hours and minutes
|
||||||
|
hm := strings.Split(ut[2], ":")
|
||||||
|
hours, err = strconv.ParseUint(hm[0], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
minutes, err = strconv.ParseUint(strings.Replace(hm[1], ",", "", -1), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stack them all together as minutes
|
||||||
|
total_time := (days * 24 * 60) + (hours * 60) + minutes
|
||||||
|
|
||||||
|
return total_time, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a weak implementation due to the limitations on retrieving this data in AIX
|
||||||
|
func UsersWithContext(ctx context.Context) ([]UserStat, error) {
|
||||||
|
var ret []UserStat
|
||||||
|
out, err := invoke.CommandWithContext(ctx, "w")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lines := strings.Split(string(out), "\n")
|
||||||
|
if len(lines) < 3 {
|
||||||
|
return []UserStat{}, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
|
|
||||||
|
hf := strings.Fields(lines[1]) // headers
|
||||||
|
for l := 2; l < len(lines); l++ {
|
||||||
|
v := strings.Fields(lines[l]) // values
|
||||||
|
us := &UserStat{}
|
||||||
|
for i, header := range hf {
|
||||||
|
// We're done in any of these use cases
|
||||||
|
if i >= len(v) || v[0] == "-" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if t, err := strconv.ParseFloat(v[i], 64); err == nil {
|
||||||
|
switch header {
|
||||||
|
case `User`:
|
||||||
|
us.User = strconv.FormatFloat(t, 'f', 1, 64)
|
||||||
|
case `tty`:
|
||||||
|
us.Terminal = strconv.FormatFloat(t, 'f', 1, 64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valid User data, so append it
|
||||||
|
ret = append(ret, *us)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Much of this function could be static. However, to be future proofed, I've made it call the OS for the information in all instances.
|
||||||
|
func PlatformInformationWithContext(ctx context.Context) (platform string, family string, version string, err error) {
|
||||||
|
// Set the platform (which should always, and only be, "AIX") from `uname -s`
|
||||||
|
out, err := invoke.CommandWithContext(ctx, "uname", "-s")
|
||||||
|
if err != nil {
|
||||||
|
return "", "", "", err
|
||||||
|
}
|
||||||
|
platform = strings.TrimRight(string(out[:]), "\n")
|
||||||
|
|
||||||
|
// Set the family
|
||||||
|
family = strings.TrimRight(string(out[:]), "\n")
|
||||||
|
|
||||||
|
// Set the version
|
||||||
|
out, err = invoke.CommandWithContext(ctx, "oslevel")
|
||||||
|
if err != nil {
|
||||||
|
return "", "", "", err
|
||||||
|
}
|
||||||
|
version = strings.TrimRight(string(out[:]), "\n")
|
||||||
|
|
||||||
|
return platform, family, version, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func KernelVersionWithContext(ctx context.Context) (version string, err error) {
|
||||||
|
out, err := invoke.CommandWithContext(ctx, "oslevel", "-s")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
version = strings.TrimRight(string(out[:]), "\n")
|
||||||
|
|
||||||
|
return version, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func KernelArch() (arch string, err error) {
|
||||||
|
out, err := invoke.Command("bootinfo", "-y")
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
arch = strings.TrimRight(string(out[:]), "\n")
|
||||||
|
|
||||||
|
return arch, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
||||||
|
return "", "", common.ErrNotImplementedError
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
//go:build aix && ppc64 && cgo
|
||||||
|
// +build aix,ppc64,cgo
|
||||||
|
|
||||||
|
// Guessed at from the following document:
|
||||||
|
// https://www.ibm.com/docs/sl/ibm-mq/9.2?topic=platforms-standard-data-types-aix-linux-windows
|
||||||
|
|
||||||
|
package host
|
||||||
|
|
||||||
|
const (
|
||||||
|
sizeofPtr = 0x8
|
||||||
|
sizeofShort = 0x2
|
||||||
|
sizeofInt = 0x4
|
||||||
|
sizeofLong = 0x8
|
||||||
|
sizeofLongLong = 0x8
|
||||||
|
sizeOfUtmp = 0x180
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
_C_short int16
|
||||||
|
_C_int int32
|
||||||
|
_C_long int64
|
||||||
|
_C_long_long int64
|
||||||
|
)
|
||||||
|
|
||||||
|
type utmp struct {
|
||||||
|
Type int16
|
||||||
|
Pad_cgo_0 [2]byte
|
||||||
|
Pid int32
|
||||||
|
Line [32]int8
|
||||||
|
Id [4]int8
|
||||||
|
User [32]int8
|
||||||
|
Host [256]int8
|
||||||
|
Exit exit_status
|
||||||
|
Session int32
|
||||||
|
Tv timeval
|
||||||
|
Addr_v6 [4]int32
|
||||||
|
X__glibc_reserved [20]int8
|
||||||
|
}
|
||||||
|
|
||||||
|
type exit_status struct {
|
||||||
|
Termination int16
|
||||||
|
Exit int16
|
||||||
|
}
|
||||||
|
|
||||||
|
type timeval struct {
|
||||||
|
Sec int64
|
||||||
|
Usec int64
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
//go:build darwin && !cgo
|
|
||||||
// +build darwin,!cgo
|
|
||||||
|
|
||||||
package host
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/v3/internal/common"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SensorsTemperaturesWithContext(ctx context.Context) ([]TemperatureStat, error) {
|
|
||||||
return []TemperatureStat{}, common.ErrNotImplementedError
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue