From b72468631a9bc1638378d7feed168833f8730486 Mon Sep 17 00:00:00 2001 From: Jaime Soriano Pastor Date: Fri, 21 Dec 2018 10:19:33 +0100 Subject: [PATCH] Update gopsutil to 2.18.11 (#9710) (cherry picked from commit 9b63a170c31e7a79e535b1ed997621911111447f) --- NOTICE.txt | 4 +- vendor/github.com/shirou/gopsutil/Gopkg.lock | 62 ++ vendor/github.com/shirou/gopsutil/Gopkg.toml | 46 ++ vendor/github.com/shirou/gopsutil/Makefile | 36 ++ vendor/github.com/shirou/gopsutil/README.rst | 322 +++++++++++ vendor/github.com/shirou/gopsutil/coverall.sh | 26 + .../shirou/gopsutil/disk/disk_linux.go | 6 +- .../shirou/gopsutil/disk/disk_unix.go | 18 +- .../shirou/gopsutil/disk/disk_windows.go | 7 +- .../shirou/gopsutil/internal/common/common.go | 4 + .../internal/common/common_windows.go | 8 +- vendor/github.com/shirou/gopsutil/mktypes.sh | 37 ++ vendor/github.com/shirou/gopsutil/net/net.go | 19 +- .../shirou/gopsutil/net/net_linux.go | 4 +- .../shirou/gopsutil/net/net_unix.go | 2 +- .../shirou/gopsutil/net/net_windows.go | 533 +++++++++++++++++- .../github.com/shirou/gopsutil/v2migration.sh | 134 +++++ .../shirou/gopsutil/windows_memo.rst | 36 ++ vendor/vendor.json | 40 +- 19 files changed, 1295 insertions(+), 49 deletions(-) create mode 100644 vendor/github.com/shirou/gopsutil/Gopkg.lock create mode 100644 vendor/github.com/shirou/gopsutil/Gopkg.toml create mode 100644 vendor/github.com/shirou/gopsutil/Makefile create mode 100644 vendor/github.com/shirou/gopsutil/README.rst create mode 100644 vendor/github.com/shirou/gopsutil/coverall.sh create mode 100644 vendor/github.com/shirou/gopsutil/mktypes.sh create mode 100644 vendor/github.com/shirou/gopsutil/v2migration.sh create mode 100644 vendor/github.com/shirou/gopsutil/windows_memo.rst diff --git a/NOTICE.txt b/NOTICE.txt index a2fc2041122..8c1700d825e 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -2358,8 +2358,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------- Dependency: github.com/shirou/gopsutil -Version: v2.18.06 -Revision: 4a180b209f5f494e5923cfce81ea30ba23915877 +Version: v2.18.11 +Revision: 0f70a4a06f7a1039305ec9b3ba9c2800f8929fba License type (autodetected): BSD-3-Clause ./vendor/github.com/shirou/gopsutil/LICENSE: -------------------------------------------------------------------- diff --git a/vendor/github.com/shirou/gopsutil/Gopkg.lock b/vendor/github.com/shirou/gopsutil/Gopkg.lock new file mode 100644 index 00000000000..34a469bd53a --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/Gopkg.lock @@ -0,0 +1,62 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "github.com/StackExchange/wmi" + packages = ["."] + revision = "5d049714c4a64225c3c79a7cf7d02f7fb5b96338" + version = "1.0.0" + +[[projects]] + name = "github.com/davecgh/go-spew" + packages = ["spew"] + revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" + version = "v1.1.1" + +[[projects]] + name = "github.com/go-ole/go-ole" + packages = [ + ".", + "oleutil" + ] + revision = "a41e3c4b706f6ae8dfbff342b06e40fa4d2d0506" + version = "v1.2.1" + +[[projects]] + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + branch = "master" + name = "github.com/shirou/w32" + packages = ["."] + revision = "bb4de0191aa41b5507caa14b0650cdbddcd9280b" + +[[projects]] + name = "github.com/stretchr/testify" + packages = [ + "assert", + "require" + ] + revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686" + version = "v1.2.2" + +[[projects]] + branch = "master" + name = "golang.org/x/sys" + packages = [ + "unix", + "windows", + "windows/svc", + "windows/svc/mgr" + ] + revision = "d0be0721c37eeb5299f245a996a483160fc36940" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "89929c5aa8f9bda295b48691b590eeec9462f8928b83c593eccb58ef45b667ac" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/vendor/github.com/shirou/gopsutil/Gopkg.toml b/vendor/github.com/shirou/gopsutil/Gopkg.toml new file mode 100644 index 00000000000..c53eeacf769 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/Gopkg.toml @@ -0,0 +1,46 @@ +# Gopkg.toml example +# +# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[[constraint]] + name = "github.com/StackExchange/wmi" + version = "1.0.0" + +[[constraint]] + branch = "master" + name = "github.com/shirou/w32" + +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.2.2" + +[[constraint]] + branch = "master" + name = "golang.org/x/sys" + +[prune] + go-tests = true + unused-packages = true diff --git a/vendor/github.com/shirou/gopsutil/Makefile b/vendor/github.com/shirou/gopsutil/Makefile new file mode 100644 index 00000000000..02f33f52a21 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/Makefile @@ -0,0 +1,36 @@ +.PHONY: help check +.DEFAULT_GOAL := help + +SUBPKGS=cpu disk docker host internal load mem net process + +help: ## Show help + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +check: ## Check + errcheck -ignore="Close|Run|Write" ./... + golint ./... | egrep -v 'underscores|HttpOnly|should have comment|comment on exported|CamelCase|VM|UID' && exit 1 || exit 0 + +BUILD_FAIL_PATTERN=grep -v "exec format error" | grep "build failed" && exit 1 || exit 0 +build_test: ## test only buildable + # Supported operating systems + GOOS=linux GOARCH=amd64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=386 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=linux GOARCH=arm64 go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=freebsd go test ./... | $(BUILD_FAIL_PATTERN) + CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=windows go test ./... | $(BUILD_FAIL_PATTERN) + # Operating systems supported for building only (not implemented error if used) + GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) + GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) + # cross build to OpenBSD not worked since process has "C" +# GOOS=openbsd go test ./... | $(BUILD_FAIL_PATTERN) + +ifeq ($(shell uname -s), Darwin) + CGO_ENABLED=1 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) +endif + @echo 'Successfully built on all known operating systems' + +init_tools: + go get github.com/golang/dep/cmd/dep diff --git a/vendor/github.com/shirou/gopsutil/README.rst b/vendor/github.com/shirou/gopsutil/README.rst new file mode 100644 index 00000000000..63f5f6948b3 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/README.rst @@ -0,0 +1,322 @@ +gopsutil: psutil for golang +============================== + +.. image:: https://circleci.com/gh/shirou/gopsutil.svg?&style=shield + :target: https://circleci.com/gh/shirou/gopsutil + +.. image:: https://coveralls.io/repos/shirou/gopsutil/badge.svg?branch=master + :target: https://coveralls.io/r/shirou/gopsutil?branch=master + +.. image:: https://godoc.org/github.com/shirou/gopsutil?status.svg + :target: http://godoc.org/github.com/shirou/gopsutil + +This is a port of psutil (https://github.com/giampaolo/psutil). The challenge is porting all +psutil functions on some architectures. + + +Breaking Changes! golang 1.8 is required +------------------------------------------- + +After v2.17.04, golang 1.8 is required to build. + + +Tag semantics +------------------------- + +gopsutil tag policy is almost same as Semantic Versioning, but automatically increase like Ubuntu versioning. + +for example, `v2.17.04` means + +- v2: major version +- 17: release year, 2017 +- 04: release month + +gopsutil aims to keep backwards-compatiblity until major version change. + +Taged at every end of month, but there are only a few commits, it can be skipped. + + +Available Architectures +------------------------------------ + +- FreeBSD i386/amd64/arm +- Linux i386/amd64/arm(raspberry pi) +- Windows/amd64 +- Darwin i386/amd64 +- OpenBSD amd64 (Thank you @mpfz0r!) +- Solaris amd64 (developed and tested on SmartOS/Illumos, Thank you @jen20!) + +All works are implemented without cgo by porting c struct to golang struct. + + +Usage +--------- + +Note: gopsutil v2 breaks compatibility. If you want to stay with compatibility, please use v1 branch and vendoring. + +.. code:: go + + package main + + import ( + "fmt" + + "github.com/shirou/gopsutil/mem" + ) + + func main() { + v, _ := mem.VirtualMemory() + + // almost every return value is a struct + fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent) + + // convert to JSON. String() is also implemented + fmt.Println(v) + } + +The output is below. + +:: + + Total: 3179569152, Free:284233728, UsedPercent:84.508194% + {"total":3179569152,"available":492572672,"used":2895335424,"usedPercent":84.50819439828305, (snip...)} + +You can set an alternative location to :code:`/proc` by setting the :code:`HOST_PROC` environment variable. + +You can set an alternative location to :code:`/sys` by setting the :code:`HOST_SYS` environment variable. + +You can set an alternative location to :code:`/etc` by setting the :code:`HOST_ETC` environment variable. + +You can set an alternative location to :code:`/var` by setting the :code:`HOST_VAR` environment variable. + +Documentation +------------------------ + +see http://godoc.org/github.com/shirou/gopsutil + +Requirements +----------------- + +- go1.7 or above is required. + + +More Info +-------------------- + +Several methods have been added which are not present in psutil, but will provide useful information. + +- host/HostInfo() (linux) + + - Hostname + - Uptime + - Procs + - OS (ex: "linux") + - Platform (ex: "ubuntu", "arch") + - PlatformFamily (ex: "debian") + - PlatformVersion (ex: "Ubuntu 13.10") + - VirtualizationSystem (ex: "LXC") + - VirtualizationRole (ex: "guest"/"host") + +- IOCounters + + - Label (linux only) The registered `device mapper name `_ + +- cpu/CPUInfo() (linux, freebsd) + + - CPU (ex: 0, 1, ...) + - VendorID (ex: "GenuineIntel") + - Family + - Model + - Stepping + - PhysicalID + - CoreID + - Cores (ex: 2) + - ModelName (ex: "Intel(R) Core(TM) i7-2640M CPU @ 2.80GHz") + - Mhz + - CacheSize + - Flags (ex: "fpu vme de pse tsc msr pae mce cx8 ...") + - Microcode + +- load/LoadAvg() (linux, freebsd) + + - Load1 + - Load5 + - Load15 + +- docker/GetDockerIDList() (linux only) + + - container id list ([]string) + +- docker/CgroupCPU() (linux only) + + - user + - system + +- docker/CgroupMem() (linux only) + + - various status + +- net_protocols (linux only) + + - system wide stats on network protocols (i.e IP, TCP, UDP, etc.) + - sourced from /proc/net/snmp + +- iptables nf_conntrack (linux only) + + - system wide stats on netfilter conntrack module + - sourced from /proc/sys/net/netfilter/nf_conntrack_count + +Some codes are ported from Ohai. many thanks. + + +Current Status +------------------ + +- x: work +- b: almost works, but something is broken + +=================== ====== ======= ======= ====== ======= ======= +name Linux FreeBSD OpenBSD MacOSX Windows Solaris +cpu_times x x x x x +cpu_count x x x x x +cpu_percent x x x x x +cpu_times_percent x x x x x +virtual_memory x x x x x b +swap_memory x x x x +disk_partitions x x x x x +disk_io_counters x x x +disk_usage x x x x x +net_io_counters x x x b x +boot_time x x x x x +users x x x x x +pids x x x x x +pid_exists x x x x x +net_connections x x x +net_protocols x +net_if_addrs +net_if_stats +netfilter_conntrack x +=================== ====== ======= ======= ====== ======= + +Process class +^^^^^^^^^^^^^^^ + +================ ===== ======= ======= ====== ======= +name Linux FreeBSD OpenBSD MacOSX Windows +pid x x x x x +ppid x x x x x +name x x x x x +cmdline x x x x +create_time x x +status x x x x +cwd x +exe x x x x +uids x x x x +gids x x x x +terminal x x x x +io_counters x x x x +nice x x x x x +num_fds x +num_ctx_switches x +num_threads x x x x x +cpu_times x x +memory_info x x x x x +memory_info_ex x +memory_maps x +open_files x +send_signal x x x x +suspend x x x x +resume x x x x +terminate x x x x x +kill x x x x +username x x x x x +ionice +rlimit x +num_handlers +threads x +cpu_percent x x x +cpu_affinity +memory_percent +parent x x x x +children x x x x x +connections x x x +is_running +================ ===== ======= ======= ====== ======= + +Original Metrics +^^^^^^^^^^^^^^^^^^^ + +================== ===== ======= ======= ====== ======= ======= +item Linux FreeBSD OpenBSD MacOSX Windows Solaris +**HostInfo** +hostname x x x x x x + uptime x x x x x + proces x x x x + os x x x x x x + platform x x x x x + platformfamily x x x x x + virtualization x +**CPU** + VendorID x x x x x x + Family x x x x x x + Model x x x x x x + Stepping x x x x x x + PhysicalID x x + CoreID x x + Cores x x x + ModelName x x x x x x + Microcode x x +**LoadAvg** + Load1 x x x x + Load5 x x x x + Load15 x x x x +**GetDockerID** + container id x no no no no +**CgroupsCPU** + user x no no no no + system x no no no no +**CgroupsMem** + various x no no no no +================== ===== ======= ======= ====== ======= ======= + +- future work + + - process_iter + - wait_procs + - Process class + + - as_dict + - wait + + +License +------------ + +New BSD License (same as psutil) + + +Related Works +----------------------- + +I have been influenced by the following great works: + +- psutil: https://github.com/giampaolo/psutil +- dstat: https://github.com/dagwieers/dstat +- gosigar: https://github.com/cloudfoundry/gosigar/ +- goprocinfo: https://github.com/c9s/goprocinfo +- go-ps: https://github.com/mitchellh/go-ps +- ohai: https://github.com/opscode/ohai/ +- bosun: https://github.com/bosun-monitor/bosun/tree/master/cmd/scollector/collectors +- mackerel: https://github.com/mackerelio/mackerel-agent/tree/master/metrics + +How to Contribute +--------------------------- + +1. Fork it +2. Create your feature branch (git checkout -b my-new-feature) +3. Commit your changes (git commit -am 'Add some feature') +4. Push to the branch (git push origin my-new-feature) +5. Create new Pull Request + +My English is terrible, so documentation or correcting comments are also +welcome. diff --git a/vendor/github.com/shirou/gopsutil/coverall.sh b/vendor/github.com/shirou/gopsutil/coverall.sh new file mode 100644 index 00000000000..35aa298ba41 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/coverall.sh @@ -0,0 +1,26 @@ +#/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 + cat $tmpprof | tail -n +2 >> $prof + rm $tmpprof + fi +done diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_linux.go b/vendor/github.com/shirou/gopsutil/disk/disk_linux.go index 6d0ca9629e3..3d68936526f 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk_linux.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk_linux.go @@ -241,7 +241,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro fields := strings.Fields(line) d := PartitionStat{ Device: fields[0], - Mountpoint: fields[1], + Mountpoint: unescapeFstab(fields[1]), Fstype: fields[2], Opts: fields[3], } @@ -395,7 +395,7 @@ func GetDiskSerialNumberWithContext(ctx context.Context, name string) string { minor := unix.Minor(uint64(stat.Rdev)) // Try to get the serial from udev data - udevDataPath := fmt.Sprintf("/run/udev/data/b%d:%d", major, minor) + udevDataPath := common.HostRun(fmt.Sprintf("udev/data/b%d:%d", major, minor)) if udevdata, err := ioutil.ReadFile(udevDataPath); err == nil { scanner := bufio.NewScanner(bytes.NewReader(udevdata)) for scanner.Scan() { @@ -408,7 +408,7 @@ func GetDiskSerialNumberWithContext(ctx context.Context, name string) string { // Try to get the serial from sysfs, look at the disk device (minor 0) directly // because if it is a partition it is not going to contain any device information - devicePath := fmt.Sprintf("/sys/dev/block/%d:0/device", major) + devicePath := common.HostSys(fmt.Sprintf("dev/block/%d:0/device", major)) model, _ := ioutil.ReadFile(filepath.Join(devicePath, "model")) serial, _ := ioutil.ReadFile(filepath.Join(devicePath, "serial")) if len(model) > 0 && len(serial) > 0 { diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_unix.go b/vendor/github.com/shirou/gopsutil/disk/disk_unix.go index bafef513d45..9b499b52873 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk_unix.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk_unix.go @@ -4,6 +4,7 @@ package disk import ( "context" + "strconv" "golang.org/x/sys/unix" ) @@ -24,7 +25,7 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { bsize := stat.Bsize ret := &UsageStat{ - Path: path, + Path: unescapeFstab(path), Fstype: getFsType(stat), Total: (uint64(stat.Blocks) * uint64(bsize)), Free: (uint64(stat.Bavail) * uint64(bsize)), @@ -46,11 +47,22 @@ func UsageWithContext(ctx context.Context, path string) (*UsageStat, error) { ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 } - if ret.Total == 0 { + if (ret.Used + ret.Free) == 0 { ret.UsedPercent = 0 } else { - ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 + // We don't use ret.Total to calculate percent. + // see https://github.com/shirou/gopsutil/issues/562 + ret.UsedPercent = (float64(ret.Used) / float64(ret.Used+ret.Free)) * 100.0 } return ret, nil } + +// Unescape escaped octal chars (like space 040, ampersand 046 and backslash 134) to their real value in fstab fields issue#555 +func unescapeFstab(path string) string { + escaped, err := strconv.Unquote(`"` + path + `"`) + if err != nil { + return path + } + return escaped +} diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_windows.go b/vendor/github.com/shirou/gopsutil/disk/disk_windows.go index 326bc1f4243..081443b7dea 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk_windows.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk_windows.go @@ -15,7 +15,7 @@ var ( procGetDiskFreeSpaceExW = common.Modkernel32.NewProc("GetDiskFreeSpaceExW") procGetLogicalDriveStringsW = common.Modkernel32.NewProc("GetLogicalDriveStringsW") procGetDriveType = common.Modkernel32.NewProc("GetDriveTypeW") - provGetVolumeInformation = common.Modkernel32.NewProc("GetVolumeInformationW") + procGetVolumeInformation = common.Modkernel32.NewProc("GetVolumeInformationW") ) var ( @@ -83,9 +83,6 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro for _, v := range lpBuffer { if v >= 65 && v <= 90 { path := string(v) + ":" - if path == "A:" || path == "B:" { // skip floppy drives - continue - } typepath, _ := windows.UTF16PtrFromString(path) typeret, _, _ := procGetDriveType.Call(uintptr(unsafe.Pointer(typepath))) if typeret == 0 { @@ -100,7 +97,7 @@ func PartitionsWithContext(ctx context.Context, all bool) ([]PartitionStat, erro lpFileSystemFlags := int64(0) lpFileSystemNameBuffer := make([]byte, 256) volpath, _ := windows.UTF16PtrFromString(string(v) + ":/") - driveret, _, err := provGetVolumeInformation.Call( + driveret, _, err := procGetVolumeInformation.Call( uintptr(unsafe.Pointer(volpath)), uintptr(unsafe.Pointer(&lpVolumeNameBuffer[0])), uintptr(len(lpVolumeNameBuffer)), diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common.go b/vendor/github.com/shirou/gopsutil/internal/common/common.go index f9373ee8945..71c2257f07f 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common.go @@ -328,6 +328,10 @@ func HostVar(combineWith ...string) string { return GetEnv("HOST_VAR", "/var", combineWith...) } +func HostRun(combineWith ...string) string { + return GetEnv("HOST_RUN", "/run", combineWith...) +} + // https://gist.github.com/kylelemons/1525278 func Pipeline(cmds ...*exec.Cmd) ([]byte, []byte, error) { // Require at least one command diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go b/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go index b02c5cf2436..0997c9b8abd 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common_windows.go @@ -47,10 +47,10 @@ const ( ) var ( - Modkernel32 = windows.NewLazyDLL("kernel32.dll") - ModNt = windows.NewLazyDLL("ntdll.dll") - ModPdh = windows.NewLazyDLL("pdh.dll") - ModPsapi = windows.NewLazyDLL("psapi.dll") + Modkernel32 = windows.NewLazySystemDLL("kernel32.dll") + ModNt = windows.NewLazySystemDLL("ntdll.dll") + ModPdh = windows.NewLazySystemDLL("pdh.dll") + ModPsapi = windows.NewLazySystemDLL("psapi.dll") ProcGetSystemTimes = Modkernel32.NewProc("GetSystemTimes") ProcNtQuerySystemInformation = ModNt.NewProc("NtQuerySystemInformation") diff --git a/vendor/github.com/shirou/gopsutil/mktypes.sh b/vendor/github.com/shirou/gopsutil/mktypes.sh new file mode 100644 index 00000000000..7bf2e241217 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/mktypes.sh @@ -0,0 +1,37 @@ + +DIRS="cpu disk docker host load mem net process" + +GOOS=`uname | tr '[:upper:]' '[:lower:]'` +ARCH=`uname -m` + +case $ARCH in + amd64) + GOARCH="amd64" + ;; + x86_64) + GOARCH="amd64" + ;; + i386) + GOARCH="386" + ;; + i686) + GOARCH="386" + ;; + arm) + GOARCH="arm" + ;; + *) + echo "unknown arch: $ARCH" + exit 1 +esac + +for DIR in $DIRS +do + if [ -e ${DIR}/types_${GOOS}.go ]; then + echo "// +build $GOOS" > ${DIR}/${DIR}_${GOOS}_${GOARCH}.go + echo "// +build $GOARCH" >> ${DIR}/${DIR}_${GOOS}_${GOARCH}.go + go tool cgo -godefs ${DIR}/types_${GOOS}.go >> ${DIR}/${DIR}_${GOOS}_${GOARCH}.go + fi +done + + diff --git a/vendor/github.com/shirou/gopsutil/net/net.go b/vendor/github.com/shirou/gopsutil/net/net.go index c31f512429d..fce86c711a4 100644 --- a/vendor/github.com/shirou/gopsutil/net/net.go +++ b/vendor/github.com/shirou/gopsutil/net/net.go @@ -71,6 +71,7 @@ type FilterStat struct { } var constMap = map[string]int{ + "unix": syscall.AF_UNIX, "TCP": syscall.SOCK_STREAM, "UDP": syscall.SOCK_DGRAM, "IPv4": syscall.AF_INET, @@ -178,10 +179,15 @@ func getIOCountersAll(n []IOCountersStat) ([]IOCountersStat, error) { func parseNetLine(line string) (ConnectionStat, error) { f := strings.Fields(line) - if len(f) < 9 { + if len(f) < 8 { return ConnectionStat{}, fmt.Errorf("wrong line,%s", line) } + if len(f) == 8 { + f = append(f, f[7]) + f[7] = "unix" + } + pid, err := strconv.Atoi(f[1]) if err != nil { return ConnectionStat{}, err @@ -199,9 +205,14 @@ func parseNetLine(line string) (ConnectionStat, error) { return ConnectionStat{}, fmt.Errorf("unknown type, %s", f[7]) } - laddr, raddr, err := parseNetAddr(f[8]) - if err != nil { - return ConnectionStat{}, fmt.Errorf("failed to parse netaddr, %s", f[8]) + var laddr, raddr Addr + if f[7] == "unix" { + laddr.IP = f[8] + } else { + laddr, raddr, err = parseNetAddr(f[8]) + if err != nil { + return ConnectionStat{}, fmt.Errorf("failed to parse netaddr, %s", f[8]) + } } n := ConnectionStat{ diff --git a/vendor/github.com/shirou/gopsutil/net/net_linux.go b/vendor/github.com/shirou/gopsutil/net/net_linux.go index fc2b22ea553..616c10ad2c9 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_linux.go +++ b/vendor/github.com/shirou/gopsutil/net/net_linux.go @@ -395,9 +395,7 @@ func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inode var ls []connTmp path = fmt.Sprintf("%s/net/%s", root, t.filename) switch t.family { - case syscall.AF_INET: - fallthrough - case syscall.AF_INET6: + case syscall.AF_INET, syscall.AF_INET6: ls, err = processInet(path, t, inodes, pid) case syscall.AF_UNIX: ls, err = processUnix(path, t, inodes, pid) diff --git a/vendor/github.com/shirou/gopsutil/net/net_unix.go b/vendor/github.com/shirou/gopsutil/net/net_unix.go index e3ff262e2cf..4451b545748 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_unix.go +++ b/vendor/github.com/shirou/gopsutil/net/net_unix.go @@ -63,7 +63,7 @@ func ConnectionsPidWithContext(ctx context.Context, kind string, pid int32) ([]C case "udp6": args = append(args, "6udp") case "unix": - return ret, common.ErrNotImplementedError + args = []string{"-U"} } r, err := common.CallLsofWithContext(ctx, invoke, pid, args...) diff --git a/vendor/github.com/shirou/gopsutil/net/net_windows.go b/vendor/github.com/shirou/gopsutil/net/net_windows.go index 7fff20e2bba..61eb6ec20cb 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_windows.go +++ b/vendor/github.com/shirou/gopsutil/net/net_windows.go @@ -5,15 +5,18 @@ package net import ( "context" "errors" + "fmt" "net" "os" + "syscall" + "unsafe" "github.com/shirou/gopsutil/internal/common" "golang.org/x/sys/windows" ) var ( - modiphlpapi = windows.NewLazyDLL("iphlpapi.dll") + modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll") procGetExtendedTCPTable = modiphlpapi.NewProc("GetExtendedTcpTable") procGetExtendedUDPTable = modiphlpapi.NewProc("GetExtendedUdpTable") ) @@ -30,6 +33,46 @@ const ( TCPTableOwnerModuleAll ) +type netConnectionKindType struct { + family uint32 + sockType uint32 + filename string +} + +var kindTCP4 = netConnectionKindType{ + family: syscall.AF_INET, + sockType: syscall.SOCK_STREAM, + filename: "tcp", +} +var kindTCP6 = netConnectionKindType{ + family: syscall.AF_INET6, + sockType: syscall.SOCK_STREAM, + filename: "tcp6", +} +var kindUDP4 = netConnectionKindType{ + family: syscall.AF_INET, + sockType: syscall.SOCK_DGRAM, + filename: "udp", +} +var kindUDP6 = netConnectionKindType{ + family: syscall.AF_INET6, + sockType: syscall.SOCK_DGRAM, + filename: "udp6", +} + +var netConnectionKindMap = map[string][]netConnectionKindType{ + "all": {kindTCP4, kindTCP6, kindUDP4, kindUDP6}, + "tcp": {kindTCP4, kindTCP6}, + "tcp4": {kindTCP4}, + "tcp6": {kindTCP6}, + "udp": {kindUDP4, kindUDP6}, + "udp4": {kindUDP4}, + "udp6": {kindUDP6}, + "inet": {kindTCP4, kindTCP6, kindUDP4, kindUDP6}, + "inet4": {kindTCP4, kindUDP4}, + "inet6": {kindTCP6, kindUDP6}, +} + func IOCounters(pernic bool) ([]IOCountersStat, error) { return IOCountersWithContext(context.Background(), pernic) } @@ -78,15 +121,71 @@ func IOCountersByFileWithContext(ctx context.Context, pernic bool, filename stri return IOCounters(pernic) } -// Return a list of network connections opened by a process +// Return a list of network connections +// Available kind: +// reference to netConnectionKindMap func Connections(kind string) ([]ConnectionStat, error) { return ConnectionsWithContext(context.Background(), kind) } func ConnectionsWithContext(ctx context.Context, kind string) ([]ConnectionStat, error) { - var ret []ConnectionStat + return ConnectionsPidWithContext(ctx, kind, 0) +} + +// ConnectionsPid Return a list of network connections opened by a process +func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { + return ConnectionsPidWithContext(context.Background(), kind, pid) +} + +func ConnectionsPidWithContext(ctx context.Context, kind string, pid int32) ([]ConnectionStat, error) { + tmap, ok := netConnectionKindMap[kind] + if !ok { + return nil, fmt.Errorf("invalid kind, %s", kind) + } + return getProcInet(tmap, pid) +} + +func getProcInet(kinds []netConnectionKindType, pid int32) ([]ConnectionStat, error) { + stats := make([]ConnectionStat, 0) + + for _, kind := range kinds { + s, err := getNetStatWithKind(kind) + if err != nil { + continue + } - return ret, common.ErrNotImplementedError + if pid == 0 { + stats = append(stats, s...) + } else { + for _, ns := range s { + if ns.Pid != pid { + continue + } + stats = append(stats, ns) + } + } + } + + return stats, nil +} + +func getNetStatWithKind(kindType netConnectionKindType) ([]ConnectionStat, error) { + if kindType.filename == "" { + return nil, fmt.Errorf("kind filename must be required") + } + + switch kindType.filename { + case kindTCP4.filename: + return getTCPConnections(kindTCP4.family) + case kindTCP6.filename: + return getTCPConnections(kindTCP6.family) + case kindUDP4.filename: + return getUDPConnections(kindUDP4.family) + case kindUDP6.filename: + return getUDPConnections(kindUDP6.family) + } + + return nil, fmt.Errorf("invalid kind filename, %s", kindType.filename) } // Return a list of network connections opened returning at most `max` @@ -118,3 +217,429 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) { func ProtoCountersWithContext(ctx context.Context, protocols []string) ([]ProtoCountersStat, error) { return nil, errors.New("NetProtoCounters not implemented for windows") } + +func getTableUintptr(family uint32, buf []byte) uintptr { + var ( + pmibTCPTable pmibTCPTableOwnerPidAll + pmibTCP6Table pmibTCP6TableOwnerPidAll + + p uintptr + ) + switch family { + case kindTCP4.family: + if len(buf) > 0 { + pmibTCPTable = (*mibTCPTableOwnerPid)(unsafe.Pointer(&buf[0])) + p = uintptr(unsafe.Pointer(pmibTCPTable)) + } else { + p = uintptr(unsafe.Pointer(pmibTCPTable)) + } + case kindTCP6.family: + if len(buf) > 0 { + pmibTCP6Table = (*mibTCP6TableOwnerPid)(unsafe.Pointer(&buf[0])) + p = uintptr(unsafe.Pointer(pmibTCP6Table)) + } else { + p = uintptr(unsafe.Pointer(pmibTCP6Table)) + } + } + return p +} + +func getTableInfo(filename string, table interface{}) (index, step, length int) { + switch filename { + case kindTCP4.filename: + index = int(unsafe.Sizeof(table.(pmibTCPTableOwnerPidAll).DwNumEntries)) + step = int(unsafe.Sizeof(table.(pmibTCPTableOwnerPidAll).Table)) + length = int(table.(pmibTCPTableOwnerPidAll).DwNumEntries) + case kindTCP6.filename: + index = int(unsafe.Sizeof(table.(pmibTCP6TableOwnerPidAll).DwNumEntries)) + step = int(unsafe.Sizeof(table.(pmibTCP6TableOwnerPidAll).Table)) + length = int(table.(pmibTCP6TableOwnerPidAll).DwNumEntries) + case kindUDP4.filename: + index = int(unsafe.Sizeof(table.(pmibUDPTableOwnerPid).DwNumEntries)) + step = int(unsafe.Sizeof(table.(pmibUDPTableOwnerPid).Table)) + length = int(table.(pmibUDPTableOwnerPid).DwNumEntries) + case kindUDP6.filename: + index = int(unsafe.Sizeof(table.(pmibUDP6TableOwnerPid).DwNumEntries)) + step = int(unsafe.Sizeof(table.(pmibUDP6TableOwnerPid).Table)) + length = int(table.(pmibUDP6TableOwnerPid).DwNumEntries) + } + + return +} + +func getTCPConnections(family uint32) ([]ConnectionStat, error) { + var ( + p uintptr + buf []byte + size uint32 + + pmibTCPTable pmibTCPTableOwnerPidAll + pmibTCP6Table pmibTCP6TableOwnerPidAll + ) + + if family == 0 { + return nil, fmt.Errorf("faimly must be required") + } + + for { + switch family { + case kindTCP4.family: + if len(buf) > 0 { + pmibTCPTable = (*mibTCPTableOwnerPid)(unsafe.Pointer(&buf[0])) + p = uintptr(unsafe.Pointer(pmibTCPTable)) + } else { + p = uintptr(unsafe.Pointer(pmibTCPTable)) + } + case kindTCP6.family: + if len(buf) > 0 { + pmibTCP6Table = (*mibTCP6TableOwnerPid)(unsafe.Pointer(&buf[0])) + p = uintptr(unsafe.Pointer(pmibTCP6Table)) + } else { + p = uintptr(unsafe.Pointer(pmibTCP6Table)) + } + } + + err := getExtendedTcpTable(p, + &size, + true, + family, + tcpTableOwnerPidAll, + 0) + if err == nil { + break + } + if err != windows.ERROR_INSUFFICIENT_BUFFER { + return nil, err + } + buf = make([]byte, size) + } + + var ( + index, step int + length int + ) + + stats := make([]ConnectionStat, 0) + switch family { + case kindTCP4.family: + index, step, length = getTableInfo(kindTCP4.filename, pmibTCPTable) + case kindTCP6.family: + index, step, length = getTableInfo(kindTCP6.filename, pmibTCP6Table) + } + + if length == 0 { + return nil, nil + } + + for i := 0; i < length; i++ { + switch family { + case kindTCP4.family: + mibs := (*mibTCPRowOwnerPid)(unsafe.Pointer(&buf[index])) + ns := mibs.convertToConnectionStat() + stats = append(stats, ns) + case kindTCP6.family: + mibs := (*mibTCP6RowOwnerPid)(unsafe.Pointer(&buf[index])) + ns := mibs.convertToConnectionStat() + stats = append(stats, ns) + } + + index += step + } + return stats, nil +} + +func getUDPConnections(family uint32) ([]ConnectionStat, error) { + var ( + p uintptr + buf []byte + size uint32 + + pmibUDPTable pmibUDPTableOwnerPid + pmibUDP6Table pmibUDP6TableOwnerPid + ) + + if family == 0 { + return nil, fmt.Errorf("faimly must be required") + } + + for { + switch family { + case kindUDP4.family: + if len(buf) > 0 { + pmibUDPTable = (*mibUDPTableOwnerPid)(unsafe.Pointer(&buf[0])) + p = uintptr(unsafe.Pointer(pmibUDPTable)) + } else { + p = uintptr(unsafe.Pointer(pmibUDPTable)) + } + case kindUDP6.family: + if len(buf) > 0 { + pmibUDP6Table = (*mibUDP6TableOwnerPid)(unsafe.Pointer(&buf[0])) + p = uintptr(unsafe.Pointer(pmibUDP6Table)) + } else { + p = uintptr(unsafe.Pointer(pmibUDP6Table)) + } + } + + err := getExtendedUdpTable( + p, + &size, + true, + family, + udpTableOwnerPid, + 0, + ) + if err == nil { + break + } + if err != windows.ERROR_INSUFFICIENT_BUFFER { + return nil, err + } + buf = make([]byte, size) + } + + var ( + index, step, length int + ) + + stats := make([]ConnectionStat, 0) + switch family { + case kindUDP4.family: + index, step, length = getTableInfo(kindUDP4.filename, pmibUDPTable) + case kindUDP6.family: + index, step, length = getTableInfo(kindUDP6.filename, pmibUDP6Table) + } + + if length == 0 { + return nil, nil + } + + for i := 0; i < length; i++ { + switch family { + case kindUDP4.family: + mibs := (*mibUDPRowOwnerPid)(unsafe.Pointer(&buf[index])) + ns := mibs.convertToConnectionStat() + stats = append(stats, ns) + case kindUDP4.family: + mibs := (*mibUDP6RowOwnerPid)(unsafe.Pointer(&buf[index])) + ns := mibs.convertToConnectionStat() + stats = append(stats, ns) + } + + index += step + } + return stats, nil +} + +// tcpStatuses https://msdn.microsoft.com/en-us/library/windows/desktop/bb485761(v=vs.85).aspx +var tcpStatuses = map[mibTCPState]string{ + 1: "CLOSED", + 2: "LISTEN", + 3: "SYN_SENT", + 4: "SYN_RECEIVED", + 5: "ESTABLISHED", + 6: "FIN_WAIT_1", + 7: "FIN_WAIT_2", + 8: "CLOSE_WAIT", + 9: "CLOSING", + 10: "LAST_ACK", + 11: "TIME_WAIT", + 12: "DELETE", +} + +func getExtendedTcpTable(pTcpTable uintptr, pdwSize *uint32, bOrder bool, ulAf uint32, tableClass tcpTableClass, reserved uint32) (errcode error) { + r1, _, _ := syscall.Syscall6(procGetExtendedTCPTable.Addr(), 6, pTcpTable, uintptr(unsafe.Pointer(pdwSize)), getUintptrFromBool(bOrder), uintptr(ulAf), uintptr(tableClass), uintptr(reserved)) + if r1 != 0 { + errcode = syscall.Errno(r1) + } + return +} + +func getExtendedUdpTable(pUdpTable uintptr, pdwSize *uint32, bOrder bool, ulAf uint32, tableClass udpTableClass, reserved uint32) (errcode error) { + r1, _, _ := syscall.Syscall6(procGetExtendedUDPTable.Addr(), 6, pUdpTable, uintptr(unsafe.Pointer(pdwSize)), getUintptrFromBool(bOrder), uintptr(ulAf), uintptr(tableClass), uintptr(reserved)) + if r1 != 0 { + errcode = syscall.Errno(r1) + } + return +} + +func getUintptrFromBool(b bool) uintptr { + if b { + return 1 + } + return 0 +} + +const anySize = 1 + +// type MIB_TCP_STATE int32 +type mibTCPState int32 + +type tcpTableClass int32 + +const ( + tcpTableBasicListener tcpTableClass = iota + tcpTableBasicConnections + tcpTableBasicAll + tcpTableOwnerPidListener + tcpTableOwnerPidConnections + tcpTableOwnerPidAll + tcpTableOwnerModuleListener + tcpTableOwnerModuleConnections + tcpTableOwnerModuleAll +) + +type udpTableClass int32 + +const ( + udpTableBasic udpTableClass = iota + udpTableOwnerPid + udpTableOwnerModule +) + +// TCP + +type mibTCPRowOwnerPid struct { + DwState uint32 + DwLocalAddr uint32 + DwLocalPort uint32 + DwRemoteAddr uint32 + DwRemotePort uint32 + DwOwningPid uint32 +} + +func (m *mibTCPRowOwnerPid) convertToConnectionStat() ConnectionStat { + ns := ConnectionStat{ + Family: kindTCP4.family, + Type: kindTCP4.sockType, + Laddr: Addr{ + IP: parseIPv4HexString(m.DwLocalAddr), + Port: uint32(decodePort(m.DwLocalPort)), + }, + Raddr: Addr{ + IP: parseIPv4HexString(m.DwRemoteAddr), + Port: uint32(decodePort(m.DwRemotePort)), + }, + Pid: int32(m.DwOwningPid), + Status: tcpStatuses[mibTCPState(m.DwState)], + } + + return ns +} + +type mibTCPTableOwnerPid struct { + DwNumEntries uint32 + Table [anySize]mibTCPRowOwnerPid +} + +type mibTCP6RowOwnerPid struct { + UcLocalAddr [16]byte + DwLocalScopeId uint32 + DwLocalPort uint32 + UcRemoteAddr [16]byte + DwRemoteScopeId uint32 + DwRemotePort uint32 + DwState uint32 + DwOwningPid uint32 +} + +func (m *mibTCP6RowOwnerPid) convertToConnectionStat() ConnectionStat { + ns := ConnectionStat{ + Family: kindTCP6.family, + Type: kindTCP6.sockType, + Laddr: Addr{ + IP: parseIPv6HexString(m.UcLocalAddr), + Port: uint32(decodePort(m.DwLocalPort)), + }, + Raddr: Addr{ + IP: parseIPv6HexString(m.UcRemoteAddr), + Port: uint32(decodePort(m.DwRemotePort)), + }, + Pid: int32(m.DwOwningPid), + Status: tcpStatuses[mibTCPState(m.DwState)], + } + + return ns +} + +type mibTCP6TableOwnerPid struct { + DwNumEntries uint32 + Table [anySize]mibTCP6RowOwnerPid +} + +type pmibTCPTableOwnerPidAll *mibTCPTableOwnerPid +type pmibTCP6TableOwnerPidAll *mibTCP6TableOwnerPid + +// UDP + +type mibUDPRowOwnerPid struct { + DwLocalAddr uint32 + DwLocalPort uint32 + DwOwningPid uint32 +} + +func (m *mibUDPRowOwnerPid) convertToConnectionStat() ConnectionStat { + ns := ConnectionStat{ + Family: kindUDP4.family, + Type: kindUDP4.sockType, + Laddr: Addr{ + IP: parseIPv4HexString(m.DwLocalAddr), + Port: uint32(decodePort(m.DwLocalPort)), + }, + Pid: int32(m.DwOwningPid), + } + + return ns +} + +type mibUDPTableOwnerPid struct { + DwNumEntries uint32 + Table [anySize]mibUDPRowOwnerPid +} + +type mibUDP6RowOwnerPid struct { + UcLocalAddr [16]byte + DwLocalScopeId uint32 + DwLocalPort uint32 + DwOwningPid uint32 +} + +func (m *mibUDP6RowOwnerPid) convertToConnectionStat() ConnectionStat { + ns := ConnectionStat{ + Family: kindUDP6.family, + Type: kindUDP6.sockType, + Laddr: Addr{ + IP: parseIPv6HexString(m.UcLocalAddr), + Port: uint32(decodePort(m.DwLocalPort)), + }, + Pid: int32(m.DwOwningPid), + } + + return ns +} + +type mibUDP6TableOwnerPid struct { + DwNumEntries uint32 + Table [anySize]mibUDP6RowOwnerPid +} + +type pmibUDPTableOwnerPid *mibUDPTableOwnerPid +type pmibUDP6TableOwnerPid *mibUDP6TableOwnerPid + +func decodePort(port uint32) uint16 { + return syscall.Ntohs(uint16(port)) +} + +func parseIPv4HexString(addr uint32) string { + return fmt.Sprintf("%d.%d.%d.%d", addr&255, addr>>8&255, addr>>16&255, addr>>24&255) +} + +func parseIPv6HexString(addr [16]byte) string { + var ret [16]byte + for i := 0; i < 16; i++ { + ret[i] = uint8(addr[i]) + } + + // convert []byte to net.IP + ip := net.IP(ret[:]) + return ip.String() +} diff --git a/vendor/github.com/shirou/gopsutil/v2migration.sh b/vendor/github.com/shirou/gopsutil/v2migration.sh new file mode 100644 index 00000000000..978cc44ee16 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/v2migration.sh @@ -0,0 +1,134 @@ +# This script is a helper of migration to gopsutil v2 using gorename +# +# go get golang.org/x/tools/cmd/gorename + +IFS=$'\n' + +## Part 1. rename Functions to pass golint. ex) cpu.CPUTimesStat -> cpu.TimesStat + +# +# Note: +# process has IOCounters() for file IO, and also NetIOCounters() for Net IO. +# This scripts replace process.NetIOCounters() to IOCounters(). +# So you need hand-fixing process. + +TARGETS=`cat < TimesStat +CPUInfoStat -> InfoStat +CPUTimes -> Times +CPUInfo -> Info +CPUCounts -> Counts +CPUPercent -> Percent +DiskUsageStat -> UsageStat +DiskPartitionStat -> PartitionStat +DiskIOCountersStat -> IOCountersStat +DiskPartitions -> Partitions +DiskIOCounters -> IOCounters +DiskUsage -> Usage +HostInfoStat -> InfoStat +HostInfo -> Info +GetVirtualization -> Virtualization +GetPlatformInformation -> PlatformInformation +LoadAvgStat -> AvgStat +LoadAvg -> Avg +NetIOCountersStat -> IOCountersStat +NetConnectionStat -> ConnectionStat +NetProtoCountersStat -> ProtoCountersStat +NetInterfaceAddr -> InterfaceAddr +NetInterfaceStat -> InterfaceStat +NetFilterStat -> FilterStat +NetInterfaces -> Interfaces +getNetIOCountersAll -> getIOCountersAll +NetIOCounters -> IOCounters +NetIOCountersByFile -> IOCountersByFile +NetProtoCounters -> ProtoCounters +NetFilterCounters -> FilterCounters +NetConnections -> Connections +NetConnectionsPid -> ConnectionsPid +Uid -> UID +Id -> ID +convertCpuTimes -> convertCPUTimes +EOF` + +for T in $TARGETS +do + echo $T + gofmt -w -r "$T" ./*.go +done + + +###### Part 2 rename JSON key name +## Google JSOn style +## https://google.github.io/styleguide/jsoncstyleguide.xml + +sed -i "" 's/guest_nice/guestNice/g' cpu/*.go +sed -i "" 's/vendor_id/vendorId/g' cpu/*.go +sed -i "" 's/physical_id/physicalId/g' cpu/*.go +sed -i "" 's/model_name/modelName/g' cpu/*.go +sed -i "" 's/cache_size/cacheSize/g' cpu/*.go +sed -i "" 's/core_id/coreId/g' cpu/*.go + +sed -i "" 's/inodes_total/inodesTotal/g' disk/*.go +sed -i "" 's/inodes_used/inodesUsed/g' disk/*.go +sed -i "" 's/inodes_free/inodesFree/g' disk/*.go +sed -i "" 's/inodes_used_percent/inodesUsedPercent/g' disk/*.go +sed -i "" 's/read_count/readCount/g' disk/*.go +sed -i "" 's/write_count/writeCount/g' disk/*.go +sed -i "" 's/read_bytes/readBytes/g' disk/*.go +sed -i "" 's/write_bytes/writeBytes/g' disk/*.go +sed -i "" 's/read_time/readTime/g' disk/*.go +sed -i "" 's/write_time/writeTime/g' disk/*.go +sed -i "" 's/io_time/ioTime/g' disk/*.go +sed -i "" 's/serial_number/serialNumber/g' disk/*.go +sed -i "" 's/used_percent/usedPercent/g' disk/*.go +sed -i "" 's/inodesUsed_percent/inodesUsedPercent/g' disk/*.go + +sed -i "" 's/total_cache/totalCache/g' docker/*.go +sed -i "" 's/total_rss_huge/totalRssHuge/g' docker/*.go +sed -i "" 's/total_rss/totalRss/g' docker/*.go +sed -i "" 's/total_mapped_file/totalMappedFile/g' docker/*.go +sed -i "" 's/total_pgpgin/totalPgpgin/g' docker/*.go +sed -i "" 's/total_pgpgout/totalPgpgout/g' docker/*.go +sed -i "" 's/total_pgfault/totalPgfault/g' docker/*.go +sed -i "" 's/total_pgmajfault/totalPgmajfault/g' docker/*.go +sed -i "" 's/total_inactive_anon/totalInactiveAnon/g' docker/*.go +sed -i "" 's/total_active_anon/totalActiveAnon/g' docker/*.go +sed -i "" 's/total_inactive_file/totalInactiveFile/g' docker/*.go +sed -i "" 's/total_active_file/totalActiveFile/g' docker/*.go +sed -i "" 's/total_unevictable/totalUnevictable/g' docker/*.go +sed -i "" 's/mem_usage_in_bytes/memUsageInBytes/g' docker/*.go +sed -i "" 's/mem_max_usage_in_bytes/memMaxUsageInBytes/g' docker/*.go +sed -i "" 's/memory.limit_in_bytes/memoryLimitInBbytes/g' docker/*.go +sed -i "" 's/memory.failcnt/memoryFailcnt/g' docker/*.go +sed -i "" 's/mapped_file/mappedFile/g' docker/*.go +sed -i "" 's/container_id/containerID/g' docker/*.go +sed -i "" 's/rss_huge/rssHuge/g' docker/*.go +sed -i "" 's/inactive_anon/inactiveAnon/g' docker/*.go +sed -i "" 's/active_anon/activeAnon/g' docker/*.go +sed -i "" 's/inactive_file/inactiveFile/g' docker/*.go +sed -i "" 's/active_file/activeFile/g' docker/*.go +sed -i "" 's/hierarchical_memory_limit/hierarchicalMemoryLimit/g' docker/*.go + +sed -i "" 's/boot_time/bootTime/g' host/*.go +sed -i "" 's/platform_family/platformFamily/g' host/*.go +sed -i "" 's/platform_version/platformVersion/g' host/*.go +sed -i "" 's/virtualization_system/virtualizationSystem/g' host/*.go +sed -i "" 's/virtualization_role/virtualizationRole/g' host/*.go + +sed -i "" 's/used_percent/usedPercent/g' mem/*.go + +sed -i "" 's/bytes_sent/bytesSent/g' net/*.go +sed -i "" 's/bytes_recv/bytesRecv/g' net/*.go +sed -i "" 's/packets_sent/packetsSent/g' net/*.go +sed -i "" 's/packets_recv/packetsRecv/g' net/*.go +sed -i "" 's/conntrack_count/conntrackCount/g' net/*.go +sed -i "" 's/conntrack_max/conntrackMax/g' net/*.go + +sed -i "" 's/read_count/readCount/g' process/*.go +sed -i "" 's/write_count/writeCount/g' process/*.go +sed -i "" 's/read_bytes/readBytes/g' process/*.go +sed -i "" 's/write_bytes/writeBytes/g' process/*.go +sed -i "" 's/shared_clean/sharedClean/g' process/*.go +sed -i "" 's/shared_dirty/sharedDirty/g' process/*.go +sed -i "" 's/private_clean/privateClean/g' process/*.go +sed -i "" 's/private_dirty/privateDirty/g' process/*.go diff --git a/vendor/github.com/shirou/gopsutil/windows_memo.rst b/vendor/github.com/shirou/gopsutil/windows_memo.rst new file mode 100644 index 00000000000..38abed819ad --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/windows_memo.rst @@ -0,0 +1,36 @@ +Windows memo +===================== + +Size +---------- + +DWORD + 32-bit unsigned integer +DWORDLONG + 64-bit unsigned integer +DWORD_PTR + unsigned long type for pointer precision +DWORD32 + 32-bit unsigned integer +DWORD64 + 64-bit unsigned integer +HALF_PTR + _WIN64 = int, else short +INT + 32-bit signed integer +INT_PTR + _WIN64 = __int64 else int +LONG + 32-bit signed integer +LONGLONG + 64-bit signed integer +LONG_PTR + _WIN64 = __int64 else long +SHORT + 16-bit integer +SIZE_T + maximum number of bytes to which a pointer can point. typedef ULONG_PTR SIZE_T; +SSIZE_T + signed version of SIZE_T. typedef LONG_PTR SSIZE_T; +WORD + 16-bit unsigned integer \ No newline at end of file diff --git a/vendor/vendor.json b/vendor/vendor.json index 6689b9c1eaa..151cabc4d16 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1751,36 +1751,36 @@ "revisionTime": "2017-08-19T20:10:35Z" }, { - "checksumSHA1": "wZ7Q/3JyIlVKeYVqRUGh1zuLa9E=", + "checksumSHA1": "KUrV5Esg6Wdcrv+hDc6/p0Q3/qw=", "path": "github.com/shirou/gopsutil", - "revision": "4a180b209f5f494e5923cfce81ea30ba23915877", - "revisionTime": "2018-06-25T08:11:43Z", - "version": "v2.18.06", - "versionExact": "v2.18.06" + "revision": "0f70a4a06f7a1039305ec9b3ba9c2800f8929fba", + "revisionTime": "2018-11-24T14:38:04Z", + "version": "v2.18.11", + "versionExact": "v2.18.11" }, { - "checksumSHA1": "RPCF/ke7rAfTtFnU1M3jCZIKsj0=", + "checksumSHA1": "Qr93LUVvC2g/aTZSXEIrw4OhuXQ=", "path": "github.com/shirou/gopsutil/disk", - "revision": "4a180b209f5f494e5923cfce81ea30ba23915877", - "revisionTime": "2018-06-25T08:11:43Z", - "version": "v2.18.06", - "versionExact": "v2.18.06" + "revision": "0f70a4a06f7a1039305ec9b3ba9c2800f8929fba", + "revisionTime": "2018-11-24T14:38:04Z", + "version": "v2.18.11", + "versionExact": "v2.18.11" }, { - "checksumSHA1": "ElneFnzdyg/mWfMFukLUHdy9DHY=", + "checksumSHA1": "GR7l7Ez4ppxIfonl7aJayYRVPWc=", "path": "github.com/shirou/gopsutil/internal/common", - "revision": "4a180b209f5f494e5923cfce81ea30ba23915877", - "revisionTime": "2018-06-25T08:11:43Z", - "version": "v2.18.06", - "versionExact": "v2.18.06" + "revision": "0f70a4a06f7a1039305ec9b3ba9c2800f8929fba", + "revisionTime": "2018-11-24T14:38:04Z", + "version": "v2.18.11", + "versionExact": "v2.18.11" }, { - "checksumSHA1": "cqp+0Xxb51xFf3ekjlaS/EpipZU=", + "checksumSHA1": "wAc1Qo6T9MTYdSog78uJfCYZPtc=", "path": "github.com/shirou/gopsutil/net", - "revision": "4a180b209f5f494e5923cfce81ea30ba23915877", - "revisionTime": "2018-06-25T08:11:43Z", - "version": "v2.18.06", - "versionExact": "v2.18.06" + "revision": "0f70a4a06f7a1039305ec9b3ba9c2800f8929fba", + "revisionTime": "2018-11-24T14:38:04Z", + "version": "v2.18.11", + "versionExact": "v2.18.11" }, { "checksumSHA1": "e7mAb9jMke2ASQGZepFgOmfBFzM=",