chore(deps): update module github.com/shirou/gopsutil to v3.21.11+incompatible
Some checks are pending
/ Release (push) Waiting to run
Some checks are pending
/ Release (push) Waiting to run
This commit is contained in:
parent
9f2fde0ac3
commit
f96efd6db0
21 changed files with 289 additions and 100 deletions
5
go.mod
5
go.mod
|
@ -5,12 +5,13 @@ go 1.17
|
|||
require (
|
||||
github.com/mackerelio/go-osstat v0.2.0
|
||||
github.com/rs/zerolog v1.25.0
|
||||
github.com/shirou/gopsutil v3.21.8+incompatible
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
golang.org/x/sys v0.0.0-20210915083310-ed5796bab164 // indirect
|
||||
)
|
||||
|
|
6
go.sum
6
go.sum
|
@ -3,6 +3,8 @@ github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9
|
|||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/go-ole/go-ole v1.2.5 h1:t4MGB5xEDZvXI+0rMjjsfBsD7yAgp/s9ZDkL1JndXwY=
|
||||
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/mackerelio/go-osstat v0.2.0 h1:UVn9Am/OOj2Ig0LNNHLqiHeXsZWmMNcMPZ3h+z/8+h8=
|
||||
github.com/mackerelio/go-osstat v0.2.0/go.mod h1:UzRL8dMCCTqG5WdRtsxbuljMpZt9PCAGXqxPst5QtaY=
|
||||
|
@ -12,7 +14,11 @@ github.com/rs/zerolog v1.25.0 h1:Rj7XygbUHKUlDPcVdoLyR91fJBsduXj5fRxyqIQj/II=
|
|||
github.com/rs/zerolog v1.25.0/go.mod h1:7KHcEGe0QZPOm2IE4Kpb5rTh6n1h2hIgS5OOnu1rUaI=
|
||||
github.com/shirou/gopsutil v3.21.8+incompatible h1:sh0foI8tMRlCidUJR+KzqWYWxrkuuPIGiO6Vp+KXdCU=
|
||||
github.com/shirou/gopsutil v3.21.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
|
||||
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
|
|
13
vendor/github.com/StackExchange/wmi/README.md
generated
vendored
13
vendor/github.com/StackExchange/wmi/README.md
generated
vendored
|
@ -1,13 +0,0 @@
|
|||
wmi
|
||||
===
|
||||
|
||||
Package wmi provides a WQL interface to Windows WMI.
|
||||
|
||||
Note: It interfaces with WMI on the local machine, therefore it only runs on Windows.
|
||||
|
||||
---
|
||||
|
||||
NOTE: This project is no longer being actively maintained. If you would like
|
||||
to become its new owner, please contact tlimoncelli at stack over flow dot com.
|
||||
|
||||
---
|
4
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
4
vendor/github.com/go-ole/go-ole/idispatch_windows.go
generated
vendored
|
@ -185,7 +185,9 @@ func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{}
|
|||
uintptr(unsafe.Pointer(&excepInfo)),
|
||||
0)
|
||||
if hr != 0 {
|
||||
err = NewErrorWithSubError(hr, BstrToString(excepInfo.bstrDescription), excepInfo)
|
||||
excepInfo.renderStrings()
|
||||
excepInfo.Clear()
|
||||
err = NewErrorWithSubError(hr, excepInfo.description, excepInfo)
|
||||
}
|
||||
for i, varg := range vargs {
|
||||
n := len(params) - i - 1
|
||||
|
|
85
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
85
vendor/github.com/go-ole/go-ole/ole.go
generated
vendored
|
@ -3,6 +3,7 @@ package ole
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// DISPPARAMS are the arguments that passed to methods or property.
|
||||
|
@ -24,6 +25,56 @@ type EXCEPINFO struct {
|
|||
pvReserved uintptr
|
||||
pfnDeferredFillIn uintptr
|
||||
scode uint32
|
||||
|
||||
// Go-specific part. Don't move upper cos it'll break structure layout for native code.
|
||||
rendered bool
|
||||
source string
|
||||
description string
|
||||
helpFile string
|
||||
}
|
||||
|
||||
// renderStrings translates BSTR strings to Go ones so `.Error` and `.String`
|
||||
// could be safely called after `.Clear`. We need this when we can't rely on
|
||||
// a caller to call `.Clear`.
|
||||
func (e *EXCEPINFO) renderStrings() {
|
||||
e.rendered = true
|
||||
if e.bstrSource == nil {
|
||||
e.source = "<nil>"
|
||||
} else {
|
||||
e.source = BstrToString(e.bstrSource)
|
||||
}
|
||||
if e.bstrDescription == nil {
|
||||
e.description = "<nil>"
|
||||
} else {
|
||||
e.description = BstrToString(e.bstrDescription)
|
||||
}
|
||||
if e.bstrHelpFile == nil {
|
||||
e.helpFile = "<nil>"
|
||||
} else {
|
||||
e.helpFile = BstrToString(e.bstrHelpFile)
|
||||
}
|
||||
}
|
||||
|
||||
// Clear frees BSTR strings inside an EXCEPINFO and set it to NULL.
|
||||
func (e *EXCEPINFO) Clear() {
|
||||
freeBSTR := func(s *uint16) {
|
||||
// SysFreeString don't return errors and is safe for call's on NULL.
|
||||
// https://docs.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-sysfreestring
|
||||
_ = SysFreeString((*int16)(unsafe.Pointer(s)))
|
||||
}
|
||||
|
||||
if e.bstrSource != nil {
|
||||
freeBSTR(e.bstrSource)
|
||||
e.bstrSource = nil
|
||||
}
|
||||
if e.bstrDescription != nil {
|
||||
freeBSTR(e.bstrDescription)
|
||||
e.bstrDescription = nil
|
||||
}
|
||||
if e.bstrHelpFile != nil {
|
||||
freeBSTR(e.bstrHelpFile)
|
||||
e.bstrHelpFile = nil
|
||||
}
|
||||
}
|
||||
|
||||
// WCode return wCode in EXCEPINFO.
|
||||
|
@ -38,48 +89,30 @@ func (e EXCEPINFO) SCODE() uint32 {
|
|||
|
||||
// String convert EXCEPINFO to string.
|
||||
func (e EXCEPINFO) String() string {
|
||||
var src, desc, hlp string
|
||||
if e.bstrSource == nil {
|
||||
src = "<nil>"
|
||||
} else {
|
||||
src = BstrToString(e.bstrSource)
|
||||
if !e.rendered {
|
||||
e.renderStrings()
|
||||
}
|
||||
|
||||
if e.bstrDescription == nil {
|
||||
desc = "<nil>"
|
||||
} else {
|
||||
desc = BstrToString(e.bstrDescription)
|
||||
}
|
||||
|
||||
if e.bstrHelpFile == nil {
|
||||
hlp = "<nil>"
|
||||
} else {
|
||||
hlp = BstrToString(e.bstrHelpFile)
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"wCode: %#x, bstrSource: %v, bstrDescription: %v, bstrHelpFile: %v, dwHelpContext: %#x, scode: %#x",
|
||||
e.wCode, src, desc, hlp, e.dwHelpContext, e.scode,
|
||||
e.wCode, e.source, e.description, e.helpFile, e.dwHelpContext, e.scode,
|
||||
)
|
||||
}
|
||||
|
||||
// Error implements error interface and returns error string.
|
||||
func (e EXCEPINFO) Error() string {
|
||||
if e.bstrDescription != nil {
|
||||
return strings.TrimSpace(BstrToString(e.bstrDescription))
|
||||
if !e.rendered {
|
||||
e.renderStrings()
|
||||
}
|
||||
|
||||
src := "Unknown"
|
||||
if e.bstrSource != nil {
|
||||
src = BstrToString(e.bstrSource)
|
||||
if e.description != "<nil>" {
|
||||
return strings.TrimSpace(e.description)
|
||||
}
|
||||
|
||||
code := e.scode
|
||||
if e.wCode != 0 {
|
||||
code = uint32(e.wCode)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v: %#x", src, code)
|
||||
return fmt.Sprintf("%v: %#x", e.source, code)
|
||||
}
|
||||
|
||||
// PARAMDATA defines parameter data type.
|
||||
|
|
4
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
4
vendor/github.com/go-ole/go-ole/safearrayconversion.go
generated
vendored
|
@ -84,13 +84,13 @@ func (sac *SafeArrayConversion) ToValueArray() (values []interface{}) {
|
|||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v
|
||||
case VT_BSTR:
|
||||
var v string
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
v , _ := safeArrayGetElementString(sac.Array, i)
|
||||
values[i] = v
|
||||
case VT_VARIANT:
|
||||
var v VARIANT
|
||||
safeArrayGetElement(sac.Array, i, unsafe.Pointer(&v))
|
||||
values[i] = v.Value()
|
||||
v.Clear()
|
||||
default:
|
||||
// TODO
|
||||
}
|
||||
|
|
11
vendor/github.com/go-ole/go-ole/variant_arm.go
generated
vendored
Normal file
11
vendor/github.com/go-ole/go-ole/variant_arm.go
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
// +build arm
|
||||
|
||||
package ole
|
||||
|
||||
type VARIANT struct {
|
||||
VT VT // 2
|
||||
wReserved1 uint16 // 4
|
||||
wReserved2 uint16 // 6
|
||||
wReserved3 uint16 // 8
|
||||
Val int64 // 16
|
||||
}
|
13
vendor/github.com/go-ole/go-ole/variant_arm64.go
generated
vendored
Normal file
13
vendor/github.com/go-ole/go-ole/variant_arm64.go
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
//go:build arm64
|
||||
// +build arm64
|
||||
|
||||
package ole
|
||||
|
||||
type VARIANT struct {
|
||||
VT VT // 2
|
||||
wReserved1 uint16 // 4
|
||||
wReserved2 uint16 // 6
|
||||
wReserved3 uint16 // 8
|
||||
Val int64 // 16
|
||||
_ [8]byte // 24
|
||||
}
|
22
vendor/github.com/go-ole/go-ole/variant_date_arm.go
generated
vendored
Normal file
22
vendor/github.com/go-ole/go-ole/variant_date_arm.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// +build windows,arm
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||
func GetVariantDate(value uint64) (time.Time, error) {
|
||||
var st syscall.Systemtime
|
||||
v1 := uint32(value)
|
||||
v2 := uint32(value >> 32)
|
||||
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(v1), uintptr(v2), uintptr(unsafe.Pointer(&st)))
|
||||
if r != 0 {
|
||||
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||
}
|
||||
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||
}
|
23
vendor/github.com/go-ole/go-ole/variant_date_arm64.go
generated
vendored
Normal file
23
vendor/github.com/go-ole/go-ole/variant_date_arm64.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
//go:build windows && arm64
|
||||
// +build windows,arm64
|
||||
|
||||
package ole
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"syscall"
|
||||
"time"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// GetVariantDate converts COM Variant Time value to Go time.Time.
|
||||
func GetVariantDate(value uint64) (time.Time, error) {
|
||||
var st syscall.Systemtime
|
||||
v1 := uint32(value)
|
||||
v2 := uint32(value >> 32)
|
||||
r, _, _ := procVariantTimeToSystemTime.Call(uintptr(v1), uintptr(v2), uintptr(unsafe.Pointer(&st)))
|
||||
if r != 0 {
|
||||
return time.Date(int(st.Year), time.Month(st.Month), int(st.Day), int(st.Hour), int(st.Minute), int(st.Second), int(st.Milliseconds/1000), time.UTC), nil
|
||||
}
|
||||
return time.Now(), errors.New("Could not convert to time, passing current time.")
|
||||
}
|
8
vendor/github.com/shirou/gopsutil/disk/disk_linux.go
generated
vendored
8
vendor/github.com/shirou/gopsutil/disk/disk_linux.go
generated
vendored
|
@ -221,15 +221,15 @@ var fsTypeMap = map[int64]string{
|
|||
func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, error) {
|
||||
useMounts := false
|
||||
|
||||
filename := common.HostProc("self/mountinfo")
|
||||
filename := common.HostProc("1/mountinfo")
|
||||
lines, err := common.ReadLines(filename)
|
||||
if err != nil {
|
||||
if err != err.(*os.PathError) {
|
||||
return nil, err
|
||||
}
|
||||
// if kernel does not support self/mountinfo, fallback to self/mounts (<2.6.26)
|
||||
// if kernel does not support 1/mountinfo, fallback to 1/mounts (<2.6.26)
|
||||
useMounts = true
|
||||
filename = common.HostProc("self/mounts")
|
||||
filename = common.HostProc("1/mounts")
|
||||
lines, err = common.ReadLines(filename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -261,7 +261,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// a line of self/mountinfo has the following structure:
|
||||
// a line of 1/mountinfo has the following structure:
|
||||
// 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
|
||||
// (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) (11)
|
||||
|
||||
|
|
2
vendor/github.com/shirou/gopsutil/internal/common/binary.go
generated
vendored
2
vendor/github.com/shirou/gopsutil/internal/common/binary.go
generated
vendored
|
@ -253,7 +253,7 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error {
|
|||
b[0] = *v
|
||||
case uint8:
|
||||
bs = b[:1]
|
||||
b[0] = byte(v)
|
||||
b[0] = v
|
||||
case []uint8:
|
||||
bs = v
|
||||
case *int16:
|
||||
|
|
18
vendor/github.com/shirou/gopsutil/internal/common/common.go
generated
vendored
18
vendor/github.com/shirou/gopsutil/internal/common/common.go
generated
vendored
|
@ -94,7 +94,7 @@ func (i FakeInvoke) CommandWithContext(ctx context.Context, name string, arg ...
|
|||
|
||||
var ErrNotImplementedError = errors.New("not implemented yet")
|
||||
|
||||
// ReadFile reads contents from a file
|
||||
// ReadFile reads contents from a file.
|
||||
func ReadFile(filename string) (string, error) {
|
||||
content, err := ioutil.ReadFile(filename)
|
||||
|
||||
|
@ -111,7 +111,7 @@ func ReadLines(filename string) ([]string, error) {
|
|||
return ReadLinesOffsetN(filename, 0, -1)
|
||||
}
|
||||
|
||||
// ReadLines reads contents from file and splits them by new line.
|
||||
// ReadLinesOffsetN reads contents from file and splits them by new line.
|
||||
// The offset tells at which line number to start.
|
||||
// The count determines the number of lines to read (starting from offset):
|
||||
// n >= 0: at most n lines
|
||||
|
@ -165,7 +165,7 @@ func UintToString(orig []uint8) string {
|
|||
size = i
|
||||
break
|
||||
}
|
||||
ret[i] = byte(o)
|
||||
ret[i] = o
|
||||
}
|
||||
if size == -1 {
|
||||
size = len(orig)
|
||||
|
@ -224,31 +224,31 @@ func ReadInts(filename string) ([]int64, error) {
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
// Parse Hex to uint32 without error
|
||||
// HexToUint32 parses Hex to uint32 without error.
|
||||
func HexToUint32(hex string) uint32 {
|
||||
vv, _ := strconv.ParseUint(hex, 16, 32)
|
||||
return uint32(vv)
|
||||
}
|
||||
|
||||
// Parse to int32 without error
|
||||
// mustParseInt32 parses to int32 without error.
|
||||
func mustParseInt32(val string) int32 {
|
||||
vv, _ := strconv.ParseInt(val, 10, 32)
|
||||
return int32(vv)
|
||||
}
|
||||
|
||||
// Parse to uint64 without error
|
||||
// mustParseUint64 parses to uint64 without error.
|
||||
func mustParseUint64(val string) uint64 {
|
||||
vv, _ := strconv.ParseInt(val, 10, 64)
|
||||
return uint64(vv)
|
||||
}
|
||||
|
||||
// Parse to Float64 without error
|
||||
// mustParseFloat64 parses to Float64 without error.
|
||||
func mustParseFloat64(val string) float64 {
|
||||
vv, _ := strconv.ParseFloat(val, 64)
|
||||
return vv
|
||||
}
|
||||
|
||||
// StringsHas checks the target string slice contains src or not
|
||||
// StringsHas checks the target string slice contains src or not.
|
||||
func StringsHas(target []string, src string) bool {
|
||||
for _, t := range target {
|
||||
if strings.TrimSpace(t) == src {
|
||||
|
@ -258,7 +258,7 @@ func StringsHas(target []string, src string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// StringsContains checks the src in any string of the target string slice
|
||||
// StringsContains checks the src in any string of the target string slice.
|
||||
func StringsContains(target []string, src string) bool {
|
||||
for _, t := range target {
|
||||
if strings.Contains(t, src) {
|
||||
|
|
55
vendor/github.com/shirou/gopsutil/internal/common/common_linux.go
generated
vendored
55
vendor/github.com/shirou/gopsutil/internal/common/common_linux.go
generated
vendored
|
@ -26,8 +26,8 @@ func DoSysctrl(mib string) ([]string, error) {
|
|||
return []string{}, err
|
||||
}
|
||||
v := strings.Replace(string(out), "{ ", "", 1)
|
||||
v = strings.Replace(string(v), " }", "", 1)
|
||||
values := strings.Fields(string(v))
|
||||
v = strings.Replace(v, " }", "", 1)
|
||||
values := strings.Fields(v)
|
||||
|
||||
return values, nil
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ func NumProcs() (uint64, error) {
|
|||
}
|
||||
|
||||
func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
||||
|
||||
system, role, err := Virtualization()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
@ -76,6 +75,18 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|||
return 0, err
|
||||
}
|
||||
|
||||
if statFile == "uptime" {
|
||||
if len(lines) != 1 {
|
||||
return 0, fmt.Errorf("wrong uptime format")
|
||||
}
|
||||
f := strings.Fields(lines[0])
|
||||
b, err := strconv.ParseFloat(f[0], 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
t := uint64(time.Now().Unix()) - uint64(b)
|
||||
return t, nil
|
||||
}
|
||||
if statFile == "stat" {
|
||||
for _, line := range lines {
|
||||
if strings.HasPrefix(line, "btime") {
|
||||
|
@ -91,17 +102,6 @@ func BootTimeWithContext(ctx context.Context) (uint64, error) {
|
|||
return t, nil
|
||||
}
|
||||
}
|
||||
} else if statFile == "uptime" {
|
||||
if len(lines) != 1 {
|
||||
return 0, fmt.Errorf("wrong uptime format")
|
||||
}
|
||||
f := strings.Fields(lines[0])
|
||||
b, err := strconv.ParseFloat(f[0], 64)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
t := uint64(time.Now().Unix()) - uint64(b)
|
||||
return t, nil
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("could not find btime")
|
||||
|
@ -111,7 +111,7 @@ func Virtualization() (string, string, error) {
|
|||
return VirtualizationWithContext(context.Background())
|
||||
}
|
||||
|
||||
// required variables for concurrency safe virtualization caching
|
||||
// required variables for concurrency safe virtualization caching.
|
||||
var (
|
||||
cachedVirtMap map[string]string
|
||||
cachedVirtMutex sync.RWMutex
|
||||
|
@ -137,28 +137,27 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|||
|
||||
if PathExists(filepath.Join(filename, "capabilities")) {
|
||||
contents, err := ReadLines(filepath.Join(filename, "capabilities"))
|
||||
if err == nil {
|
||||
if StringsContains(contents, "control_d") {
|
||||
if err == nil && StringsContains(contents, "control_d") {
|
||||
role = "host"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filename = HostProc("modules")
|
||||
if PathExists(filename) {
|
||||
contents, err := ReadLines(filename)
|
||||
if err == nil {
|
||||
if StringsContains(contents, "kvm") {
|
||||
switch {
|
||||
case StringsContains(contents, "kvm"):
|
||||
system = "kvm"
|
||||
role = "host"
|
||||
} else if StringsContains(contents, "vboxdrv") {
|
||||
case StringsContains(contents, "vboxdrv"):
|
||||
system = "vbox"
|
||||
role = "host"
|
||||
} else if StringsContains(contents, "vboxguest") {
|
||||
case StringsContains(contents, "vboxguest"):
|
||||
system = "vbox"
|
||||
role = "guest"
|
||||
} else if StringsContains(contents, "vmware") {
|
||||
case StringsContains(contents, "vmware"):
|
||||
system = "vmware"
|
||||
role = "guest"
|
||||
}
|
||||
|
@ -201,7 +200,6 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|||
if PathExists(filepath.Join(filename, "self", "status")) {
|
||||
contents, err := ReadLines(filepath.Join(filename, "self", "status"))
|
||||
if err == nil {
|
||||
|
||||
if StringsContains(contents, "s_context:") ||
|
||||
StringsContains(contents, "VxID:") {
|
||||
system = "linux-vserver"
|
||||
|
@ -224,16 +222,17 @@ func VirtualizationWithContext(ctx context.Context) (string, string, error) {
|
|||
if PathExists(filepath.Join(filename, "self", "cgroup")) {
|
||||
contents, err := ReadLines(filepath.Join(filename, "self", "cgroup"))
|
||||
if err == nil {
|
||||
if StringsContains(contents, "lxc") {
|
||||
switch {
|
||||
case StringsContains(contents, "lxc"):
|
||||
system = "lxc"
|
||||
role = "guest"
|
||||
} else if StringsContains(contents, "docker") {
|
||||
case StringsContains(contents, "docker"):
|
||||
system = "docker"
|
||||
role = "guest"
|
||||
} else if StringsContains(contents, "machine-rkt") {
|
||||
case StringsContains(contents, "machine-rkt"):
|
||||
system = "rkt"
|
||||
role = "guest"
|
||||
} else if PathExists("/usr/bin/lxc-version") {
|
||||
case PathExists("/usr/bin/lxc-version"):
|
||||
system = "lxc"
|
||||
role = "host"
|
||||
}
|
||||
|
@ -281,7 +280,7 @@ func GetOSRelease() (platform string, version string, err error) {
|
|||
return platform, version, nil
|
||||
}
|
||||
|
||||
// Remove quotes of the source string
|
||||
// trimQuotes removes quotes in the source string.
|
||||
func trimQuotes(s string) string {
|
||||
if len(s) >= 2 {
|
||||
if s[0] == '"' && s[len(s)-1] == '"' {
|
||||
|
|
3
vendor/github.com/shirou/gopsutil/internal/common/common_unix.go
generated
vendored
3
vendor/github.com/shirou/gopsutil/internal/common/common_unix.go
generated
vendored
|
@ -41,8 +41,7 @@ func CallLsofWithContext(ctx context.Context, invoke Invoker, pid int32, args ..
|
|||
}
|
||||
|
||||
func CallPgrepWithContext(ctx context.Context, invoke Invoker, pid int32) ([]int32, error) {
|
||||
var cmd []string
|
||||
cmd = []string{"-P", strconv.Itoa(int(pid))}
|
||||
cmd := []string{"-P", strconv.Itoa(int(pid))}
|
||||
pgrep, err := exec.LookPath("pgrep")
|
||||
if err != nil {
|
||||
return []int32{}, err
|
||||
|
|
73
vendor/github.com/shirou/gopsutil/internal/common/common_windows.go
generated
vendored
73
vendor/github.com/shirou/gopsutil/internal/common/common_windows.go
generated
vendored
|
@ -6,11 +6,12 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/StackExchange/wmi"
|
||||
"github.com/yusufpapurcu/wmi"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
|
@ -48,11 +49,18 @@ const (
|
|||
PDH_INVALID_DATA = 0xc0000bc6
|
||||
PDH_INVALID_HANDLE = 0xC0000bbc
|
||||
PDH_NO_DATA = 0x800007d5
|
||||
|
||||
STATUS_BUFFER_OVERFLOW = 0x80000005
|
||||
STATUS_BUFFER_TOO_SMALL = 0xC0000023
|
||||
STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
|
||||
)
|
||||
|
||||
const (
|
||||
ProcessBasicInformation = 0
|
||||
ProcessWow64Information = 26
|
||||
ProcessQueryInformation = windows.PROCESS_DUP_HANDLE | windows.PROCESS_QUERY_INFORMATION
|
||||
|
||||
SystemExtendedHandleInformationClass = 64
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -227,3 +235,66 @@ func ConvertDOSPath(p string) string {
|
|||
}
|
||||
return p
|
||||
}
|
||||
|
||||
type NtStatus uint32
|
||||
|
||||
func (s NtStatus) Error() error {
|
||||
if s == 0 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("NtStatus 0x%08x", uint32(s))
|
||||
}
|
||||
|
||||
func (s NtStatus) IsError() bool {
|
||||
return s>>30 == 3
|
||||
}
|
||||
|
||||
type SystemExtendedHandleTableEntryInformation struct {
|
||||
Object uintptr
|
||||
UniqueProcessId uintptr
|
||||
HandleValue uintptr
|
||||
GrantedAccess uint32
|
||||
CreatorBackTraceIndex uint16
|
||||
ObjectTypeIndex uint16
|
||||
HandleAttributes uint32
|
||||
Reserved uint32
|
||||
}
|
||||
|
||||
type SystemExtendedHandleInformation struct {
|
||||
NumberOfHandles uintptr
|
||||
Reserved uintptr
|
||||
Handles [1]SystemExtendedHandleTableEntryInformation
|
||||
}
|
||||
|
||||
// CallWithExpandingBuffer https://github.com/hillu/go-ntdll
|
||||
func CallWithExpandingBuffer(fn func() NtStatus, buf *[]byte, resultLength *uint32) NtStatus {
|
||||
for {
|
||||
if st := fn(); st == STATUS_BUFFER_OVERFLOW || st == STATUS_BUFFER_TOO_SMALL || st == STATUS_INFO_LENGTH_MISMATCH {
|
||||
if int(*resultLength) <= cap(*buf) {
|
||||
(*reflect.SliceHeader)(unsafe.Pointer(buf)).Len = int(*resultLength)
|
||||
} else {
|
||||
*buf = make([]byte, int(*resultLength))
|
||||
}
|
||||
continue
|
||||
} else {
|
||||
if !st.IsError() {
|
||||
*buf = (*buf)[:int(*resultLength)]
|
||||
}
|
||||
return st
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func NtQuerySystemInformation(
|
||||
SystemInformationClass uint32,
|
||||
SystemInformation *byte,
|
||||
SystemInformationLength uint32,
|
||||
ReturnLength *uint32,
|
||||
) NtStatus {
|
||||
r0, _, _ := ProcNtQuerySystemInformation.Call(
|
||||
uintptr(SystemInformationClass),
|
||||
uintptr(unsafe.Pointer(SystemInformation)),
|
||||
uintptr(SystemInformationLength),
|
||||
uintptr(unsafe.Pointer(ReturnLength)))
|
||||
return NtStatus(r0)
|
||||
}
|
||||
|
|
6
vendor/github.com/yusufpapurcu/wmi/README.md
generated
vendored
Normal file
6
vendor/github.com/yusufpapurcu/wmi/README.md
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
wmi
|
||||
===
|
||||
|
||||
Package wmi provides a WQL interface to Windows WMI.
|
||||
|
||||
Note: It interfaces with WMI on the local machine, therefore it only runs on Windows.
|
|
@ -1,3 +1,4 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package wmi
|
25
vendor/github.com/StackExchange/wmi/wmi.go → vendor/github.com/yusufpapurcu/wmi/wmi.go
generated
vendored
25
vendor/github.com/StackExchange/wmi/wmi.go → vendor/github.com/yusufpapurcu/wmi/wmi.go
generated
vendored
|
@ -1,3 +1,4 @@
|
|||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
|
@ -20,7 +21,6 @@ Example code to print names of running processes:
|
|||
println(i, v.Name)
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
package wmi
|
||||
|
||||
|
@ -338,11 +338,6 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat
|
|||
f := v.Field(i)
|
||||
of := f
|
||||
isPtr := f.Kind() == reflect.Ptr
|
||||
if isPtr {
|
||||
ptr := reflect.New(f.Type().Elem())
|
||||
f.Set(ptr)
|
||||
f = f.Elem()
|
||||
}
|
||||
n := v.Type().Field(i).Name
|
||||
if n[0] < 'A' || n[0] > 'Z' {
|
||||
continue
|
||||
|
@ -367,6 +362,12 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat
|
|||
}
|
||||
defer prop.Clear()
|
||||
|
||||
if isPtr && !(c.PtrNil && prop.VT == 0x1) {
|
||||
ptr := reflect.New(f.Type().Elem())
|
||||
f.Set(ptr)
|
||||
f = f.Elem()
|
||||
}
|
||||
|
||||
if prop.VT == 0x1 { //VT_NULL
|
||||
continue
|
||||
}
|
||||
|
@ -455,6 +456,18 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat
|
|||
Reason: "not a Float32",
|
||||
}
|
||||
}
|
||||
case float64:
|
||||
switch f.Kind() {
|
||||
case reflect.Float32, reflect.Float64:
|
||||
f.SetFloat(val)
|
||||
default:
|
||||
return &ErrFieldMismatch{
|
||||
StructType: of.Type(),
|
||||
FieldName: n,
|
||||
Reason: "not a Float64",
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
if f.Kind() == reflect.Slice {
|
||||
switch f.Type().Elem().Kind() {
|
8
vendor/modules.txt
vendored
8
vendor/modules.txt
vendored
|
@ -1,7 +1,6 @@
|
|||
# github.com/StackExchange/wmi v1.2.1
|
||||
## explicit; go 1.13
|
||||
github.com/StackExchange/wmi
|
||||
# github.com/go-ole/go-ole v1.2.5
|
||||
# github.com/go-ole/go-ole v1.2.6
|
||||
## explicit; go 1.12
|
||||
github.com/go-ole/go-ole
|
||||
github.com/go-ole/go-ole/oleutil
|
||||
|
@ -15,10 +14,13 @@ github.com/rs/zerolog
|
|||
github.com/rs/zerolog/internal/cbor
|
||||
github.com/rs/zerolog/internal/json
|
||||
github.com/rs/zerolog/log
|
||||
# github.com/shirou/gopsutil v3.21.8+incompatible
|
||||
# github.com/shirou/gopsutil v3.21.11+incompatible
|
||||
## explicit
|
||||
github.com/shirou/gopsutil/disk
|
||||
github.com/shirou/gopsutil/internal/common
|
||||
# github.com/yusufpapurcu/wmi v1.2.4
|
||||
## explicit; go 1.16
|
||||
github.com/yusufpapurcu/wmi
|
||||
# golang.org/x/sys v0.0.0-20210915083310-ed5796bab164
|
||||
## explicit; go 1.17
|
||||
golang.org/x/sys/internal/unsafeheader
|
||||
|
|
Loading…
Reference in a new issue