From 2c1ea857cdff1c53f847ac0b2ae0110a0e6eba5f Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 11 Aug 2016 10:52:04 -0700 Subject: [PATCH 1/8] Remove github.com/shiro/gopsutil (leave its child packages, however) --- vendor/github.com/shirou/gopsutil/LICENSE | 61 ---- vendor/github.com/shirou/gopsutil/Makefile | 26 -- vendor/github.com/shirou/gopsutil/README.rst | 300 ------------------ vendor/github.com/shirou/gopsutil/circle.yml | 11 - vendor/github.com/shirou/gopsutil/coverall.sh | 26 -- vendor/github.com/shirou/gopsutil/doc.go | 1 - vendor/github.com/shirou/gopsutil/mktypes.sh | 37 --- .../github.com/shirou/gopsutil/v2migration.sh | 134 -------- .../shirou/gopsutil/windows_memo.rst | 36 --- 9 files changed, 632 deletions(-) delete mode 100644 vendor/github.com/shirou/gopsutil/LICENSE delete mode 100644 vendor/github.com/shirou/gopsutil/Makefile delete mode 100644 vendor/github.com/shirou/gopsutil/README.rst delete mode 100644 vendor/github.com/shirou/gopsutil/circle.yml delete mode 100644 vendor/github.com/shirou/gopsutil/coverall.sh delete mode 100644 vendor/github.com/shirou/gopsutil/doc.go delete mode 100644 vendor/github.com/shirou/gopsutil/mktypes.sh delete mode 100644 vendor/github.com/shirou/gopsutil/v2migration.sh delete mode 100644 vendor/github.com/shirou/gopsutil/windows_memo.rst diff --git a/vendor/github.com/shirou/gopsutil/LICENSE b/vendor/github.com/shirou/gopsutil/LICENSE deleted file mode 100644 index da71a5e729f..00000000000 --- a/vendor/github.com/shirou/gopsutil/LICENSE +++ /dev/null @@ -1,61 +0,0 @@ -gopsutil is distributed under BSD license reproduced below. - -Copyright (c) 2014, WAKAYAMA Shirou -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the gopsutil authors nor the names of its contributors - may be used to endorse or promote products derived from this software without - specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - -------- -internal/common/binary.go in the gopsutil is copied and modifid from golang/encoding/binary.go. - - - -Copyright (c) 2009 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/vendor/github.com/shirou/gopsutil/Makefile b/vendor/github.com/shirou/gopsutil/Makefile deleted file mode 100644 index ec936f3ea80..00000000000 --- a/vendor/github.com/shirou/gopsutil/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -.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 go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=freebsd go test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=0 GOOS=darwin go test ./... | $(BUILD_FAIL_PATTERN) - CGO_ENABLED=1 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=dragonfly go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=netbsd go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=openbsd go test ./... | $(BUILD_FAIL_PATTERN) - GOOS=solaris go test ./... | $(BUILD_FAIL_PATTERN) - @echo 'Successfully built on all known operating systems' diff --git a/vendor/github.com/shirou/gopsutil/README.rst b/vendor/github.com/shirou/gopsutil/README.rst deleted file mode 100644 index 848a126b698..00000000000 --- a/vendor/github.com/shirou/gopsutil/README.rst +++ /dev/null @@ -1,300 +0,0 @@ -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 (http://pythonhosted.org/psutil/). The challenge is porting all -psutil functions on some architectures. - - -.. highlights:: Breaking Changes! - - Breaking changes is introduced at v2. See `issue 174 `_ . - - -Migrating to v2 -------------------------- - -On gopsutil itself, `v2migration.sh `_ is used for migration. It can not be commonly used, but it may help you with migration. - - -Available Architectures ------------------------------------- - -- FreeBSD i386/amd64 -- Linux i386/amd64/arm(raspberry pi) -- Windows/amd64 -- Darwin/amd64 - -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. - -Documentation ------------------------- - -see http://godoc.org/github.com/shirou/gopsutil - -Requirements ------------------ - -- go1.5 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") - -- 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 ...") - -- 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 MacOSX Windows -cpu_times x x x x -cpu_count x x x x -cpu_percent x x x x -cpu_times_percent x x x x -virtual_memory x x x x -swap_memory x x x -disk_partitions x x x x -disk_io_counters x x -disk_usage x x x x -net_io_counters x x b x -boot_time x x x x -users x x x x -pids x x x x -pid_exists x x x x -net_connections x x -net_protocols x -net_if_addrs -net_if_stats -netfilter_conntrack x -================= ====== ======= ====== ======= - -Process class -^^^^^^^^^^^^^^^ - -================ ===== ======= ====== ======= -name Linux FreeBSD MacOSX Windows -pid x x x x -ppid x x x x -name x x x x -cmdline x x x -create_time x -status x x x -cwd x -exe x x x -uids x x x -gids x x x -terminal x x x -io_counters x x x -nice x x x x -num_fds x -num_ctx_switches x -num_threads x x x x -cpu_times x -memory_info x x x x -memory_info_ex x -memory_maps x -open_files x -send_signal x x x -suspend x x x -resume x x x -terminate x x x -kill x x x -username x -ionice -rlimit -num_handlres -threads -cpu_percent x x -cpu_affinity -memory_percent -parent x x -children x x x -connections x x -is_running -================ ===== ======= ====== ======= - -Original Metrics -^^^^^^^^^^^^^^^^^^^ -================== ===== ======= ====== ======= -item Linux FreeBSD MacOSX Windows -**HostInfo** -hostname x x x x - uptime x x x - proces x x - os x x x x - platform x x x - platformfamily x x x - virtualization x -**CPU** - VendorID x x x x - Family x x x x - Model x x x x - Stepping x x x x - PhysicalID x - CoreID x - Cores x x - ModelName x x x x -**LoadAvg** - Load1 x x x - Load5 x x x - Load15 x x x -**GetDockerID** - container id x no no no -**CgroupsCPU** - user x no no no - system x no no no -**CgroupsMem** - various x 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: http://pythonhosted.org/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/circle.yml b/vendor/github.com/shirou/gopsutil/circle.yml deleted file mode 100644 index ad8c43d558d..00000000000 --- a/vendor/github.com/shirou/gopsutil/circle.yml +++ /dev/null @@ -1,11 +0,0 @@ -machine: - timezone: - Asia/Tokyo -test: - override: - - GOOS=linux GOARCH=amd64 go test -v ./... - - GOOS=linux GOARCH=386 go get -v ./... - - GOOS=linux GOARCH=arm GOARM=7 go get -v ./... - - GOOS=freebsd GOARCH=amd64 go get -v ./... - - GOOS=windows GOARCH=amd64 go get -v ./... - - GOOS=darwin GOARCH=amd64 go get -v ./... diff --git a/vendor/github.com/shirou/gopsutil/coverall.sh b/vendor/github.com/shirou/gopsutil/coverall.sh deleted file mode 100644 index 35aa298ba41..00000000000 --- a/vendor/github.com/shirou/gopsutil/coverall.sh +++ /dev/null @@ -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 - cat $tmpprof | tail -n +2 >> $prof - rm $tmpprof - fi -done diff --git a/vendor/github.com/shirou/gopsutil/doc.go b/vendor/github.com/shirou/gopsutil/doc.go deleted file mode 100644 index 6a65fe268a9..00000000000 --- a/vendor/github.com/shirou/gopsutil/doc.go +++ /dev/null @@ -1 +0,0 @@ -package gopsutil diff --git a/vendor/github.com/shirou/gopsutil/mktypes.sh b/vendor/github.com/shirou/gopsutil/mktypes.sh deleted file mode 100644 index 7bf2e241217..00000000000 --- a/vendor/github.com/shirou/gopsutil/mktypes.sh +++ /dev/null @@ -1,37 +0,0 @@ - -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/v2migration.sh b/vendor/github.com/shirou/gopsutil/v2migration.sh deleted file mode 100644 index 978cc44ee16..00000000000 --- a/vendor/github.com/shirou/gopsutil/v2migration.sh +++ /dev/null @@ -1,134 +0,0 @@ -# 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 deleted file mode 100644 index 38abed819ad..00000000000 --- a/vendor/github.com/shirou/gopsutil/windows_memo.rst +++ /dev/null @@ -1,36 +0,0 @@ -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 From 5f920feac2c9bb04b5c46e1e84338e3f2fcf0117 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 11 Aug 2016 10:57:09 -0700 Subject: [PATCH 2/8] Update github.com/shirou/gopsutil/host to include HostID update --- vendor/github.com/shirou/gopsutil/LICENSE | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 vendor/github.com/shirou/gopsutil/LICENSE diff --git a/vendor/github.com/shirou/gopsutil/LICENSE b/vendor/github.com/shirou/gopsutil/LICENSE new file mode 100644 index 00000000000..da71a5e729f --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/LICENSE @@ -0,0 +1,61 @@ +gopsutil is distributed under BSD license reproduced below. + +Copyright (c) 2014, WAKAYAMA Shirou +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + * Neither the name of the gopsutil authors nor the names of its contributors + may be used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +------- +internal/common/binary.go in the gopsutil is copied and modifid from golang/encoding/binary.go. + + + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file From 6c194a47c211504dda968b9120e6e886b65c0800 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Thu, 11 Aug 2016 11:43:45 -0700 Subject: [PATCH 3/8] Generate a durable NodeID if possible, otherwise fall back to a random HostID. --- client/client.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/client/client.go b/client/client.go index 620b853daa2..fcc4e1d7519 100644 --- a/client/client.go +++ b/client/client.go @@ -32,6 +32,7 @@ import ( "github.com/hashicorp/nomad/nomad/structs" vaultapi "github.com/hashicorp/vault/api" "github.com/mitchellh/hashstructure" + "github.com/shirou/gopsutil/host" ) const ( @@ -629,12 +630,23 @@ func (c *Client) getAllocRunners() map[string]*AllocRunner { return runners } -// nodeIDs restores the nodes persistent unique ID and SecretID or generates new -// ones -func (c *Client) nodeID() (id string, secret string, err error) { +// nodeID restores, or generates if necessary, a unique node ID and SecretID. +// The node ID is, if available, a persistent unique ID. The secret ID is a +// high-entropy random UUID. +func (c *Client) nodeID() (id, secret string, err error) { + var hostID string + hostInfo, err := host.Info() + if err == nil && hostInfo.HostID != "" { + hostID = hostInfo.HostID + } else { + // Generate a random hostID if no constant ID is available on + // this platform. + hostID = structs.GenerateUUID() + } + // Do not persist in dev mode if c.config.DevMode { - return structs.GenerateUUID(), structs.GenerateUUID(), nil + return hostID, nil } // Attempt to read existing ID @@ -655,8 +667,7 @@ func (c *Client) nodeID() (id string, secret string, err error) { if len(idBuf) != 0 { id = string(idBuf) } else { - // Generate new ID - id = structs.GenerateUUID() + id = hostID // Persist the ID if err := ioutil.WriteFile(idPath, []byte(id), 0700); err != nil { @@ -686,7 +697,7 @@ func (c *Client) setupNode() error { node = &structs.Node{} c.config.Node = node } - // Generate an iD for the node + // Generate an ID and secret for the node id, secretID, err := c.nodeID() if err != nil { return fmt.Errorf("node ID setup failed: %v", err) From e4df8042e35c3d1e0ed99d1a1fe7d5d1275803e2 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 1 Feb 2017 22:20:52 -0800 Subject: [PATCH 4/8] Slight mis-merge: secret-id in dev mode is random and needs to be returned. --- client/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index fcc4e1d7519..3ad8f07bd04 100644 --- a/client/client.go +++ b/client/client.go @@ -646,7 +646,7 @@ func (c *Client) nodeID() (id, secret string, err error) { // Do not persist in dev mode if c.config.DevMode { - return hostID, nil + return hostID, structs.GenerateUUID(), nil } // Attempt to read existing ID From 2b7861630daa87493c6c0ca11f9f0aea876b0442 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 1 Feb 2017 22:25:39 -0800 Subject: [PATCH 5/8] Update `github.com/shirou/w32` --- vendor/github.com/shirou/w32/advapi32.go | 2 ++ vendor/github.com/shirou/w32/comctl32.go | 2 ++ vendor/github.com/shirou/w32/comdlg32.go | 2 ++ vendor/github.com/shirou/w32/constants.go | 4 ++-- vendor/github.com/shirou/w32/dwmapi.go | 2 ++ vendor/github.com/shirou/w32/gdi32.go | 2 ++ vendor/github.com/shirou/w32/gdiplus.go | 2 ++ vendor/github.com/shirou/w32/idispatch.go | 2 ++ vendor/github.com/shirou/w32/istream.go | 2 ++ vendor/github.com/shirou/w32/iunknown.go | 2 ++ vendor/github.com/shirou/w32/kernel32.go | 2 ++ vendor/github.com/shirou/w32/ole32.go | 2 ++ vendor/github.com/shirou/w32/oleaut32.go | 2 ++ vendor/github.com/shirou/w32/opengl32.go | 2 ++ vendor/github.com/shirou/w32/psapi.go | 2 ++ vendor/github.com/shirou/w32/shell32.go | 2 ++ vendor/github.com/shirou/w32/user32.go | 2 ++ vendor/github.com/shirou/w32/utils.go | 2 ++ vendor/vendor.json | 4 +++- 19 files changed, 39 insertions(+), 3 deletions(-) diff --git a/vendor/github.com/shirou/w32/advapi32.go b/vendor/github.com/shirou/w32/advapi32.go index 2f8a4fe0109..35fd35a6761 100644 --- a/vendor/github.com/shirou/w32/advapi32.go +++ b/vendor/github.com/shirou/w32/advapi32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/comctl32.go b/vendor/github.com/shirou/w32/comctl32.go index 4f4e6b53a5b..51395580e1f 100644 --- a/vendor/github.com/shirou/w32/comctl32.go +++ b/vendor/github.com/shirou/w32/comctl32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/comdlg32.go b/vendor/github.com/shirou/w32/comdlg32.go index 37bc98581d7..ad9f7762fda 100644 --- a/vendor/github.com/shirou/w32/comdlg32.go +++ b/vendor/github.com/shirou/w32/comdlg32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/constants.go b/vendor/github.com/shirou/w32/constants.go index 1fd6a856e78..62d2d4b3188 100644 --- a/vendor/github.com/shirou/w32/constants.go +++ b/vendor/github.com/shirou/w32/constants.go @@ -1047,7 +1047,7 @@ const ( MB_DEFBUTTON4 = 0x00000300 ) -//COM +//COM const ( E_INVALIDARG = 0x80070057 E_OUTOFMEMORY = 0x8007000E @@ -2281,7 +2281,7 @@ const ( SC_MANAGER_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SC_MANAGER_CONNECT | SC_MANAGER_CREATE_SERVICE | SC_MANAGER_ENUMERATE_SERVICE | SC_MANAGER_LOCK | SC_MANAGER_QUERY_LOCK_STATUS | SC_MANAGER_MODIFY_BOOT_CONFIG ) -// Service Types (Bit Mask) +// Service Types (Bit Mask) const ( SERVICE_KERNEL_DRIVER = 0x00000001 SERVICE_FILE_SYSTEM_DRIVER = 0x00000002 diff --git a/vendor/github.com/shirou/w32/dwmapi.go b/vendor/github.com/shirou/w32/dwmapi.go index eb656d18748..139b93745a2 100644 --- a/vendor/github.com/shirou/w32/dwmapi.go +++ b/vendor/github.com/shirou/w32/dwmapi.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/gdi32.go b/vendor/github.com/shirou/w32/gdi32.go index 6f377e8e4cc..34f032c7bc5 100644 --- a/vendor/github.com/shirou/w32/gdi32.go +++ b/vendor/github.com/shirou/w32/gdi32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/gdiplus.go b/vendor/github.com/shirou/w32/gdiplus.go index f3a8fca4d12..443334b0b7f 100644 --- a/vendor/github.com/shirou/w32/gdiplus.go +++ b/vendor/github.com/shirou/w32/gdiplus.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/idispatch.go b/vendor/github.com/shirou/w32/idispatch.go index 41634a64889..d6c2504d8ba 100644 --- a/vendor/github.com/shirou/w32/idispatch.go +++ b/vendor/github.com/shirou/w32/idispatch.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/istream.go b/vendor/github.com/shirou/w32/istream.go index 2b840c3b09f..0bb28222257 100644 --- a/vendor/github.com/shirou/w32/istream.go +++ b/vendor/github.com/shirou/w32/istream.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/iunknown.go b/vendor/github.com/shirou/w32/iunknown.go index d63ff1bbcae..847fba7ecdb 100644 --- a/vendor/github.com/shirou/w32/iunknown.go +++ b/vendor/github.com/shirou/w32/iunknown.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 type pIUnknownVtbl struct { diff --git a/vendor/github.com/shirou/w32/kernel32.go b/vendor/github.com/shirou/w32/kernel32.go index 891ec1578b4..5d5b4d8aaef 100644 --- a/vendor/github.com/shirou/w32/kernel32.go +++ b/vendor/github.com/shirou/w32/kernel32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/ole32.go b/vendor/github.com/shirou/w32/ole32.go index a7f79b550d7..48589848c1c 100644 --- a/vendor/github.com/shirou/w32/ole32.go +++ b/vendor/github.com/shirou/w32/ole32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/oleaut32.go b/vendor/github.com/shirou/w32/oleaut32.go index 0eeeab72462..cdfcb00381d 100644 --- a/vendor/github.com/shirou/w32/oleaut32.go +++ b/vendor/github.com/shirou/w32/oleaut32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/opengl32.go b/vendor/github.com/shirou/w32/opengl32.go index 7363bb10ad6..4f35f19ef85 100644 --- a/vendor/github.com/shirou/w32/opengl32.go +++ b/vendor/github.com/shirou/w32/opengl32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/psapi.go b/vendor/github.com/shirou/w32/psapi.go index bd1e12627c5..ab7858cb552 100644 --- a/vendor/github.com/shirou/w32/psapi.go +++ b/vendor/github.com/shirou/w32/psapi.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/shell32.go b/vendor/github.com/shirou/w32/shell32.go index 0923b8b61d6..0f5ce8cbd02 100644 --- a/vendor/github.com/shirou/w32/shell32.go +++ b/vendor/github.com/shirou/w32/shell32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/user32.go b/vendor/github.com/shirou/w32/user32.go index 44b87726d1c..6aa7cd70599 100644 --- a/vendor/github.com/shirou/w32/user32.go +++ b/vendor/github.com/shirou/w32/user32.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/github.com/shirou/w32/utils.go b/vendor/github.com/shirou/w32/utils.go index 4fb5b6c2c1f..69aa31a46d9 100644 --- a/vendor/github.com/shirou/w32/utils.go +++ b/vendor/github.com/shirou/w32/utils.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build windows + package w32 import ( diff --git a/vendor/vendor.json b/vendor/vendor.json index 570e53e7993..4b43c9828a8 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1031,8 +1031,10 @@ "revisionTime": "2016-08-29T23:42:49Z" }, { + "checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=", "path": "github.com/shirou/w32", - "revision": "ada3ba68f000aa1b58580e45c9d308fe0b7fc5c5" + "revision": "bb4de0191aa41b5507caa14b0650cdbddcd9280b", + "revisionTime": "2016-09-30T03:27:40Z" }, { "checksumSHA1": "tHm2SMtuRfrwh6NnnymsuoJ6e0Q=", From 12b1ee182bf5c615755265eb90e1ed0b6ae57133 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 1 Feb 2017 22:41:29 -0800 Subject: [PATCH 6/8] Update github.com/shirou/gopsutil and friends. --- vendor/github.com/shirou/gopsutil/cpu/cpu.go | 83 ++++ .../shirou/gopsutil/cpu/cpu_darwin_cgo.go | 2 +- .../shirou/gopsutil/cpu/cpu_fallback.go | 2 +- .../shirou/gopsutil/cpu/cpu_freebsd.go | 49 ++- .../shirou/gopsutil/cpu/cpu_linux.go | 27 +- .../shirou/gopsutil/cpu/cpu_openbsd.go | 110 ++++++ .../shirou/gopsutil/cpu/cpu_unix.go | 90 ----- .../shirou/gopsutil/cpu/cpu_windows.go | 19 - .../github.com/shirou/gopsutil/disk/disk.go | 1 + .../shirou/gopsutil/disk/disk_fallback.go | 2 +- .../shirou/gopsutil/disk/disk_linux.go | 5 + .../shirou/gopsutil/disk/disk_openbsd.go | 158 ++++++++ .../gopsutil/disk/disk_openbsd_amd64.go | 91 +++++ .../shirou/gopsutil/disk/disk_unix.go | 15 +- .../shirou/gopsutil/disk/types_openbsd.go | 70 ++++ .../github.com/shirou/gopsutil/host/host.go | 5 +- .../shirou/gopsutil/host/host_darwin.go | 27 +- .../shirou/gopsutil/host/host_darwin_386.go | 19 + .../shirou/gopsutil/host/host_fallback.go | 2 +- .../shirou/gopsutil/host/host_freebsd.go | 4 + .../shirou/gopsutil/host/host_freebsd_arm.go | 44 +++ .../shirou/gopsutil/host/host_linux.go | 6 +- .../shirou/gopsutil/host/host_linux_s390x.go | 45 +++ .../shirou/gopsutil/host/host_openbsd.go | 154 ++++++++ .../gopsutil/host/host_openbsd_amd64.go | 31 ++ .../shirou/gopsutil/host/host_windows.go | 6 +- .../shirou/gopsutil/host/types_openbsd.go | 43 +++ .../shirou/gopsutil/internal/common/common.go | 43 +++ .../internal/common/common_freebsd.go | 2 +- .../internal/common/common_openbsd.go | 70 ++++ .../gopsutil/internal/common/common_unix.go | 2 +- vendor/github.com/shirou/gopsutil/mem/mem.go | 4 + .../shirou/gopsutil/mem/mem_darwin.go | 8 +- .../shirou/gopsutil/mem/mem_fallback.go | 2 +- .../shirou/gopsutil/mem/mem_linux.go | 12 +- .../shirou/gopsutil/mem/mem_openbsd.go | 110 ++++++ .../shirou/gopsutil/mem/mem_openbsd_amd64.go | 122 ++++++ .../shirou/gopsutil/mem/types_openbsd.go | 34 ++ vendor/github.com/shirou/gopsutil/net/net.go | 15 +- .../shirou/gopsutil/net/net_darwin.go | 263 ++++++++++--- .../shirou/gopsutil/net/net_fallback.go | 6 +- .../shirou/gopsutil/net/net_linux.go | 126 +++++- .../shirou/gopsutil/net/net_openbsd.go | 153 ++++++++ .../shirou/gopsutil/net/net_unix.go | 11 + .../shirou/gopsutil/net/net_windows.go | 65 ++-- .../shirou/gopsutil/process/process.go | 21 + .../shirou/gopsutil/process/process_darwin.go | 29 +- .../gopsutil/process/process_darwin_386.go | 234 +++++++++++ .../gopsutil/process/process_fallback.go | 2 +- .../gopsutil/process/process_freebsd_386.go | 304 +++++++-------- .../gopsutil/process/process_freebsd_amd64.go | 304 +++++++-------- .../gopsutil/process/process_freebsd_arm.go | 192 ++++++++++ .../shirou/gopsutil/process/process_linux.go | 129 ++++++- .../gopsutil/process/process_linux_386.go | 9 - .../gopsutil/process/process_linux_amd64.go | 9 - .../gopsutil/process/process_linux_arm.go | 9 - .../gopsutil/process/process_linux_arm64.go | 9 - .../gopsutil/process/process_openbsd.go | 362 ++++++++++++++++++ .../gopsutil/process/process_openbsd_amd64.go | 200 ++++++++++ .../shirou/gopsutil/process/process_posix.go | 22 +- .../gopsutil/process/process_windows.go | 13 +- .../shirou/gopsutil/process/types_openbsd.go | 103 +++++ vendor/vendor.json | 48 +-- 63 files changed, 3505 insertions(+), 652 deletions(-) create mode 100644 vendor/github.com/shirou/gopsutil/cpu/cpu_openbsd.go delete mode 100644 vendor/github.com/shirou/gopsutil/cpu/cpu_unix.go create mode 100644 vendor/github.com/shirou/gopsutil/disk/disk_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/disk/disk_openbsd_amd64.go create mode 100644 vendor/github.com/shirou/gopsutil/disk/types_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/host/host_darwin_386.go create mode 100644 vendor/github.com/shirou/gopsutil/host/host_freebsd_arm.go create mode 100644 vendor/github.com/shirou/gopsutil/host/host_linux_s390x.go create mode 100644 vendor/github.com/shirou/gopsutil/host/host_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/host/host_openbsd_amd64.go create mode 100644 vendor/github.com/shirou/gopsutil/host/types_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/internal/common/common_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/mem/mem_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/mem/mem_openbsd_amd64.go create mode 100644 vendor/github.com/shirou/gopsutil/mem/types_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/net/net_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/process/process_darwin_386.go create mode 100644 vendor/github.com/shirou/gopsutil/process/process_freebsd_arm.go delete mode 100644 vendor/github.com/shirou/gopsutil/process/process_linux_386.go delete mode 100644 vendor/github.com/shirou/gopsutil/process/process_linux_amd64.go delete mode 100644 vendor/github.com/shirou/gopsutil/process/process_linux_arm.go delete mode 100644 vendor/github.com/shirou/gopsutil/process/process_linux_arm64.go create mode 100644 vendor/github.com/shirou/gopsutil/process/process_openbsd.go create mode 100644 vendor/github.com/shirou/gopsutil/process/process_openbsd_amd64.go create mode 100644 vendor/github.com/shirou/gopsutil/process/types_openbsd.go diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu.go b/vendor/github.com/shirou/gopsutil/cpu/cpu.go index 6f76b764c08..b51e27ff606 100644 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu.go +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu.go @@ -2,10 +2,12 @@ package cpu import ( "encoding/json" + "fmt" "runtime" "strconv" "strings" "sync" + "time" "github.com/shirou/gopsutil/internal/common" ) @@ -91,3 +93,84 @@ func (c InfoStat) String() string { s, _ := json.Marshal(c) return string(s) } + +func getAllBusy(t TimesStat) (float64, float64) { + busy := t.User + t.System + t.Nice + t.Iowait + t.Irq + + t.Softirq + t.Steal + t.Guest + t.GuestNice + t.Stolen + return busy + t.Idle, busy +} + +func calculateBusy(t1, t2 TimesStat) float64 { + t1All, t1Busy := getAllBusy(t1) + t2All, t2Busy := getAllBusy(t2) + + if t2Busy <= t1Busy { + return 0 + } + if t2All <= t1All { + return 1 + } + return (t2Busy - t1Busy) / (t2All - t1All) * 100 +} + +func calculateAllBusy(t1, t2 []TimesStat) ([]float64, error) { + // Make sure the CPU measurements have the same length. + if len(t1) != len(t2) { + return nil, fmt.Errorf( + "received two CPU counts: %d != %d", + len(t1), len(t2), + ) + } + + ret := make([]float64, len(t1)) + for i, t := range t2 { + ret[i] = calculateBusy(t1[i], t) + } + return ret, nil +} + +//Percent calculates the percentage of cpu used either per CPU or combined. +//If an interval of 0 is given it will compare the current cpu times against the last call. +func Percent(interval time.Duration, percpu bool) ([]float64, error) { + if interval <= 0 { + return percentUsedFromLastCall(percpu) + } + + // Get CPU usage at the start of the interval. + cpuTimes1, err := Times(percpu) + if err != nil { + return nil, err + } + + time.Sleep(interval) + + // And at the end of the interval. + cpuTimes2, err := Times(percpu) + if err != nil { + return nil, err + } + + return calculateAllBusy(cpuTimes1, cpuTimes2) +} + +func percentUsedFromLastCall(percpu bool) ([]float64, error) { + cpuTimes, err := Times(percpu) + if err != nil { + return nil, err + } + lastCPUPercent.Lock() + defer lastCPUPercent.Unlock() + var lastTimes []TimesStat + if percpu { + lastTimes = lastCPUPercent.lastPerCPUTimes + lastCPUPercent.lastPerCPUTimes = cpuTimes + } else { + lastTimes = lastCPUPercent.lastCPUTimes + lastCPUPercent.lastCPUTimes = cpuTimes + } + + if lastTimes == nil { + return nil, fmt.Errorf("Error getting times for cpu percent. LastTimes was nil") + } + return calculateAllBusy(lastTimes, cpuTimes) +} diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_darwin_cgo.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_darwin_cgo.go index 6b813d78e33..180e0afa73f 100644 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu_darwin_cgo.go +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu_darwin_cgo.go @@ -57,7 +57,7 @@ func perCPUTimes() ([]TimesStat, error) { // copy the cpuload array to a []byte buffer // where we can binary.Read the data size := int(ncpu) * binary.Size(cpu_ticks) - buf := C.GoBytes(unsafe.Pointer(cpuload), C.int(size)) + buf := (*[1 << 30]byte)(unsafe.Pointer(cpuload))[:size:size] bbuf := bytes.NewBuffer(buf) diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_fallback.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_fallback.go index 4fc8257a914..ffed727be5c 100644 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu_fallback.go +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows package cpu diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_freebsd.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_freebsd.go index edc962788e1..5834d6e11bd 100644 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu_freebsd.go +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu_freebsd.go @@ -21,6 +21,12 @@ const ( ) var ClocksPerSec = float64(128) +var cpuMatch = regexp.MustCompile(`^CPU:`) +var originMatch = regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`) +var featuresMatch = regexp.MustCompile(`Features=.+<(.+)>`) +var featuresMatch2 = regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`) +var cpuEnd = regexp.MustCompile(`^Trying to mount root`) +var cpuCores = regexp.MustCompile(`FreeBSD/SMP: (\d*) package\(s\) x (\d*) core\(s\)`) func init() { getconf, err := exec.LookPath("/usr/bin/getconf") @@ -102,18 +108,18 @@ func Times(percpu bool) ([]TimesStat, error) { // are the same across CPUs. func Info() ([]InfoStat, error) { const dmesgBoot = "/var/run/dmesg.boot" - lines, _ := common.ReadLines(dmesgBoot) - c := InfoStat{} + c, num, err := parseDmesgBoot(dmesgBoot) + if err != nil { + return nil, err + } var vals []string - var err error if vals, err = common.DoSysctrl("hw.clockrate"); err != nil { return nil, err } if c.Mhz, err = strconv.ParseFloat(vals[0], 64); err != nil { return nil, fmt.Errorf("Unable to parse FreeBSD CPU clock rate: %v", err) } - c.CPU = int32(c.Mhz) if vals, err = common.DoSysctrl("hw.ncpu"); err != nil { return nil, err @@ -129,26 +135,51 @@ func Info() ([]InfoStat, error) { } c.ModelName = strings.Join(vals, " ") + ret := make([]InfoStat, num) + for i := 0; i < num; i++ { + ret[i] = c + } + + return ret, nil +} + +func parseDmesgBoot(fileName string) (InfoStat, int, error) { + c := InfoStat{} + lines, _ := common.ReadLines(fileName) + var cpuNum int for _, line := range lines { - if matches := regexp.MustCompile(`Origin\s*=\s*"(.+)"\s+Id\s*=\s*(.+)\s+Family\s*=\s*(.+)\s+Model\s*=\s*(.+)\s+Stepping\s*=\s*(.+)`).FindStringSubmatch(line); matches != nil { + if matches := cpuEnd.FindStringSubmatch(line); matches != nil { + break + } else if matches := originMatch.FindStringSubmatch(line); matches != nil { c.VendorID = matches[1] c.Family = matches[3] c.Model = matches[4] t, err := strconv.ParseInt(matches[5], 10, 32) if err != nil { - return nil, fmt.Errorf("Unable to parse FreeBSD CPU stepping information from %q: %v", line, err) + return c, 0, fmt.Errorf("Unable to parse FreeBSD CPU stepping information from %q: %v", line, err) } c.Stepping = int32(t) - } else if matches := regexp.MustCompile(`Features=.+<(.+)>`).FindStringSubmatch(line); matches != nil { + } else if matches := featuresMatch.FindStringSubmatch(line); matches != nil { for _, v := range strings.Split(matches[1], ",") { c.Flags = append(c.Flags, strings.ToLower(v)) } - } else if matches := regexp.MustCompile(`Features2=[a-f\dx]+<(.+)>`).FindStringSubmatch(line); matches != nil { + } else if matches := featuresMatch2.FindStringSubmatch(line); matches != nil { for _, v := range strings.Split(matches[1], ",") { c.Flags = append(c.Flags, strings.ToLower(v)) } + } else if matches := cpuCores.FindStringSubmatch(line); matches != nil { + t, err := strconv.ParseInt(matches[1], 10, 32) + if err != nil { + return c, 0, fmt.Errorf("Unable to parse FreeBSD CPU Nums from %q: %v", line, err) + } + cpuNum = int(t) + t2, err := strconv.ParseInt(matches[2], 10, 32) + if err != nil { + return c, 0, fmt.Errorf("Unable to parse FreeBSD CPU cores from %q: %v", line, err) + } + c.Cores = int32(t2) } } - return []InfoStat{c}, nil + return c, cpuNum, nil } diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_linux.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_linux.go index 71d38842015..1e3f6f515c7 100644 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu_linux.go +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu_linux.go @@ -36,6 +36,9 @@ func Times(percpu bool) ([]TimesStat, error) { var startIdx uint = 1 for { linen, _ := common.ReadLinesOffsetN(filename, startIdx, 1) + if len(linen) == 0 { + break + } line := linen[0] if !strings.HasPrefix(line, "cpu") { break @@ -97,7 +100,7 @@ func finishCPUInfo(c *InfoStat) error { return nil } } - c.Mhz = value/1000.0 // value is in kHz + c.Mhz = value / 1000.0 // value is in kHz return nil } @@ -144,17 +147,29 @@ func Info() ([]InfoStat, error) { c.Family = value case "model": c.Model = value - case "model name": + case "model name", "cpu": c.ModelName = value - case "stepping": - t, err := strconv.ParseInt(value, 10, 64) + if strings.Contains(value, "POWER8") || + strings.Contains(value, "POWER7") { + c.Model = strings.Split(value, " ")[0] + c.Family = "POWER" + c.VendorID = "IBM" + } + case "stepping", "revision": + val := value + + if key == "revision" { + val = strings.Split(value, ".")[0] + } + + t, err := strconv.ParseInt(val, 10, 64) if err != nil { return ret, err } c.Stepping = int32(t) - case "cpu MHz": + case "cpu MHz", "clock": // treat this as the fallback value, thus we ignore error - if t, err := strconv.ParseFloat(value, 64); err == nil { + if t, err := strconv.ParseFloat(strings.Replace(value, "MHz", "", 1), 64); err == nil { c.Mhz = t } case "cache size": diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_openbsd.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_openbsd.go new file mode 100644 index 00000000000..c59bf9caa9e --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu_openbsd.go @@ -0,0 +1,110 @@ +// +build openbsd + +package cpu + +import ( + "bytes" + "encoding/binary" + "fmt" + "os/exec" + "strconv" + "strings" + "syscall" + + "github.com/shirou/gopsutil/internal/common" +) + +// sys/sched.h +const ( + CPUser = 0 + CPNice = 1 + CPSys = 2 + CPIntr = 3 + CPIdle = 4 + CPUStates = 5 +) + +// sys/sysctl.h +const ( + CTLKern = 1 // "high kernel": proc, limits + KernCptime = 40 // KERN_CPTIME + KernCptime2 = 71 // KERN_CPTIME2 +) + +var ClocksPerSec = float64(128) + +func init() { + getconf, err := exec.LookPath("/usr/bin/getconf") + if err != nil { + return + } + out, err := invoke.Command(getconf, "CLK_TCK") + // ignore errors + if err == nil { + i, err := strconv.ParseFloat(strings.TrimSpace(string(out)), 64) + if err == nil { + ClocksPerSec = float64(i) + } + } +} + +func Times(percpu bool) ([]TimesStat, error) { + var ret []TimesStat + + var ncpu int + if percpu { + ncpu, _ = Counts(true) + } else { + ncpu = 1 + } + + for i := 0; i < ncpu; i++ { + var cpuTimes [CPUStates]int64 + var mib []int32 + if percpu { + mib = []int32{CTLKern, KernCptime} + } else { + mib = []int32{CTLKern, KernCptime2, int32(i)} + } + buf, _, err := common.CallSyscall(mib) + if err != nil { + return ret, err + } + + br := bytes.NewReader(buf) + err = binary.Read(br, binary.LittleEndian, &cpuTimes) + if err != nil { + return ret, err + } + c := TimesStat{ + User: float64(cpuTimes[CPUser]) / ClocksPerSec, + Nice: float64(cpuTimes[CPNice]) / ClocksPerSec, + System: float64(cpuTimes[CPSys]) / ClocksPerSec, + Idle: float64(cpuTimes[CPIdle]) / ClocksPerSec, + Irq: float64(cpuTimes[CPIntr]) / ClocksPerSec, + } + if !percpu { + c.CPU = "cpu-total" + } else { + c.CPU = fmt.Sprintf("cpu%d", i) + } + ret = append(ret, c) + } + + return ret, nil +} + +// Returns only one (minimal) CPUInfoStat on OpenBSD +func Info() ([]InfoStat, error) { + var ret []InfoStat + + c := InfoStat{} + + v, err := syscall.Sysctl("hw.model") + if err != nil { + return nil, err + } + c.ModelName = v + + return append(ret, c), nil +} diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_unix.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_unix.go deleted file mode 100644 index 0ed7d62ad8d..00000000000 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu_unix.go +++ /dev/null @@ -1,90 +0,0 @@ -// +build linux freebsd darwin - -package cpu - -import ( - "fmt" - "time" -) - -func getAllBusy(t TimesStat) (float64, float64) { - busy := t.User + t.System + t.Nice + t.Iowait + t.Irq + - t.Softirq + t.Steal + t.Guest + t.GuestNice + t.Stolen - return busy + t.Idle, busy -} - -func calculateBusy(t1, t2 TimesStat) float64 { - t1All, t1Busy := getAllBusy(t1) - t2All, t2Busy := getAllBusy(t2) - - if t2Busy <= t1Busy { - return 0 - } - if t2All <= t1All { - return 1 - } - return (t2Busy - t1Busy) / (t2All - t1All) * 100 -} - -func calculateAllBusy(t1, t2 []TimesStat) ([]float64, error) { - // Make sure the CPU measurements have the same length. - if len(t1) != len(t2) { - return nil, fmt.Errorf( - "received two CPU counts: %d != %d", - len(t1), len(t2), - ) - } - - ret := make([]float64, len(t1)) - for i, t := range t2 { - ret[i] = calculateBusy(t1[i], t) - } - return ret, nil -} - -//Percent calculates the percentage of cpu used either per CPU or combined. -//If an interval of 0 is given it will compare the current cpu times against the last call. -func Percent(interval time.Duration, percpu bool) ([]float64, error) { - if interval <= 0 { - return percentUsedFromLastCall(percpu) - } - - // Get CPU usage at the start of the interval. - cpuTimes1, err := Times(percpu) - if err != nil { - return nil, err - } - - time.Sleep(interval) - - // And at the end of the interval. - cpuTimes2, err := Times(percpu) - if err != nil { - return nil, err - } - - return calculateAllBusy(cpuTimes1, cpuTimes2) -} - -func percentUsedFromLastCall(percpu bool) ([]float64, error) { - cpuTimes, err := Times(percpu) - if err != nil { - return nil, err - } - lastCPUPercent.Lock() - defer lastCPUPercent.Unlock() - var lastTimes []TimesStat - if percpu { - lastTimes = lastCPUPercent.lastPerCPUTimes - lastCPUPercent.lastPerCPUTimes = cpuTimes - } else { - lastTimes = lastCPUPercent.lastCPUTimes - lastCPUPercent.lastCPUTimes = cpuTimes - } - - if lastTimes == nil { - return nil, fmt.Errorf("Error getting times for cpu percent. LastTimes was nil") - } - return calculateAllBusy(lastTimes, cpuTimes) - -} diff --git a/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go b/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go index fbd25e6057d..a32d2419af8 100644 --- a/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go +++ b/vendor/github.com/shirou/gopsutil/cpu/cpu_windows.go @@ -5,7 +5,6 @@ package cpu import ( "fmt" "syscall" - "time" "unsafe" "github.com/StackExchange/wmi" @@ -85,21 +84,3 @@ func Info() ([]InfoStat, error) { return ret, nil } - -func Percent(interval time.Duration, percpu bool) ([]float64, error) { - var ret []float64 - var dst []Win32_Processor - q := wmi.CreateQuery(&dst, "") - err := wmi.Query(q, &dst) - if err != nil { - return ret, err - } - for _, l := range dst { - // use range but windows can only get one percent. - if l.LoadPercentage == nil { - continue - } - ret = append(ret, float64(*l.LoadPercentage)) - } - return ret, nil -} diff --git a/vendor/github.com/shirou/gopsutil/disk/disk.go b/vendor/github.com/shirou/gopsutil/disk/disk.go index 0f310e70a0d..a2c47204d75 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk.go @@ -43,6 +43,7 @@ type IOCountersStat struct { WriteTime uint64 `json:"writeTime"` IopsInProgress uint64 `json:"iopsInProgress"` IoTime uint64 `json:"ioTime"` + WeightedIO uint64 `json:"weightedIO"` Name string `json:"name"` SerialNumber string `json:"serialNumber"` } diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go b/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go index b86db052106..6fb01a986c0 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows package disk diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_linux.go b/vendor/github.com/shirou/gopsutil/disk/disk_linux.go index a9c1bc8a724..51f17cd415b 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk_linux.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk_linux.go @@ -328,6 +328,10 @@ func IOCounters() (map[string]IOCountersStat, error) { if err != nil { return ret, err } + weightedIO, err := strconv.ParseUint((fields[13]), 10, 64) + if err != nil { + return ret, err + } d := IOCountersStat{ ReadBytes: rbytes * SectorSize, WriteBytes: wbytes * SectorSize, @@ -339,6 +343,7 @@ func IOCounters() (map[string]IOCountersStat, error) { WriteTime: wtime, IopsInProgress: iopsInProgress, IoTime: iotime, + WeightedIO: weightedIO, } if d == empty { continue diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_openbsd.go b/vendor/github.com/shirou/gopsutil/disk/disk_openbsd.go new file mode 100644 index 00000000000..2129b2b6adf --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/disk/disk_openbsd.go @@ -0,0 +1,158 @@ +// +build openbsd + +package disk + +import ( + "bytes" + "encoding/binary" + "path" + "syscall" + "unsafe" + + "github.com/shirou/gopsutil/internal/common" +) + +func Partitions(all bool) ([]PartitionStat, error) { + var ret []PartitionStat + + // get length + count, err := syscall.Getfsstat(nil, MNT_WAIT) + if err != nil { + return ret, err + } + + fs := make([]Statfs, count) + _, err = Getfsstat(fs, MNT_WAIT) + + for _, stat := range fs { + opts := "rw" + if stat.F_flags&MNT_RDONLY != 0 { + opts = "ro" + } + if stat.F_flags&MNT_SYNCHRONOUS != 0 { + opts += ",sync" + } + if stat.F_flags&MNT_NOEXEC != 0 { + opts += ",noexec" + } + if stat.F_flags&MNT_NOSUID != 0 { + opts += ",nosuid" + } + if stat.F_flags&MNT_NODEV != 0 { + opts += ",nodev" + } + if stat.F_flags&MNT_ASYNC != 0 { + opts += ",async" + } + + d := PartitionStat{ + Device: common.IntToString(stat.F_mntfromname[:]), + Mountpoint: common.IntToString(stat.F_mntonname[:]), + Fstype: common.IntToString(stat.F_fstypename[:]), + Opts: opts, + } + if all == false { + if !path.IsAbs(d.Device) || !common.PathExists(d.Device) { + continue + } + } + + ret = append(ret, d) + } + + return ret, nil +} + +func IOCounters() (map[string]IOCountersStat, error) { + ret := make(map[string]IOCountersStat) + + r, err := syscall.Sysctl("hw.diskstats") + if err != nil { + return nil, err + } + buf := []byte(r) + length := len(buf) + + count := int(uint64(length) / uint64(sizeOfDiskstats)) + + // parse buf to Diskstats + for i := 0; i < count; i++ { + b := buf[i*sizeOfDiskstats : i*sizeOfDiskstats+sizeOfDiskstats] + d, err := parseDiskstats(b) + if err != nil { + continue + } + name := common.IntToString(d.Name[:]) + + ds := IOCountersStat{ + ReadCount: d.Rxfer, + WriteCount: d.Wxfer, + ReadBytes: d.Rbytes, + WriteBytes: d.Wbytes, + Name: name, + } + ret[name] = ds + } + + return ret, nil +} + +// BT2LD(time) ((long double)(time).sec + (time).frac * BINTIME_SCALE) + +// Getfsstat is borrowed from pkg/syscall/syscall_freebsd.go +// change Statfs_t to Statfs in order to get more information +func Getfsstat(buf []Statfs, flags int) (n int, err error) { + var _p0 unsafe.Pointer + var bufsize uintptr + if len(buf) > 0 { + _p0 = unsafe.Pointer(&buf[0]) + bufsize = unsafe.Sizeof(Statfs{}) * uintptr(len(buf)) + } + r0, _, e1 := syscall.Syscall(syscall.SYS_GETFSSTAT, uintptr(_p0), bufsize, uintptr(flags)) + n = int(r0) + if e1 != 0 { + err = e1 + } + return +} + +func parseDiskstats(buf []byte) (Diskstats, error) { + var ds Diskstats + br := bytes.NewReader(buf) + // err := binary.Read(br, binary.LittleEndian, &ds) + err := common.Read(br, binary.LittleEndian, &ds) + if err != nil { + return ds, err + } + + return ds, nil +} + +func Usage(path string) (*UsageStat, error) { + stat := syscall.Statfs_t{} + err := syscall.Statfs(path, &stat) + if err != nil { + return nil, err + } + bsize := stat.F_bsize + + ret := &UsageStat{ + Path: path, + Fstype: getFsType(stat), + Total: (uint64(stat.F_blocks) * uint64(bsize)), + Free: (uint64(stat.F_bavail) * uint64(bsize)), + InodesTotal: (uint64(stat.F_files)), + InodesFree: (uint64(stat.F_ffree)), + } + + ret.InodesUsed = (ret.InodesTotal - ret.InodesFree) + ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 + ret.Used = (uint64(stat.F_blocks) - uint64(stat.F_bfree)) * uint64(bsize) + ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 + + return ret, nil +} + +func getFsType(stat syscall.Statfs_t) string { + return common.IntToString(stat.F_fstypename[:]) +} diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_openbsd_amd64.go b/vendor/github.com/shirou/gopsutil/disk/disk_openbsd_amd64.go new file mode 100644 index 00000000000..07a845fbcbc --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/disk/disk_openbsd_amd64.go @@ -0,0 +1,91 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_openbsd.go + +package disk + +const ( + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 + sizeofLongDouble = 0x8 + + DEVSTAT_NO_DATA = 0x00 + DEVSTAT_READ = 0x01 + DEVSTAT_WRITE = 0x02 + DEVSTAT_FREE = 0x03 + + MNT_RDONLY = 0x00000001 + MNT_SYNCHRONOUS = 0x00000002 + MNT_NOEXEC = 0x00000004 + MNT_NOSUID = 0x00000008 + MNT_NODEV = 0x00000010 + MNT_ASYNC = 0x00000040 + + MNT_WAIT = 1 + MNT_NOWAIT = 2 + MNT_LAZY = 3 +) + +const ( + sizeOfDiskstats = 0x70 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 + _C_long_double int64 +) + +type Statfs struct { + F_flags uint32 + F_bsize uint32 + F_iosize uint32 + Pad_cgo_0 [4]byte + F_blocks uint64 + F_bfree uint64 + F_bavail int64 + F_files uint64 + F_ffree uint64 + F_favail int64 + F_syncwrites uint64 + F_syncreads uint64 + F_asyncwrites uint64 + F_asyncreads uint64 + F_fsid Fsid + F_namemax uint32 + F_owner uint32 + F_ctime uint64 + F_fstypename [16]int8 + F_mntonname [90]int8 + F_mntfromname [90]int8 + F_mntfromspec [90]int8 + Pad_cgo_1 [2]byte + Mount_info [160]byte +} +type Diskstats struct { + Name [16]int8 + Busy int32 + Pad_cgo_0 [4]byte + Rxfer uint64 + Wxfer uint64 + Seek uint64 + Rbytes uint64 + Wbytes uint64 + Attachtime Timeval + Timestamp Timeval + Time Timeval +} +type Fsid struct { + Val [2]int32 +} +type Timeval struct { + Sec int64 + Usec int64 +} + +type Diskstat struct{} +type Bintime struct{} diff --git a/vendor/github.com/shirou/gopsutil/disk/disk_unix.go b/vendor/github.com/shirou/gopsutil/disk/disk_unix.go index 3d8133168e5..f0616c30aaa 100644 --- a/vendor/github.com/shirou/gopsutil/disk/disk_unix.go +++ b/vendor/github.com/shirou/gopsutil/disk/disk_unix.go @@ -25,10 +25,21 @@ func Usage(path string) (*UsageStat, error) { if ret.InodesTotal < ret.InodesFree { return ret, nil } + ret.InodesUsed = (ret.InodesTotal - ret.InodesFree) - ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 ret.Used = (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(bsize) - ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 + + if ret.InodesTotal == 0 { + ret.InodesUsedPercent = 0 + } else { + ret.InodesUsedPercent = (float64(ret.InodesUsed) / float64(ret.InodesTotal)) * 100.0 + } + + if ret.Total == 0 { + ret.UsedPercent = 0 + } else { + ret.UsedPercent = (float64(ret.Used) / float64(ret.Total)) * 100.0 + } return ret, nil } diff --git a/vendor/github.com/shirou/gopsutil/disk/types_openbsd.go b/vendor/github.com/shirou/gopsutil/disk/types_openbsd.go new file mode 100644 index 00000000000..1e3ddef5cfb --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/disk/types_openbsd.go @@ -0,0 +1,70 @@ +// +build ignore +// Hand writing: _Ctype_struct___0 + +/* +Input to cgo -godefs. +*/ + +package disk + +/* +#include +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + +*/ +import "C" + +// Machine characteristics; for internal use. + +const ( + sizeofPtr = C.sizeofPtr + sizeofShort = C.sizeof_short + sizeofInt = C.sizeof_int + sizeofLong = C.sizeof_long + sizeofLongLong = C.sizeof_longlong + sizeofLongDouble = C.sizeof_longlong + + DEVSTAT_NO_DATA = 0x00 + DEVSTAT_READ = 0x01 + DEVSTAT_WRITE = 0x02 + DEVSTAT_FREE = 0x03 + + // from sys/mount.h + MNT_RDONLY = 0x00000001 /* read only filesystem */ + MNT_SYNCHRONOUS = 0x00000002 /* filesystem written synchronously */ + MNT_NOEXEC = 0x00000004 /* can't exec from filesystem */ + MNT_NOSUID = 0x00000008 /* don't honor setuid bits on fs */ + MNT_NODEV = 0x00000010 /* don't interpret special files */ + MNT_ASYNC = 0x00000040 /* filesystem written asynchronously */ + + MNT_WAIT = 1 /* synchronously wait for I/O to complete */ + MNT_NOWAIT = 2 /* start all I/O, but do not wait for it */ + MNT_LAZY = 3 /* push data not written by filesystem syncer */ +) + +const ( + sizeOfDiskstats = C.sizeof_struct_diskstats +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong + _C_long_double C.longlong +) + +type Statfs C.struct_statfs +type Diskstats C.struct_diskstats +type Fsid C.fsid_t +type Timeval C.struct_timeval + +type Diskstat C.struct_diskstat +type Bintime C.struct_bintime diff --git a/vendor/github.com/shirou/gopsutil/host/host.go b/vendor/github.com/shirou/gopsutil/host/host.go index 85d4053345f..5a800a7d351 100644 --- a/vendor/github.com/shirou/gopsutil/host/host.go +++ b/vendor/github.com/shirou/gopsutil/host/host.go @@ -6,7 +6,10 @@ import ( "github.com/shirou/gopsutil/internal/common" ) -var invoke common.Invoker +var ( + invoke common.Invoker + cachedBootTime = uint64(0) +) func init() { invoke = common.Invoke{} diff --git a/vendor/github.com/shirou/gopsutil/host/host_darwin.go b/vendor/github.com/shirou/gopsutil/host/host_darwin.go index e148ed7c0f5..08e9809c823 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_darwin.go +++ b/vendor/github.com/shirou/gopsutil/host/host_darwin.go @@ -32,11 +32,11 @@ func Info() (*InfoStat, error) { ret.Hostname = hostname } - platform, family, version, err := PlatformInformation() + platform, family, pver, version, err := PlatformInformation() if err == nil { ret.Platform = platform ret.PlatformFamily = family - ret.PlatformVersion = version + ret.PlatformVersion = pver ret.KernelVersion = version } @@ -66,6 +66,9 @@ func Info() (*InfoStat, error) { } func BootTime() (uint64, error) { + if cachedBootTime != 0 { + return cachedBootTime, nil + } values, err := common.DoSysctrl("kern.boottime") if err != nil { return 0, err @@ -76,8 +79,9 @@ func BootTime() (uint64, error) { if err != nil { return 0, err } + cachedBootTime = uint64(boottime) - return uint64(boottime), nil + return cachedBootTime, nil } func uptime(boot uint64) uint64 { @@ -135,26 +139,37 @@ func Users() ([]UserStat, error) { } -func PlatformInformation() (string, string, string, error) { +func PlatformInformation() (string, string, string, string, error) { platform := "" family := "" version := "" + pver := "" + sw_vers, err := exec.LookPath("sw_vers") + if err != nil { + return "", "", "", "", err + } uname, err := exec.LookPath("uname") if err != nil { - return "", "", "", err + return "", "", "", "", err } + out, err := invoke.Command(uname, "-s") if err == nil { platform = strings.ToLower(strings.TrimSpace(string(out))) } + out, err = invoke.Command(sw_vers, "-productVersion") + if err == nil { + pver = strings.ToLower(strings.TrimSpace(string(out))) + } + out, err = invoke.Command(uname, "-r") if err == nil { version = strings.ToLower(strings.TrimSpace(string(out))) } - return platform, family, version, nil + return platform, family, pver, version, nil } func Virtualization() (string, string, error) { diff --git a/vendor/github.com/shirou/gopsutil/host/host_darwin_386.go b/vendor/github.com/shirou/gopsutil/host/host_darwin_386.go new file mode 100644 index 00000000000..c3596f9f5e9 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/host/host_darwin_386.go @@ -0,0 +1,19 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_darwin.go + +package host + +type Utmpx struct { + User [256]int8 + ID [4]int8 + Line [32]int8 + Pid int32 + Type int16 + Pad_cgo_0 [6]byte + Tv Timeval + Host [256]int8 + Pad [16]uint32 +} +type Timeval struct { + Sec int32 +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_fallback.go b/vendor/github.com/shirou/gopsutil/host/host_fallback.go index 7a9301bdf5d..0adcdf25aea 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_fallback.go +++ b/vendor/github.com/shirou/gopsutil/host/host_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows package host diff --git a/vendor/github.com/shirou/gopsutil/host/host_freebsd.go b/vendor/github.com/shirou/gopsutil/host/host_freebsd.go index b7644728686..481d3df877d 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_freebsd.go +++ b/vendor/github.com/shirou/gopsutil/host/host_freebsd.go @@ -69,6 +69,9 @@ func Info() (*InfoStat, error) { } func BootTime() (uint64, error) { + if cachedBootTime != 0 { + return cachedBootTime, nil + } values, err := common.DoSysctrl("kern.boottime") if err != nil { return 0, err @@ -80,6 +83,7 @@ func BootTime() (uint64, error) { if err != nil { return 0, err } + cachedBootTime = boottime return boottime, nil } diff --git a/vendor/github.com/shirou/gopsutil/host/host_freebsd_arm.go b/vendor/github.com/shirou/gopsutil/host/host_freebsd_arm.go new file mode 100644 index 00000000000..ac74980ae4e --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/host/host_freebsd_arm.go @@ -0,0 +1,44 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_freebsd.go + +package host + +const ( + sizeofPtr = 0x4 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 + sizeOfUtmpx = 197 // TODO: why should 197, not 0x118 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Utmp struct { + Line [8]int8 + Name [16]int8 + Host [16]int8 + Time int32 +} + +type Utmpx struct { + Type int16 + Tv Timeval + Id [8]int8 + Pid int32 + User [32]int8 + Line [16]int8 + Host [125]int8 + // Host [128]int8 + // X__ut_spare [64]int8 +} + +type Timeval struct { + Sec [4]byte + Usec [3]byte +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_linux.go b/vendor/github.com/shirou/gopsutil/host/host_linux.go index 1bae4a0642b..69cc1380cd9 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_linux.go +++ b/vendor/github.com/shirou/gopsutil/host/host_linux.go @@ -86,6 +86,9 @@ func Info() (*InfoStat, error) { // BootTime returns the system boot time expressed in seconds since the epoch. func BootTime() (uint64, error) { + if cachedBootTime != 0 { + return cachedBootTime, nil + } filename := common.HostProc("stat") lines, err := common.ReadLines(filename) if err != nil { @@ -101,7 +104,8 @@ func BootTime() (uint64, error) { if err != nil { return 0, err } - return uint64(b), nil + cachedBootTime = uint64(b) + return cachedBootTime, nil } } diff --git a/vendor/github.com/shirou/gopsutil/host/host_linux_s390x.go b/vendor/github.com/shirou/gopsutil/host/host_linux_s390x.go new file mode 100644 index 00000000000..083fbf924af --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/host/host_linux_s390x.go @@ -0,0 +1,45 @@ +// +build linux +// +build s390x +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_linux.go + +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 +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_openbsd.go b/vendor/github.com/shirou/gopsutil/host/host_openbsd.go new file mode 100644 index 00000000000..e533d8697c6 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/host/host_openbsd.go @@ -0,0 +1,154 @@ +// +build openbsd + +package host + +import ( + "bytes" + "encoding/binary" + "io/ioutil" + "os" + "os/exec" + "runtime" + "strconv" + "strings" + "time" + "unsafe" + + "github.com/shirou/gopsutil/internal/common" + "github.com/shirou/gopsutil/process" +) + +const ( + UTNameSize = 32 /* see MAXLOGNAME in */ + UTLineSize = 8 + UTHostSize = 16 +) + +func Info() (*InfoStat, error) { + ret := &InfoStat{ + OS: runtime.GOOS, + PlatformFamily: "openbsd", + } + + hostname, err := os.Hostname() + if err == nil { + ret.Hostname = hostname + } + + platform, family, version, err := PlatformInformation() + if err == nil { + ret.Platform = platform + ret.PlatformFamily = family + ret.PlatformVersion = version + } + system, role, err := Virtualization() + if err == nil { + ret.VirtualizationSystem = system + ret.VirtualizationRole = role + } + + procs, err := process.Pids() + if err == nil { + ret.Procs = uint64(len(procs)) + } + + boot, err := BootTime() + if err == nil { + ret.BootTime = boot + ret.Uptime = uptime(boot) + } + + return ret, nil +} + +func BootTime() (uint64, error) { + val, err := common.DoSysctrl("kern.boottime") + if err != nil { + return 0, err + } + + boottime, err := strconv.ParseUint(val[0], 10, 64) + if err != nil { + return 0, err + } + + return boottime, nil +} + +func uptime(boot uint64) uint64 { + return uint64(time.Now().Unix()) - boot +} + +func Uptime() (uint64, error) { + boot, err := BootTime() + if err != nil { + return 0, err + } + return uptime(boot), nil +} + +func PlatformInformation() (string, string, string, error) { + platform := "" + family := "" + version := "" + uname, err := exec.LookPath("uname") + if err != nil { + return "", "", "", err + } + + out, err := invoke.Command(uname, "-s") + if err == nil { + platform = strings.ToLower(strings.TrimSpace(string(out))) + } + + out, err = invoke.Command(uname, "-r") + if err == nil { + version = strings.ToLower(strings.TrimSpace(string(out))) + } + + return platform, family, version, nil +} + +func Virtualization() (string, string, error) { + system := "" + role := "" + + return system, role, nil +} + +func Users() ([]UserStat, error) { + var ret []UserStat + utmpfile := "/var/run/utmp" + file, err := os.Open(utmpfile) + if err != nil { + return ret, err + } + buf, err := ioutil.ReadAll(file) + if err != nil { + return ret, err + } + + u := Utmp{} + entrySize := int(unsafe.Sizeof(u)) + count := len(buf) / entrySize + + for i := 0; i < count; i++ { + b := buf[i*entrySize : i*entrySize+entrySize] + var u Utmp + br := bytes.NewReader(b) + err := binary.Read(br, binary.LittleEndian, &u) + if err != nil || u.Time == 0 { + continue + } + user := UserStat{ + User: common.IntToString(u.Name[:]), + Terminal: common.IntToString(u.Line[:]), + Host: common.IntToString(u.Host[:]), + Started: int(u.Time), + } + + ret = append(ret, user) + } + + return ret, nil +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_openbsd_amd64.go b/vendor/github.com/shirou/gopsutil/host/host_openbsd_amd64.go new file mode 100644 index 00000000000..afe0943e77e --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/host/host_openbsd_amd64.go @@ -0,0 +1,31 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_openbsd.go + +package host + +const ( + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 + sizeOfUtmp = 0x130 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Utmp struct { + Line [8]int8 + Name [32]int8 + Host [256]int8 + Time int64 +} +type Timeval struct { + Sec int64 + Usec int64 +} diff --git a/vendor/github.com/shirou/gopsutil/host/host_windows.go b/vendor/github.com/shirou/gopsutil/host/host_windows.go index abf793e5d6a..f983a4f2916 100644 --- a/vendor/github.com/shirou/gopsutil/host/host_windows.go +++ b/vendor/github.com/shirou/gopsutil/host/host_windows.go @@ -91,11 +91,15 @@ func bootTime(up uint64) uint64 { } func BootTime() (uint64, error) { + if cachedBootTime != 0 { + return cachedBootTime, nil + } up, err := Uptime() if err != nil { return 0, err } - return bootTime(up), nil + cachedBootTime = bootTime(up) + return cachedBootTime, nil } func PlatformInformation() (platform string, family string, version string, err error) { diff --git a/vendor/github.com/shirou/gopsutil/host/types_openbsd.go b/vendor/github.com/shirou/gopsutil/host/types_openbsd.go new file mode 100644 index 00000000000..9ebb97ce52e --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/host/types_openbsd.go @@ -0,0 +1,43 @@ +// +build ignore + +/* +Input to cgo -godefs. +*/ + +package host + +/* +#define KERNEL +#include +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + +*/ +import "C" + +// Machine characteristics; for internal use. + +const ( + sizeofPtr = C.sizeofPtr + sizeofShort = C.sizeof_short + sizeofInt = C.sizeof_int + sizeofLong = C.sizeof_long + sizeofLongLong = C.sizeof_longlong + sizeOfUtmp = C.sizeof_struct_utmp +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong +) + +type Utmp C.struct_utmp +type Timeval C.struct_timeval diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common.go b/vendor/github.com/shirou/gopsutil/internal/common/common.go index f0ea6dd36fd..9ad42647ded 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common.go @@ -341,3 +341,46 @@ func WaitTimeout(c *exec.Cmd, timeout time.Duration) error { return ErrTimeout } } + +// https://gist.github.com/kylelemons/1525278 +func Pipeline(cmds ...*exec.Cmd) ([]byte, []byte, error) { + // Require at least one command + if len(cmds) < 1 { + return nil, nil, nil + } + + // Collect the output from the command(s) + var output bytes.Buffer + var stderr bytes.Buffer + + last := len(cmds) - 1 + for i, cmd := range cmds[:last] { + var err error + // Connect each command's stdin to the previous command's stdout + if cmds[i+1].Stdin, err = cmd.StdoutPipe(); err != nil { + return nil, nil, err + } + // Connect each command's stderr to a buffer + cmd.Stderr = &stderr + } + + // Connect the output and error for the last command + cmds[last].Stdout, cmds[last].Stderr = &output, &stderr + + // Start each command + for _, cmd := range cmds { + if err := cmd.Start(); err != nil { + return output.Bytes(), stderr.Bytes(), err + } + } + + // Wait for each command to complete + for _, cmd := range cmds { + if err := cmd.Wait(); err != nil { + return output.Bytes(), stderr.Bytes(), err + } + } + + // Return the pipeline output and the collected standard error + return output.Bytes(), stderr.Bytes(), nil +} diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common_freebsd.go b/vendor/github.com/shirou/gopsutil/internal/common/common_freebsd.go index dfdcebd8d7d..bda4ecfa526 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common_freebsd.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common_freebsd.go @@ -1,4 +1,4 @@ -// +build freebsd +// +build freebsd openbsd package common diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common_openbsd.go b/vendor/github.com/shirou/gopsutil/internal/common/common_openbsd.go new file mode 100644 index 00000000000..959d9e56df9 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/internal/common/common_openbsd.go @@ -0,0 +1,70 @@ +// +build openbsd + +package common + +import ( + "os" + "os/exec" + "strings" + "syscall" + "unsafe" +) + +func DoSysctrl(mib string) ([]string, error) { + err := os.Setenv("LC_ALL", "C") + if err != nil { + return []string{}, err + } + sysctl, err := exec.LookPath("/sbin/sysctl") + if err != nil { + return []string{}, err + } + out, err := exec.Command(sysctl, "-n", mib).Output() + if err != nil { + return []string{}, err + } + v := strings.Replace(string(out), "{ ", "", 1) + v = strings.Replace(string(v), " }", "", 1) + values := strings.Fields(string(v)) + + return values, nil +} + +func CallSyscall(mib []int32) ([]byte, uint64, error) { + mibptr := unsafe.Pointer(&mib[0]) + miblen := uint64(len(mib)) + + // get required buffer size + length := uint64(0) + _, _, err := syscall.Syscall6( + syscall.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + 0, + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + var b []byte + return b, length, err + } + if length == 0 { + var b []byte + return b, length, err + } + // get proc info itself + buf := make([]byte, length) + _, _, err = syscall.Syscall6( + syscall.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + return buf, length, err + } + + return buf, length, nil +} diff --git a/vendor/github.com/shirou/gopsutil/internal/common/common_unix.go b/vendor/github.com/shirou/gopsutil/internal/common/common_unix.go index 6622eecc2e3..cc934dd6e92 100644 --- a/vendor/github.com/shirou/gopsutil/internal/common/common_unix.go +++ b/vendor/github.com/shirou/gopsutil/internal/common/common_unix.go @@ -1,4 +1,4 @@ -// +build linux freebsd darwin +// +build linux freebsd darwin openbsd package common diff --git a/vendor/github.com/shirou/gopsutil/mem/mem.go b/vendor/github.com/shirou/gopsutil/mem/mem.go index a6c012387dd..87dfb53b40f 100644 --- a/vendor/github.com/shirou/gopsutil/mem/mem.go +++ b/vendor/github.com/shirou/gopsutil/mem/mem.go @@ -54,6 +54,10 @@ type VirtualMemoryStat struct { Writeback uint64 `json:"writeback"` Dirty uint64 `json:"dirty"` WritebackTmp uint64 `json:"writebacktmp"` + Shared uint64 `json:"shared"` + Slab uint64 `json:"slab"` + PageTables uint64 `json:"pagetables"` + SwapCached uint64 `json:"swapcached"` } type SwapMemoryStat struct { diff --git a/vendor/github.com/shirou/gopsutil/mem/mem_darwin.go b/vendor/github.com/shirou/gopsutil/mem/mem_darwin.go index 922b05cb4f6..afd7def460e 100644 --- a/vendor/github.com/shirou/gopsutil/mem/mem_darwin.go +++ b/vendor/github.com/shirou/gopsutil/mem/mem_darwin.go @@ -57,11 +57,11 @@ func SwapMemory() (*SwapMemoryStat, error) { u = ((total_v - free_v) / total_v) * 100.0 } - // vm.swapusage shows "M", multiply 1000 + // vm.swapusage shows "M", multiply 1024 * 1024 to convert bytes. ret = &SwapMemoryStat{ - Total: uint64(total_v * 1000), - Used: uint64(used_v * 1000), - Free: uint64(free_v * 1000), + Total: uint64(total_v * 1024 * 1024), + Used: uint64(used_v * 1024 * 1024), + Free: uint64(free_v * 1024 * 1024), UsedPercent: u, } diff --git a/vendor/github.com/shirou/gopsutil/mem/mem_fallback.go b/vendor/github.com/shirou/gopsutil/mem/mem_fallback.go index 022b9422b86..b7284b2e79e 100644 --- a/vendor/github.com/shirou/gopsutil/mem/mem_fallback.go +++ b/vendor/github.com/shirou/gopsutil/mem/mem_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows package mem diff --git a/vendor/github.com/shirou/gopsutil/mem/mem_linux.go b/vendor/github.com/shirou/gopsutil/mem/mem_linux.go index 7df4c3ebb6f..e7540af74a6 100644 --- a/vendor/github.com/shirou/gopsutil/mem/mem_linux.go +++ b/vendor/github.com/shirou/gopsutil/mem/mem_linux.go @@ -52,6 +52,14 @@ func VirtualMemory() (*VirtualMemoryStat, error) { ret.WritebackTmp = t * 1024 case "Dirty": ret.Dirty = t * 1024 + case "Shmem": + ret.Shared = t * 1024 + case "Slab": + ret.Slab = t * 1024 + case "PageTables": + ret.PageTables = t * 1024 + case "SwapCached": + ret.SwapCached = t * 1024 } } if !memavail { @@ -70,8 +78,8 @@ func SwapMemory() (*SwapMemoryStat, error) { return nil, err } ret := &SwapMemoryStat{ - Total: uint64(sysinfo.Totalswap), - Free: uint64(sysinfo.Freeswap), + Total: uint64(sysinfo.Totalswap) * uint64(sysinfo.Unit), + Free: uint64(sysinfo.Freeswap) * uint64(sysinfo.Unit), } ret.Used = ret.Total - ret.Free //check Infinity diff --git a/vendor/github.com/shirou/gopsutil/mem/mem_openbsd.go b/vendor/github.com/shirou/gopsutil/mem/mem_openbsd.go new file mode 100644 index 00000000000..2e94bea11b0 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/mem/mem_openbsd.go @@ -0,0 +1,110 @@ +// +build openbsd + +package mem + +import ( + "bytes" + "encoding/binary" + "errors" + "fmt" + "github.com/shirou/gopsutil/internal/common" + "os/exec" +) + +func GetPageSize() (uint64, error) { + mib := []int32{CTLVm, VmUvmexp} + buf, length, err := common.CallSyscall(mib) + if err != nil { + return 0, err + } + if length < sizeOfUvmexp { + return 0, fmt.Errorf("short syscall ret %d bytes", length) + } + var uvmexp Uvmexp + br := bytes.NewReader(buf) + err = common.Read(br, binary.LittleEndian, &uvmexp) + if err != nil { + return 0, err + } + return uint64(uvmexp.Pagesize), nil +} + +func VirtualMemory() (*VirtualMemoryStat, error) { + mib := []int32{CTLVm, VmUvmexp} + buf, length, err := common.CallSyscall(mib) + if err != nil { + return nil, err + } + if length < sizeOfUvmexp { + return nil, fmt.Errorf("short syscall ret %d bytes", length) + } + var uvmexp Uvmexp + br := bytes.NewReader(buf) + err = common.Read(br, binary.LittleEndian, &uvmexp) + if err != nil { + return nil, err + } + p := uint64(uvmexp.Pagesize) + + ret := &VirtualMemoryStat{ + Total: uint64(uvmexp.Npages) * p, + Free: uint64(uvmexp.Free) * p, + Active: uint64(uvmexp.Active) * p, + Inactive: uint64(uvmexp.Inactive) * p, + Cached: 0, // not available + Wired: uint64(uvmexp.Wired) * p, + } + + ret.Available = ret.Inactive + ret.Cached + ret.Free + ret.Used = ret.Total - ret.Available + ret.UsedPercent = float64(ret.Used) / float64(ret.Total) * 100.0 + + mib = []int32{CTLVfs, VfsGeneric, VfsBcacheStat} + buf, length, err = common.CallSyscall(mib) + if err != nil { + return nil, err + } + if length < sizeOfBcachestats { + return nil, fmt.Errorf("short syscall ret %d bytes", length) + } + var bcs Bcachestats + br = bytes.NewReader(buf) + err = common.Read(br, binary.LittleEndian, &bcs) + if err != nil { + return nil, err + } + ret.Buffers = uint64(bcs.Numbufpages) * p + + return ret, nil +} + +// Return swapctl summary info +func SwapMemory() (*SwapMemoryStat, error) { + swapctl, err := exec.LookPath("swapctl") + if err != nil { + return nil, err + } + + out, err := invoke.Command(swapctl, "-sk") + if err != nil { + return &SwapMemoryStat{}, nil + } + + line := string(out) + var total, used, free uint64 + + _, err = fmt.Sscanf(line, + "total: %d 1K-blocks allocated, %d used, %d available", + &total, &used, &free) + if err != nil { + return nil, errors.New("failed to parse swapctl output") + } + + percent := float64(used) / float64(total) * 100 + return &SwapMemoryStat{ + Total: total * 1024, + Used: used * 1024, + Free: free * 1024, + UsedPercent: percent, + }, nil +} diff --git a/vendor/github.com/shirou/gopsutil/mem/mem_openbsd_amd64.go b/vendor/github.com/shirou/gopsutil/mem/mem_openbsd_amd64.go new file mode 100644 index 00000000000..e09b908e466 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/mem/mem_openbsd_amd64.go @@ -0,0 +1,122 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_openbsd.go + +package mem + +const ( + CTLVm = 2 + CTLVfs = 10 + VmUvmexp = 4 + VfsGeneric = 0 + VfsBcacheStat = 3 +) + +const ( + sizeOfUvmexp = 0x154 + sizeOfBcachestats = 0x78 +) + +type Uvmexp struct { + Pagesize int32 + Pagemask int32 + Pageshift int32 + Npages int32 + Free int32 + Active int32 + Inactive int32 + Paging int32 + Wired int32 + Zeropages int32 + Reserve_pagedaemon int32 + Reserve_kernel int32 + Anonpages int32 + Vnodepages int32 + Vtextpages int32 + Freemin int32 + Freetarg int32 + Inactarg int32 + Wiredmax int32 + Anonmin int32 + Vtextmin int32 + Vnodemin int32 + Anonminpct int32 + Vtextminpct int32 + Vnodeminpct int32 + Nswapdev int32 + Swpages int32 + Swpginuse int32 + Swpgonly int32 + Nswget int32 + Nanon int32 + Nanonneeded int32 + Nfreeanon int32 + Faults int32 + Traps int32 + Intrs int32 + Swtch int32 + Softs int32 + Syscalls int32 + Pageins int32 + Obsolete_swapins int32 + Obsolete_swapouts int32 + Pgswapin int32 + Pgswapout int32 + Forks int32 + Forks_ppwait int32 + Forks_sharevm int32 + Pga_zerohit int32 + Pga_zeromiss int32 + Zeroaborts int32 + Fltnoram int32 + Fltnoanon int32 + Fltpgwait int32 + Fltpgrele int32 + Fltrelck int32 + Fltrelckok int32 + Fltanget int32 + Fltanretry int32 + Fltamcopy int32 + Fltnamap int32 + Fltnomap int32 + Fltlget int32 + Fltget int32 + Flt_anon int32 + Flt_acow int32 + Flt_obj int32 + Flt_prcopy int32 + Flt_przero int32 + Pdwoke int32 + Pdrevs int32 + Pdswout int32 + Pdfreed int32 + Pdscans int32 + Pdanscan int32 + Pdobscan int32 + Pdreact int32 + Pdbusy int32 + Pdpageouts int32 + Pdpending int32 + Pddeact int32 + Pdreanon int32 + Pdrevnode int32 + Pdrevtext int32 + Fpswtch int32 + Kmapent int32 +} +type Bcachestats struct { + Numbufs int64 + Numbufpages int64 + Numdirtypages int64 + Numcleanpages int64 + Pendingwrites int64 + Pendingreads int64 + Numwrites int64 + Numreads int64 + Cachehits int64 + Busymapped int64 + Dmapages int64 + Highpages int64 + Delwribufs int64 + Kvaslots int64 + Avail int64 +} diff --git a/vendor/github.com/shirou/gopsutil/mem/types_openbsd.go b/vendor/github.com/shirou/gopsutil/mem/types_openbsd.go new file mode 100644 index 00000000000..83cb91a1964 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/mem/types_openbsd.go @@ -0,0 +1,34 @@ +// +build ignore + +/* +Input to cgo -godefs. +*/ + +package mem + +/* +#include +#include +#include +#include + +*/ +import "C" + +// Machine characteristics; for internal use. + +const ( + CTLVm = 2 + CTLVfs = 10 + VmUvmexp = 4 // get uvmexp + VfsGeneric = 0 + VfsBcacheStat = 3 +) + +const ( + sizeOfUvmexp = C.sizeof_struct_uvmexp + sizeOfBcachestats = C.sizeof_struct_bcachestats +) + +type Uvmexp C.struct_uvmexp +type Bcachestats C.struct_bcachestats diff --git a/vendor/github.com/shirou/gopsutil/net/net.go b/vendor/github.com/shirou/gopsutil/net/net.go index 4d120dc7ed4..48660ec747e 100644 --- a/vendor/github.com/shirou/gopsutil/net/net.go +++ b/vendor/github.com/shirou/gopsutil/net/net.go @@ -39,13 +39,14 @@ type Addr struct { } type ConnectionStat struct { - Fd uint32 `json:"fd"` - Family uint32 `json:"family"` - Type uint32 `json:"type"` - Laddr Addr `json:"localaddr"` - Raddr Addr `json:"remoteaddr"` - Status string `json:"status"` - Pid int32 `json:"pid"` + Fd uint32 `json:"fd"` + Family uint32 `json:"family"` + Type uint32 `json:"type"` + Laddr Addr `json:"localaddr"` + Raddr Addr `json:"remoteaddr"` + Status string `json:"status"` + Uids []int32 `json:"uids"` + Pid int32 `json:"pid"` } // System wide stats about different network protocols diff --git a/vendor/github.com/shirou/gopsutil/net/net_darwin.go b/vendor/github.com/shirou/gopsutil/net/net_darwin.go index 78ccb665d39..f1065c6d01f 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_darwin.go +++ b/vendor/github.com/shirou/gopsutil/net/net_darwin.go @@ -4,95 +4,248 @@ package net import ( "errors" + "fmt" "os/exec" + "regexp" "strconv" "strings" +) - "github.com/shirou/gopsutil/internal/common" +var ( + errNetstatHeader = errors.New("Can't parse header of netstat output") + netstatLinkRegexp = regexp.MustCompile(`^$`) ) -// example of netstat -idbn output on yosemite +const endOfLine = "\n" + +func parseNetstatLine(line string) (stat *IOCountersStat, linkId *uint, err error) { + var ( + numericValue uint64 + columns = strings.Fields(line) + ) + + if columns[0] == "Name" { + err = errNetstatHeader + return + } + + // try to extract the numeric value from + if subMatch := netstatLinkRegexp.FindStringSubmatch(columns[2]); len(subMatch) == 2 { + numericValue, err = strconv.ParseUint(subMatch[1], 10, 64) + if err != nil { + return + } + linkIdUint := uint(numericValue) + linkId = &linkIdUint + } + + base := 1 + numberColumns := len(columns) + // sometimes Address is ommitted + if numberColumns < 12 { + base = 0 + } + if numberColumns < 11 || numberColumns > 13 { + err = fmt.Errorf("Line %q do have an invalid number of columns %d", line, numberColumns) + return + } + + parsed := make([]uint64, 0, 7) + vv := []string{ + columns[base+3], // Ipkts == PacketsRecv + columns[base+4], // Ierrs == Errin + columns[base+5], // Ibytes == BytesRecv + columns[base+6], // Opkts == PacketsSent + columns[base+7], // Oerrs == Errout + columns[base+8], // Obytes == BytesSent + } + if len(columns) == 12 { + vv = append(vv, columns[base+10]) + } + + for _, target := range vv { + if target == "-" { + parsed = append(parsed, 0) + continue + } + + if numericValue, err = strconv.ParseUint(target, 10, 64); err != nil { + return + } + parsed = append(parsed, numericValue) + } + + stat = &IOCountersStat{ + Name: strings.Trim(columns[0], "*"), // remove the * that sometimes is on right on interface + PacketsRecv: parsed[0], + Errin: parsed[1], + BytesRecv: parsed[2], + PacketsSent: parsed[3], + Errout: parsed[4], + BytesSent: parsed[5], + } + if len(parsed) == 7 { + stat.Dropout = parsed[6] + } + return +} + +type netstatInterface struct { + linkId *uint + stat *IOCountersStat +} + +func parseNetstatOutput(output string) ([]netstatInterface, error) { + var ( + err error + lines = strings.Split(strings.Trim(output, endOfLine), endOfLine) + ) + + // number of interfaces is number of lines less one for the header + numberInterfaces := len(lines) - 1 + + interfaces := make([]netstatInterface, numberInterfaces) + // no output beside header + if numberInterfaces == 0 { + return interfaces, nil + } + + for index := 0; index < numberInterfaces; index++ { + nsIface := netstatInterface{} + if nsIface.stat, nsIface.linkId, err = parseNetstatLine(lines[index+1]); err != nil { + return nil, err + } + interfaces[index] = nsIface + } + return interfaces, nil +} + +// map that hold the name of a network interface and the number of usage +type mapInterfaceNameUsage map[string]uint + +func newMapInterfaceNameUsage(ifaces []netstatInterface) mapInterfaceNameUsage { + output := make(mapInterfaceNameUsage) + for index := range ifaces { + if ifaces[index].linkId != nil { + ifaceName := ifaces[index].stat.Name + usage, ok := output[ifaceName] + if ok { + output[ifaceName] = usage + 1 + } else { + output[ifaceName] = 1 + } + } + } + return output +} + +func (min mapInterfaceNameUsage) isTruncated() bool { + for _, usage := range min { + if usage > 1 { + return true + } + } + return false +} + +func (min mapInterfaceNameUsage) notTruncated() []string { + output := make([]string, 0) + for ifaceName, usage := range min { + if usage == 1 { + output = append(output, ifaceName) + } + } + return output +} + +// example of `netstat -ibdnW` output on yosemite // Name Mtu Network Address Ipkts Ierrs Ibytes Opkts Oerrs Obytes Coll Drop // lo0 16384 869107 0 169411755 869107 0 169411755 0 0 // lo0 16384 ::1/128 ::1 869107 - 169411755 869107 - 169411755 - - // lo0 16384 127 127.0.0.1 869107 - 169411755 869107 - 169411755 - - func IOCounters(pernic bool) ([]IOCountersStat, error) { + var ( + ret []IOCountersStat + retIndex int + ) + netstat, err := exec.LookPath("/usr/sbin/netstat") if err != nil { return nil, err } + + // try to get all interface metrics, and hope there won't be any truncated out, err := invoke.Command(netstat, "-ibdnW") if err != nil { return nil, err } - lines := strings.Split(string(out), "\n") - ret := make([]IOCountersStat, 0, len(lines)-1) - exists := make([]string, 0, len(ret)) + nsInterfaces, err := parseNetstatOutput(string(out)) + if err != nil { + return nil, err + } - for _, line := range lines { - values := strings.Fields(line) - if len(values) < 1 || values[0] == "Name" { - // skip first line - continue - } - if common.StringsHas(exists, values[0]) { - // skip if already get - continue - } - exists = append(exists, values[0]) + ifaceUsage := newMapInterfaceNameUsage(nsInterfaces) + notTruncated := ifaceUsage.notTruncated() + ret = make([]IOCountersStat, len(notTruncated)) - base := 1 - // sometimes Address is ommitted - if len(values) < 11 { - base = 0 + if !ifaceUsage.isTruncated() { + // no truncated interface name, return stats of all interface with + for index := range nsInterfaces { + if nsInterfaces[index].linkId != nil { + ret[retIndex] = *nsInterfaces[index].stat + retIndex++ + } } - - parsed := make([]uint64, 0, 7) - vv := []string{ - values[base+3], // Ipkts == PacketsRecv - values[base+4], // Ierrs == Errin - values[base+5], // Ibytes == BytesRecv - values[base+6], // Opkts == PacketsSent - values[base+7], // Oerrs == Errout - values[base+8], // Obytes == BytesSent + } else { + // duplicated interface, list all interfaces + ifconfig, err := exec.LookPath("/sbin/ifconfig") + if err != nil { + return nil, err } - if len(values) == 12 { - vv = append(vv, values[base+10]) + if out, err = invoke.Command(ifconfig, "-l"); err != nil { + return nil, err } + interfaceNames := strings.Fields(strings.TrimRight(string(out), endOfLine)) - for _, target := range vv { - if target == "-" { - parsed = append(parsed, 0) - continue + // for each of the interface name, run netstat if we don't have any stats yet + for _, interfaceName := range interfaceNames { + truncated := true + for index := range nsInterfaces { + if nsInterfaces[index].linkId != nil && nsInterfaces[index].stat.Name == interfaceName { + // handle the non truncated name to avoid execute netstat for them again + ret[retIndex] = *nsInterfaces[index].stat + retIndex++ + truncated = false + break + } } - - t, err := strconv.ParseUint(target, 10, 64) - if err != nil { - return nil, err + if truncated { + // run netstat with -I$ifacename + if out, err = invoke.Command(netstat, "-ibdnWI"+interfaceName); err != nil { + return nil, err + } + parsedIfaces, err := parseNetstatOutput(string(out)) + if err != nil { + return nil, err + } + if len(parsedIfaces) == 0 { + // interface had been removed since `ifconfig -l` had been executed + continue + } + for index := range parsedIfaces { + if parsedIfaces[index].linkId != nil { + ret = append(ret, *parsedIfaces[index].stat) + break + } + } } - parsed = append(parsed, t) } - - n := IOCountersStat{ - Name: values[0], - PacketsRecv: parsed[0], - Errin: parsed[1], - BytesRecv: parsed[2], - PacketsSent: parsed[3], - Errout: parsed[4], - BytesSent: parsed[5], - } - if len(parsed) == 7 { - n.Dropout = parsed[6] - } - ret = append(ret, n) } if pernic == false { return getIOCountersAll(ret) } - return ret, nil } diff --git a/vendor/github.com/shirou/gopsutil/net/net_fallback.go b/vendor/github.com/shirou/gopsutil/net/net_fallback.go index b2c80090fc9..653bd47e5e3 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_fallback.go +++ b/vendor/github.com/shirou/gopsutil/net/net_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows package net @@ -19,3 +19,7 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) { func Connections(kind string) ([]ConnectionStat, error) { return []ConnectionStat{}, common.ErrNotImplementedError } + +func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { + return []ConnectionStat{}, common.ErrNotImplementedError +} diff --git a/vendor/github.com/shirou/gopsutil/net/net_linux.go b/vendor/github.com/shirou/gopsutil/net/net_linux.go index 0803d8e789b..8905b13a944 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_linux.go +++ b/vendor/github.com/shirou/gopsutil/net/net_linux.go @@ -79,11 +79,11 @@ func IOCountersByFile(pernic bool, filename string) ([]IOCountersStat, error) { if err != nil { return ret, err } - dropOut, err := strconv.ParseUint(fields[13], 10, 64) + dropOut, err := strconv.ParseUint(fields[11], 10, 64) if err != nil { return ret, err } - fifoOut, err := strconv.ParseUint(fields[14], 10, 64) + fifoOut, err := strconv.ParseUint(fields[12], 10, 64) if err != nil { return ret, err } @@ -185,8 +185,8 @@ func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) { // the currently in use conntrack count and the max. // If the file does not exist or is invalid it will return nil. func FilterCounters() ([]FilterStat, error) { - countfile := common.HostProc("sys/net/netfilter/nf_conntrackCount") - maxfile := common.HostProc("sys/net/netfilter/nf_conntrackMax") + countfile := common.HostProc("sys/net/netfilter/nf_conntrack_count") + maxfile := common.HostProc("sys/net/netfilter/nf_conntrack_max") count, err := common.ReadInts(countfile) @@ -291,6 +291,12 @@ func Connections(kind string) ([]ConnectionStat, error) { return ConnectionsPid(kind, 0) } +// Return a list of network connections opened returning at most `max` +// connections for each running process. +func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { + return ConnectionsPidMax(kind, 0, max) +} + // Return a list of network connections opened by a process. func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { tmap, ok := netConnectionKindMap[kind] @@ -301,9 +307,33 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { var err error var inodes map[string][]inodeMap if pid == 0 { - inodes, err = getProcInodesAll(root) + inodes, err = getProcInodesAll(root, 0) + } else { + inodes, err = getProcInodes(root, pid, 0) + if len(inodes) == 0 { + // no connection for the pid + return []ConnectionStat{}, nil + } + } + if err != nil { + return nil, fmt.Errorf("cound not get pid(s), %d", pid) + } + return statsFromInodes(root, pid, tmap, inodes) +} + +// Return up to `max` network connections opened by a process. +func ConnectionsPidMax(kind string, pid int32, max int) ([]ConnectionStat, error) { + tmap, ok := netConnectionKindMap[kind] + if !ok { + return nil, fmt.Errorf("invalid kind, %s", kind) + } + root := common.HostProc() + var err error + var inodes map[string][]inodeMap + if pid == 0 { + inodes, err = getProcInodesAll(root, max) } else { - inodes, err = getProcInodes(root, pid) + inodes, err = getProcInodes(root, pid, max) if len(inodes) == 0 { // no connection for the pid return []ConnectionStat{}, nil @@ -312,10 +342,14 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { if err != nil { return nil, fmt.Errorf("cound not get pid(s), %d", pid) } + return statsFromInodes(root, pid, tmap, inodes) +} - dupCheckMap := make(map[string]bool) +func statsFromInodes(root string, pid int32, tmap []netConnectionKindType, inodes map[string][]inodeMap) ([]ConnectionStat, error) { + dupCheckMap := make(map[connTmp]struct{}) var ret []ConnectionStat + var err error for _, t := range tmap { var path string var ls []connTmp @@ -332,6 +366,10 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { return nil, err } for _, c := range ls { + if _, ok := dupCheckMap[c]; ok { + continue + } + conn := ConnectionStat{ Fd: c.fd, Family: c.family, @@ -346,13 +384,13 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { } else { conn.Pid = c.pid } - // check duplicate using JSON format - json := conn.String() - _, exists := dupCheckMap[json] - if !exists { - ret = append(ret, conn) - dupCheckMap[json] = true - } + + // fetch process owner Real, effective, saved set, and filesystem UIDs + proc := process{Pid: conn.Pid} + conn.Uids, _ = proc.getUids() + + ret = append(ret, conn) + dupCheckMap[c] = struct{}{} } } @@ -361,11 +399,15 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { } // getProcInodes returnes fd of the pid. -func getProcInodes(root string, pid int32) (map[string][]inodeMap, error) { +func getProcInodes(root string, pid int32, max int) (map[string][]inodeMap, error) { ret := make(map[string][]inodeMap) dir := fmt.Sprintf("%s/%d/fd", root, pid) - files, err := ioutil.ReadDir(dir) + f, err := os.Open(dir) + if err != nil { + return ret, nil + } + files, err := f.Readdir(max) if err != nil { return ret, nil } @@ -429,7 +471,55 @@ func Pids() ([]int32, error) { return ret, nil } -func getProcInodesAll(root string) (map[string][]inodeMap, error) { +// Note: the following is based off process_linux structs and methods +// we need these to fetch the owner of a process ID +// FIXME: Import process occures import cycle. +// see remarks on pids() +type process struct { + Pid int32 `json:"pid"` + uids []int32 +} + +// Uids returns user ids of the process as a slice of the int +func (p *process) getUids() ([]int32, error) { + err := p.fillFromStatus() + if err != nil { + return []int32{}, err + } + return p.uids, nil +} + +// Get status from /proc/(pid)/status +func (p *process) fillFromStatus() error { + pid := p.Pid + statPath := common.HostProc(strconv.Itoa(int(pid)), "status") + contents, err := ioutil.ReadFile(statPath) + if err != nil { + return err + } + lines := strings.Split(string(contents), "\n") + for _, line := range lines { + tabParts := strings.SplitN(line, "\t", 2) + if len(tabParts) < 2 { + continue + } + value := tabParts[1] + switch strings.TrimRight(tabParts[0], ":") { + case "Uid": + p.uids = make([]int32, 0, 4) + for _, i := range strings.Split(value, "\t") { + v, err := strconv.ParseInt(i, 10, 32) + if err != nil { + return err + } + p.uids = append(p.uids, int32(v)) + } + } + } + return nil +} + +func getProcInodesAll(root string, max int) (map[string][]inodeMap, error) { pids, err := Pids() if err != nil { return nil, err @@ -437,7 +527,7 @@ func getProcInodesAll(root string) (map[string][]inodeMap, error) { ret := make(map[string][]inodeMap) for _, pid := range pids { - t, err := getProcInodes(root, pid) + t, err := getProcInodes(root, pid, max) if err != nil { return ret, err } diff --git a/vendor/github.com/shirou/gopsutil/net/net_openbsd.go b/vendor/github.com/shirou/gopsutil/net/net_openbsd.go new file mode 100644 index 00000000000..85cc70c4977 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/net/net_openbsd.go @@ -0,0 +1,153 @@ +// +build openbsd + +package net + +import ( + "errors" + "os/exec" + "strconv" + "strings" + + "github.com/shirou/gopsutil/internal/common" +) + +func ParseNetstat(output string, mode string, + iocs map[string]IOCountersStat) error { + lines := strings.Split(output, "\n") + + exists := make([]string, 0, len(lines)-1) + + columns := 6 + if mode == "ind" { + columns = 10 + } + for _, line := range lines { + values := strings.Fields(line) + if len(values) < 1 || values[0] == "Name" { + continue + } + if common.StringsHas(exists, values[0]) { + // skip if already get + continue + } + + if len(values) < columns { + continue + } + base := 1 + // sometimes Address is ommitted + if len(values) < columns { + base = 0 + } + + parsed := make([]uint64, 0, 8) + var vv []string + if mode == "inb" { + vv = []string{ + values[base+3], // BytesRecv + values[base+4], // BytesSent + } + } else { + vv = []string{ + values[base+3], // Ipkts + values[base+4], // Ierrs + values[base+5], // Opkts + values[base+6], // Oerrs + values[base+8], // Drops + } + } + for _, target := range vv { + if target == "-" { + parsed = append(parsed, 0) + continue + } + + t, err := strconv.ParseUint(target, 10, 64) + if err != nil { + return err + } + parsed = append(parsed, t) + } + exists = append(exists, values[0]) + + n, present := iocs[values[0]] + if !present { + n = IOCountersStat{Name: values[0]} + } + if mode == "inb" { + n.BytesRecv = parsed[0] + n.BytesSent = parsed[1] + } else { + n.PacketsRecv = parsed[0] + n.Errin = parsed[1] + n.PacketsSent = parsed[2] + n.Errout = parsed[3] + n.Dropin = parsed[4] + n.Dropout = parsed[4] + } + + iocs[n.Name] = n + } + return nil +} + +func IOCounters(pernic bool) ([]IOCountersStat, error) { + netstat, err := exec.LookPath("/usr/bin/netstat") + if err != nil { + return nil, err + } + out, err := invoke.Command(netstat, "-inb") + if err != nil { + return nil, err + } + out2, err := invoke.Command(netstat, "-ind") + if err != nil { + return nil, err + } + iocs := make(map[string]IOCountersStat) + + lines := strings.Split(string(out), "\n") + ret := make([]IOCountersStat, 0, len(lines)-1) + + err = ParseNetstat(string(out), "inb", iocs) + if err != nil { + return nil, err + } + err = ParseNetstat(string(out2), "ind", iocs) + if err != nil { + return nil, err + } + + for _, ioc := range iocs { + ret = append(ret, ioc) + } + + if pernic == false { + return getIOCountersAll(ret) + } + + return ret, nil +} + +// NetIOCountersByFile is an method which is added just a compatibility for linux. +func IOCountersByFile(pernic bool, filename string) ([]IOCountersStat, error) { + return IOCounters(pernic) +} + +func FilterCounters() ([]FilterStat, error) { + return nil, errors.New("NetFilterCounters not implemented for openbsd") +} + +// NetProtoCounters returns network statistics for the entire system +// If protocols is empty then all protocols are returned, otherwise +// just the protocols in the list are returned. +// Not Implemented for OpenBSD +func ProtoCounters(protocols []string) ([]ProtoCountersStat, error) { + return nil, errors.New("NetProtoCounters not implemented for openbsd") +} + +// Return a list of network connections opened. +// Not Implemented for OpenBSD +func Connections(kind string) ([]ConnectionStat, error) { + return nil, errors.New("Connections not implemented for openbsd") +} diff --git a/vendor/github.com/shirou/gopsutil/net/net_unix.go b/vendor/github.com/shirou/gopsutil/net/net_unix.go index 45de6b17deb..1224128ab66 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_unix.go +++ b/vendor/github.com/shirou/gopsutil/net/net_unix.go @@ -13,6 +13,12 @@ func Connections(kind string) ([]ConnectionStat, error) { return ConnectionsPid(kind, 0) } +// Return a list of network connections opened returning at most `max` +// connections for each running process. +func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { + return []ConnectionStat{}, common.ErrNotImplementedError +} + // Return a list of network connections opened by a process. func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { var ret []ConnectionStat @@ -66,3 +72,8 @@ func ConnectionsPid(kind string, pid int32) ([]ConnectionStat, error) { return ret, nil } + +// Return up to `max` network connections opened by a process. +func ConnectionsPidMax(kind string, pid int32, max int) ([]ConnectionStat, error) { + return []ConnectionStat{}, common.ErrNotImplementedError +} diff --git a/vendor/github.com/shirou/gopsutil/net/net_windows.go b/vendor/github.com/shirou/gopsutil/net/net_windows.go index f125260c4d5..996e83226ac 100644 --- a/vendor/github.com/shirou/gopsutil/net/net_windows.go +++ b/vendor/github.com/shirou/gopsutil/net/net_windows.go @@ -7,7 +7,6 @@ import ( "net" "os" "syscall" - "unsafe" "github.com/shirou/gopsutil/internal/common" ) @@ -35,37 +34,28 @@ func IOCounters(pernic bool) ([]IOCountersStat, error) { if err != nil { return nil, err } - - ai, err := getAdapterList() - if err != nil { - return nil, err - } var ret []IOCountersStat for _, ifi := range ifs { - name := ifi.Name - for ; ai != nil; ai = ai.Next { - name = common.BytePtrToString(&ai.Description[0]) - c := IOCountersStat{ - Name: name, - } - - row := syscall.MibIfRow{Index: ai.Index} - e := syscall.GetIfEntry(&row) - if e != nil { - return nil, os.NewSyscallError("GetIfEntry", e) - } - c.BytesSent = uint64(row.OutOctets) - c.BytesRecv = uint64(row.InOctets) - c.PacketsSent = uint64(row.OutUcastPkts) - c.PacketsRecv = uint64(row.InUcastPkts) - c.Errin = uint64(row.InErrors) - c.Errout = uint64(row.OutErrors) - c.Dropin = uint64(row.InDiscards) - c.Dropout = uint64(row.OutDiscards) - - ret = append(ret, c) + c := IOCountersStat{ + Name: ifi.Name, } + + row := syscall.MibIfRow{Index: uint32(ifi.Index)} + e := syscall.GetIfEntry(&row) + if e != nil { + return nil, os.NewSyscallError("GetIfEntry", e) + } + c.BytesSent = uint64(row.OutOctets) + c.BytesRecv = uint64(row.InOctets) + c.PacketsSent = uint64(row.OutUcastPkts) + c.PacketsRecv = uint64(row.InUcastPkts) + c.Errin = uint64(row.InErrors) + c.Errout = uint64(row.OutErrors) + c.Dropin = uint64(row.InDiscards) + c.Dropout = uint64(row.OutDiscards) + + ret = append(ret, c) } if pernic == false { @@ -86,21 +76,10 @@ func Connections(kind string) ([]ConnectionStat, error) { return ret, common.ErrNotImplementedError } -// borrowed from src/pkg/net/interface_windows.go -func getAdapterList() (*syscall.IpAdapterInfo, error) { - b := make([]byte, 1000) - l := uint32(len(b)) - a := (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0])) - err := syscall.GetAdaptersInfo(a, &l) - if err == syscall.ERROR_BUFFER_OVERFLOW { - b = make([]byte, l) - a = (*syscall.IpAdapterInfo)(unsafe.Pointer(&b[0])) - err = syscall.GetAdaptersInfo(a, &l) - } - if err != nil { - return nil, os.NewSyscallError("GetAdaptersInfo", err) - } - return a, nil +// Return a list of network connections opened returning at most `max` +// connections for each running process. +func ConnectionsMax(kind string, max int) ([]ConnectionStat, error) { + return []ConnectionStat{}, common.ErrNotImplementedError } func FilterCounters() ([]FilterStat, error) { diff --git a/vendor/github.com/shirou/gopsutil/process/process.go b/vendor/github.com/shirou/gopsutil/process/process.go index 4b69224340e..b97f777fdff 100644 --- a/vendor/github.com/shirou/gopsutil/process/process.go +++ b/vendor/github.com/shirou/gopsutil/process/process.go @@ -60,6 +60,27 @@ type NumCtxSwitchesStat struct { Involuntary int64 `json:"involuntary"` } +// Resource limit constants are from /usr/include/x86_64-linux-gnu/bits/resource.h +// from libc6-dev package in Ubuntu 16.10 +const ( + RLIMIT_CPU int32 = 0 + RLIMIT_FSIZE int32 = 1 + RLIMIT_DATA int32 = 2 + RLIMIT_STACK int32 = 3 + RLIMIT_CORE int32 = 4 + RLIMIT_RSS int32 = 5 + RLIMIT_NPROC int32 = 6 + RLIMIT_NOFILE int32 = 7 + RLIMIT_MEMLOCK int32 = 8 + RLIMIT_AS int32 = 9 + RLIMIT_LOCKS int32 = 10 + RLIMIT_SIGPENDING int32 = 11 + RLIMIT_MSGQUEUE int32 = 12 + RLIMIT_NICE int32 = 13 + RLIMIT_RTPRIO int32 = 14 + RLIMIT_RTTIME int32 = 15 +) + func (p Process) String() string { s, _ := json.Marshal(p) return string(s) diff --git a/vendor/github.com/shirou/gopsutil/process/process_darwin.go b/vendor/github.com/shirou/gopsutil/process/process_darwin.go index 8ba1619bf7c..b3a6a2e111c 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_darwin.go +++ b/vendor/github.com/shirou/gopsutil/process/process_darwin.go @@ -80,7 +80,34 @@ func (p *Process) Name() (string, error) { return common.IntToString(k.Proc.P_comm[:]), nil } func (p *Process) Exe() (string, error) { - return "", common.ErrNotImplementedError + lsof_bin, err := exec.LookPath("lsof") + if err != nil { + return "", err + } + + awk_bin, err := exec.LookPath("awk") + if err != nil { + return "", err + } + + sed_bin, err := exec.LookPath("sed") + if err != nil { + return "", err + } + + lsof := exec.Command(lsof_bin, "-p", strconv.Itoa(int(p.Pid)), "-Fn") + awk := exec.Command(awk_bin, "NR==3{print}") + sed := exec.Command(sed_bin, "s/n\\//\\//") + + output, _, err := common.Pipeline(lsof, awk, sed) + + if err != nil { + return "", err + } + + ret := strings.TrimSpace(string(output)) + + return ret, nil } // Cmdline returns the command line arguments of the process as a string with diff --git a/vendor/github.com/shirou/gopsutil/process/process_darwin_386.go b/vendor/github.com/shirou/gopsutil/process/process_darwin_386.go new file mode 100644 index 00000000000..f8e922385b9 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/process/process_darwin_386.go @@ -0,0 +1,234 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_darwin.go + +package process + +const ( + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int32 + Pad_cgo_0 [4]byte +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type UGid_t uint32 + +type KinfoProc struct { + Proc ExternProc + Eproc Eproc +} + +type Eproc struct { + Paddr *uint64 + Sess *Session + Pcred Upcred + Ucred Uucred + Pad_cgo_0 [4]byte + Vm Vmspace + Ppid int32 + Pgid int32 + Jobc int16 + Pad_cgo_1 [2]byte + Tdev int32 + Tpgid int32 + Pad_cgo_2 [4]byte + Tsess *Session + Wmesg [8]int8 + Xsize int32 + Xrssize int16 + Xccount int16 + Xswrss int16 + Pad_cgo_3 [2]byte + Flag int32 + Login [12]int8 + Spare [4]int32 + Pad_cgo_4 [4]byte +} + +type Proc struct{} + +type Session struct{} + +type ucred struct { + Link _Ctype_struct___0 + Ref uint64 + Posix Posix_cred + Label *Label + Audit Au_session +} + +type Uucred struct { + Ref int32 + UID uint32 + Ngroups int16 + Pad_cgo_0 [2]byte + Groups [16]uint32 +} + +type Upcred struct { + Pc_lock [72]int8 + Pc_ucred *ucred + P_ruid uint32 + P_svuid uint32 + P_rgid uint32 + P_svgid uint32 + P_refcnt int32 + Pad_cgo_0 [4]byte +} + +type Vmspace struct { + Dummy int32 + Pad_cgo_0 [4]byte + Dummy2 *int8 + Dummy3 [5]int32 + Pad_cgo_1 [4]byte + Dummy4 [3]*int8 +} + +type Sigacts struct{} + +type ExternProc struct { + P_un [16]byte + P_vmspace uint64 + P_sigacts uint64 + Pad_cgo_0 [3]byte + P_flag int32 + P_stat int8 + P_pid int32 + P_oppid int32 + P_dupfd int32 + Pad_cgo_1 [4]byte + User_stack uint64 + Exit_thread uint64 + P_debugger int32 + Sigwait int32 + P_estcpu uint32 + P_cpticks int32 + P_pctcpu uint32 + Pad_cgo_2 [4]byte + P_wchan uint64 + P_wmesg uint64 + P_swtime uint32 + P_slptime uint32 + P_realtimer Itimerval + P_rtime Timeval + P_uticks uint64 + P_sticks uint64 + P_iticks uint64 + P_traceflag int32 + Pad_cgo_3 [4]byte + P_tracep uint64 + P_siglist int32 + Pad_cgo_4 [4]byte + P_textvp uint64 + P_holdcnt int32 + P_sigmask uint32 + P_sigignore uint32 + P_sigcatch uint32 + P_priority uint8 + P_usrpri uint8 + P_nice int8 + P_comm [17]int8 + Pad_cgo_5 [4]byte + P_pgrp uint64 + P_addr uint64 + P_xstat uint16 + P_acflag uint16 + Pad_cgo_6 [4]byte + P_ru uint64 +} + +type Itimerval struct { + Interval Timeval + Value Timeval +} + +type Vnode struct{} + +type Pgrp struct{} + +type UserStruct struct{} + +type Au_session struct { + Aia_p *AuditinfoAddr + Mask AuMask +} + +type Posix_cred struct { + UID uint32 + Ruid uint32 + Svuid uint32 + Ngroups int16 + Pad_cgo_0 [2]byte + Groups [16]uint32 + Rgid uint32 + Svgid uint32 + Gmuid uint32 + Flags int32 +} + +type Label struct{} + +type AuditinfoAddr struct { + Auid uint32 + Mask AuMask + Termid AuTidAddr + Asid int32 + Flags uint64 +} +type AuMask struct { + Success uint32 + Failure uint32 +} +type AuTidAddr struct { + Port int32 + Type uint32 + Addr [4]uint32 +} + +type UcredQueue struct { + Next *ucred + Prev **ucred +} diff --git a/vendor/github.com/shirou/gopsutil/process/process_fallback.go b/vendor/github.com/shirou/gopsutil/process/process_fallback.go index 35ba7c19bb1..ed622a81dcf 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_fallback.go +++ b/vendor/github.com/shirou/gopsutil/process/process_fallback.go @@ -1,4 +1,4 @@ -// +build !darwin,!linux,!freebsd,!windows +// +build !darwin,!linux,!freebsd,!openbsd,!windows package process diff --git a/vendor/github.com/shirou/gopsutil/process/process_freebsd_386.go b/vendor/github.com/shirou/gopsutil/process/process_freebsd_386.go index 05e96d0f035..08ab333b435 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_freebsd_386.go +++ b/vendor/github.com/shirou/gopsutil/process/process_freebsd_386.go @@ -4,189 +4,189 @@ package process const ( - CTLKern = 1 - KernProc = 14 - KernProcPID = 1 - KernProcProc = 8 - KernProcPathname = 12 - KernProcArgs = 7 + CTLKern = 1 + KernProc = 14 + KernProcPID = 1 + KernProcProc = 8 + KernProcPathname = 12 + KernProcArgs = 7 ) const ( - sizeofPtr = 0x4 - sizeofShort = 0x2 - sizeofInt = 0x4 - sizeofLong = 0x4 - sizeofLongLong = 0x8 + sizeofPtr = 0x4 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x4 + sizeofLongLong = 0x8 ) const ( - sizeOfKinfoVmentry = 0x488 - sizeOfKinfoProc = 0x300 + sizeOfKinfoVmentry = 0x488 + sizeOfKinfoProc = 0x300 ) const ( - SIDL = 1 - SRUN = 2 - SSLEEP = 3 - SSTOP = 4 - SZOMB = 5 - SWAIT = 6 - SLOCK = 7 + SIDL = 1 + SRUN = 2 + SSLEEP = 3 + SSTOP = 4 + SZOMB = 5 + SWAIT = 6 + SLOCK = 7 ) type ( - _C_short int16 - _C_int int32 - _C_long int32 - _C_long_long int64 + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 ) type Timespec struct { - Sec int32 - Nsec int32 + Sec int32 + Nsec int32 } type Timeval struct { - Sec int32 - Usec int32 + Sec int32 + Usec int32 } type Rusage struct { - Utime Timeval - Stime Timeval - Maxrss int32 - Ixrss int32 - Idrss int32 - Isrss int32 - Minflt int32 - Majflt int32 - Nswap int32 - Inblock int32 - Oublock int32 - Msgsnd int32 - Msgrcv int32 - Nsignals int32 - Nvcsw int32 - Nivcsw int32 + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 } type Rlimit struct { - Cur int64 - Max int64 + Cur int64 + Max int64 } type KinfoProc struct { - Structsize int32 - Layout int32 - Args int32 /* pargs */ - Paddr int32 /* proc */ - Addr int32 /* user */ - Tracep int32 /* vnode */ - Textvp int32 /* vnode */ - Fd int32 /* filedesc */ - Vmspace int32 /* vmspace */ - Wchan int32 - Pid int32 - Ppid int32 - Pgid int32 - Tpgid int32 - Sid int32 - Tsid int32 - Jobc int16 - Spare_short1 int16 - Tdev uint32 - Siglist [16]byte /* sigset */ - Sigmask [16]byte /* sigset */ - Sigignore [16]byte /* sigset */ - Sigcatch [16]byte /* sigset */ - Uid uint32 - Ruid uint32 - Svuid uint32 - Rgid uint32 - Svgid uint32 - Ngroups int16 - Spare_short2 int16 - Groups [16]uint32 - Size uint32 - Rssize int32 - Swrss int32 - Tsize int32 - Dsize int32 - Ssize int32 - Xstat uint16 - Acflag uint16 - Pctcpu uint32 - Estcpu uint32 - Slptime uint32 - Swtime uint32 - Cow uint32 - Runtime uint64 - Start Timeval - Childtime Timeval - Flag int32 - Kiflag int32 - Traceflag int32 - Stat int8 - Nice int8 - Lock int8 - Rqindex int8 - Oncpu uint8 - Lastcpu uint8 - Tdname [17]int8 - Wmesg [9]int8 - Login [18]int8 - Lockname [9]int8 - Comm [20]int8 - Emul [17]int8 - Loginclass [18]int8 - Sparestrings [50]int8 - Spareints [7]int32 - Flag2 int32 - Fibnum int32 - Cr_flags uint32 - Jid int32 - Numthreads int32 - Tid int32 - Pri Priority - Rusage Rusage - Rusage_ch Rusage - Pcb int32 /* pcb */ - Kstack int32 - Udata int32 - Tdaddr int32 /* thread */ - Spareptrs [6]int32 - Sparelongs [12]int32 - Sflag int32 - Tdflags int32 + Structsize int32 + Layout int32 + Args int32 /* pargs */ + Paddr int32 /* proc */ + Addr int32 /* user */ + Tracep int32 /* vnode */ + Textvp int32 /* vnode */ + Fd int32 /* filedesc */ + Vmspace int32 /* vmspace */ + Wchan int32 + Pid int32 + Ppid int32 + Pgid int32 + Tpgid int32 + Sid int32 + Tsid int32 + Jobc int16 + Spare_short1 int16 + Tdev uint32 + Siglist [16]byte /* sigset */ + Sigmask [16]byte /* sigset */ + Sigignore [16]byte /* sigset */ + Sigcatch [16]byte /* sigset */ + Uid uint32 + Ruid uint32 + Svuid uint32 + Rgid uint32 + Svgid uint32 + Ngroups int16 + Spare_short2 int16 + Groups [16]uint32 + Size uint32 + Rssize int32 + Swrss int32 + Tsize int32 + Dsize int32 + Ssize int32 + Xstat uint16 + Acflag uint16 + Pctcpu uint32 + Estcpu uint32 + Slptime uint32 + Swtime uint32 + Cow uint32 + Runtime uint64 + Start Timeval + Childtime Timeval + Flag int32 + Kiflag int32 + Traceflag int32 + Stat int8 + Nice int8 + Lock int8 + Rqindex int8 + Oncpu uint8 + Lastcpu uint8 + Tdname [17]int8 + Wmesg [9]int8 + Login [18]int8 + Lockname [9]int8 + Comm [20]int8 + Emul [17]int8 + Loginclass [18]int8 + Sparestrings [50]int8 + Spareints [7]int32 + Flag2 int32 + Fibnum int32 + Cr_flags uint32 + Jid int32 + Numthreads int32 + Tid int32 + Pri Priority + Rusage Rusage + Rusage_ch Rusage + Pcb int32 /* pcb */ + Kstack int32 + Udata int32 + Tdaddr int32 /* thread */ + Spareptrs [6]int32 + Sparelongs [12]int32 + Sflag int32 + Tdflags int32 } type Priority struct { - Class uint8 - Level uint8 - Native uint8 - User uint8 + Class uint8 + Level uint8 + Native uint8 + User uint8 } type KinfoVmentry struct { - Structsize int32 - Type int32 - Start uint64 - End uint64 - Offset uint64 - Vn_fileid uint64 - Vn_fsid uint32 - Flags int32 - Resident int32 - Private_resident int32 - Protection int32 - Ref_count int32 - Shadow_count int32 - Vn_type int32 - Vn_size uint64 - Vn_rdev uint32 - Vn_mode uint16 - Status uint16 - X_kve_ispare [12]int32 - Path [1024]int8 + Structsize int32 + Type int32 + Start uint64 + End uint64 + Offset uint64 + Vn_fileid uint64 + Vn_fsid uint32 + Flags int32 + Resident int32 + Private_resident int32 + Protection int32 + Ref_count int32 + Shadow_count int32 + Vn_type int32 + Vn_size uint64 + Vn_rdev uint32 + Vn_mode uint16 + Status uint16 + X_kve_ispare [12]int32 + Path [1024]int8 } diff --git a/vendor/github.com/shirou/gopsutil/process/process_freebsd_amd64.go b/vendor/github.com/shirou/gopsutil/process/process_freebsd_amd64.go index 79e2ba8816e..560e627d249 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_freebsd_amd64.go +++ b/vendor/github.com/shirou/gopsutil/process/process_freebsd_amd64.go @@ -4,189 +4,189 @@ package process const ( - CTLKern = 1 - KernProc = 14 - KernProcPID = 1 - KernProcProc = 8 - KernProcPathname = 12 - KernProcArgs = 7 + CTLKern = 1 + KernProc = 14 + KernProcPID = 1 + KernProcProc = 8 + KernProcPathname = 12 + KernProcArgs = 7 ) const ( - sizeofPtr = 0x8 - sizeofShort = 0x2 - sizeofInt = 0x4 - sizeofLong = 0x8 - sizeofLongLong = 0x8 + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 ) const ( - sizeOfKinfoVmentry = 0x488 - sizeOfKinfoProc = 0x440 + sizeOfKinfoVmentry = 0x488 + sizeOfKinfoProc = 0x440 ) const ( - SIDL = 1 - SRUN = 2 - SSLEEP = 3 - SSTOP = 4 - SZOMB = 5 - SWAIT = 6 - SLOCK = 7 + SIDL = 1 + SRUN = 2 + SSLEEP = 3 + SSTOP = 4 + SZOMB = 5 + SWAIT = 6 + SLOCK = 7 ) type ( - _C_short int16 - _C_int int32 - _C_long int64 - _C_long_long int64 + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 ) type Timespec struct { - Sec int64 - Nsec int64 + Sec int64 + Nsec int64 } type Timeval struct { - Sec int64 - Usec int64 + Sec int64 + Usec int64 } type Rusage struct { - Utime Timeval - Stime Timeval - Maxrss int64 - Ixrss int64 - Idrss int64 - Isrss int64 - Minflt int64 - Majflt int64 - Nswap int64 - Inblock int64 - Oublock int64 - Msgsnd int64 - Msgrcv int64 - Nsignals int64 - Nvcsw int64 - Nivcsw int64 + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 } type Rlimit struct { - Cur int64 - Max int64 + Cur int64 + Max int64 } type KinfoProc struct { - Structsize int32 - Layout int32 - Args int64 /* pargs */ - Paddr int64 /* proc */ - Addr int64 /* user */ - Tracep int64 /* vnode */ - Textvp int64 /* vnode */ - Fd int64 /* filedesc */ - Vmspace int64 /* vmspace */ - Wchan int64 - Pid int32 - Ppid int32 - Pgid int32 - Tpgid int32 - Sid int32 - Tsid int32 - Jobc int16 - Spare_short1 int16 - Tdev uint32 - Siglist [16]byte /* sigset */ - Sigmask [16]byte /* sigset */ - Sigignore [16]byte /* sigset */ - Sigcatch [16]byte /* sigset */ - Uid uint32 - Ruid uint32 - Svuid uint32 - Rgid uint32 - Svgid uint32 - Ngroups int16 - Spare_short2 int16 - Groups [16]uint32 - Size uint64 - Rssize int64 - Swrss int64 - Tsize int64 - Dsize int64 - Ssize int64 - Xstat uint16 - Acflag uint16 - Pctcpu uint32 - Estcpu uint32 - Slptime uint32 - Swtime uint32 - Cow uint32 - Runtime uint64 - Start Timeval - Childtime Timeval - Flag int64 - Kiflag int64 - Traceflag int32 - Stat int8 - Nice int8 - Lock int8 - Rqindex int8 - Oncpu uint8 - Lastcpu uint8 - Tdname [17]int8 - Wmesg [9]int8 - Login [18]int8 - Lockname [9]int8 - Comm [20]int8 - Emul [17]int8 - Loginclass [18]int8 - Sparestrings [50]int8 - Spareints [7]int32 - Flag2 int32 - Fibnum int32 - Cr_flags uint32 - Jid int32 - Numthreads int32 - Tid int32 - Pri Priority - Rusage Rusage - Rusage_ch Rusage - Pcb int64 /* pcb */ - Kstack int64 - Udata int64 - Tdaddr int64 /* thread */ - Spareptrs [6]int64 - Sparelongs [12]int64 - Sflag int64 - Tdflags int64 + Structsize int32 + Layout int32 + Args int64 /* pargs */ + Paddr int64 /* proc */ + Addr int64 /* user */ + Tracep int64 /* vnode */ + Textvp int64 /* vnode */ + Fd int64 /* filedesc */ + Vmspace int64 /* vmspace */ + Wchan int64 + Pid int32 + Ppid int32 + Pgid int32 + Tpgid int32 + Sid int32 + Tsid int32 + Jobc int16 + Spare_short1 int16 + Tdev uint32 + Siglist [16]byte /* sigset */ + Sigmask [16]byte /* sigset */ + Sigignore [16]byte /* sigset */ + Sigcatch [16]byte /* sigset */ + Uid uint32 + Ruid uint32 + Svuid uint32 + Rgid uint32 + Svgid uint32 + Ngroups int16 + Spare_short2 int16 + Groups [16]uint32 + Size uint64 + Rssize int64 + Swrss int64 + Tsize int64 + Dsize int64 + Ssize int64 + Xstat uint16 + Acflag uint16 + Pctcpu uint32 + Estcpu uint32 + Slptime uint32 + Swtime uint32 + Cow uint32 + Runtime uint64 + Start Timeval + Childtime Timeval + Flag int64 + Kiflag int64 + Traceflag int32 + Stat int8 + Nice int8 + Lock int8 + Rqindex int8 + Oncpu uint8 + Lastcpu uint8 + Tdname [17]int8 + Wmesg [9]int8 + Login [18]int8 + Lockname [9]int8 + Comm [20]int8 + Emul [17]int8 + Loginclass [18]int8 + Sparestrings [50]int8 + Spareints [7]int32 + Flag2 int32 + Fibnum int32 + Cr_flags uint32 + Jid int32 + Numthreads int32 + Tid int32 + Pri Priority + Rusage Rusage + Rusage_ch Rusage + Pcb int64 /* pcb */ + Kstack int64 + Udata int64 + Tdaddr int64 /* thread */ + Spareptrs [6]int64 + Sparelongs [12]int64 + Sflag int64 + Tdflags int64 } type Priority struct { - Class uint8 - Level uint8 - Native uint8 - User uint8 + Class uint8 + Level uint8 + Native uint8 + User uint8 } type KinfoVmentry struct { - Structsize int32 - Type int32 - Start uint64 - End uint64 - Offset uint64 - Vn_fileid uint64 - Vn_fsid uint32 - Flags int32 - Resident int32 - Private_resident int32 - Protection int32 - Ref_count int32 - Shadow_count int32 - Vn_type int32 - Vn_size uint64 - Vn_rdev uint32 - Vn_mode uint16 - Status uint16 - X_kve_ispare [12]int32 - Path [1024]int8 + Structsize int32 + Type int32 + Start uint64 + End uint64 + Offset uint64 + Vn_fileid uint64 + Vn_fsid uint32 + Flags int32 + Resident int32 + Private_resident int32 + Protection int32 + Ref_count int32 + Shadow_count int32 + Vn_type int32 + Vn_size uint64 + Vn_rdev uint32 + Vn_mode uint16 + Status uint16 + X_kve_ispare [12]int32 + Path [1024]int8 } diff --git a/vendor/github.com/shirou/gopsutil/process/process_freebsd_arm.go b/vendor/github.com/shirou/gopsutil/process/process_freebsd_arm.go new file mode 100644 index 00000000000..81ae0b9a8d4 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/process/process_freebsd_arm.go @@ -0,0 +1,192 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_freebsd.go + +package process + +const ( + CTLKern = 1 + KernProc = 14 + KernProcPID = 1 + KernProcProc = 8 + KernProcPathname = 12 + KernProcArgs = 7 +) + +const ( + sizeofPtr = 0x4 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x4 + sizeofLongLong = 0x8 +) + +const ( + sizeOfKinfoVmentry = 0x488 + sizeOfKinfoProc = 0x440 +) + +const ( + SIDL = 1 + SRUN = 2 + SSLEEP = 3 + SSTOP = 4 + SZOMB = 5 + SWAIT = 6 + SLOCK = 7 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int32 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int64 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int32 + Ixrss int32 + Idrss int32 + Isrss int32 + Minflt int32 + Majflt int32 + Nswap int32 + Inblock int32 + Oublock int32 + Msgsnd int32 + Msgrcv int32 + Nsignals int32 + Nvcsw int32 + Nivcsw int32 +} + +type Rlimit struct { + Cur int32 + Max int32 +} + +type KinfoProc struct { + Structsize int32 + Layout int32 + Args int32 /* pargs */ + Paddr int32 /* proc */ + Addr int32 /* user */ + Tracep int32 /* vnode */ + Textvp int32 /* vnode */ + Fd int32 /* filedesc */ + Vmspace int32 /* vmspace */ + Wchan int32 + Pid int32 + Ppid int32 + Pgid int32 + Tpgid int32 + Sid int32 + Tsid int32 + Jobc int16 + Spare_short1 int16 + Tdev uint32 + Siglist [16]byte /* sigset */ + Sigmask [16]byte /* sigset */ + Sigignore [16]byte /* sigset */ + Sigcatch [16]byte /* sigset */ + Uid uint32 + Ruid uint32 + Svuid uint32 + Rgid uint32 + Svgid uint32 + Ngroups int16 + Spare_short2 int16 + Groups [16]uint32 + Size uint32 + Rssize int32 + Swrss int32 + Tsize int32 + Dsize int32 + Ssize int32 + Xstat uint16 + Acflag uint16 + Pctcpu uint32 + Estcpu uint32 + Slptime uint32 + Swtime uint32 + Cow uint32 + Runtime uint64 + Start Timeval + Childtime Timeval + Flag int32 + Kiflag int32 + Traceflag int32 + Stat int8 + Nice int8 + Lock int8 + Rqindex int8 + Oncpu uint8 + Lastcpu uint8 + Tdname [17]int8 + Wmesg [9]int8 + Login [18]int8 + Lockname [9]int8 + Comm [20]int8 + Emul [17]int8 + Loginclass [18]int8 + Sparestrings [50]int8 + Spareints [4]int32 + Flag2 int32 + Fibnum int32 + Cr_flags uint32 + Jid int32 + Numthreads int32 + Tid int32 + Pri Priority + Rusage Rusage + Rusage_ch Rusage + Pcb int32 /* pcb */ + Kstack int32 + Udata int32 + Tdaddr int32 /* thread */ + Spareptrs [6]int64 + Sparelongs [12]int64 + Sflag int64 + Tdflags int64 +} + +type Priority struct { + Class uint8 + Level uint8 + Native uint8 + User uint8 +} + +type KinfoVmentry struct { + Structsize int32 + Type int32 + Start uint64 + End uint64 + Offset uint64 + Vn_fileid uint64 + Vn_fsid uint32 + Flags int32 + Resident int32 + Private_resident int32 + Protection int32 + Ref_count int32 + Shadow_count int32 + Vn_type int32 + Vn_size uint64 + Vn_rdev uint32 + Vn_mode uint16 + Status uint16 + X_kve_ispare [12]int32 + Path [1024]int8 +} diff --git a/vendor/github.com/shirou/gopsutil/process/process_linux.go b/vendor/github.com/shirou/gopsutil/process/process_linux.go index 158cb047783..5b5c6bcc1e0 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_linux.go +++ b/vendor/github.com/shirou/gopsutil/process/process_linux.go @@ -3,11 +3,13 @@ package process import ( + "bufio" "bytes" "encoding/json" "errors" "fmt" "io/ioutil" + "math" "os" "path/filepath" "strconv" @@ -20,10 +22,14 @@ import ( "github.com/shirou/gopsutil/net" ) -var ErrorNoChildren = errors.New("process does not have children") +var ( + ErrorNoChildren = errors.New("process does not have children") + PageSize = uint64(os.Getpagesize()) +) const ( - PrioProcess = 0 // linux/resource.h + PrioProcess = 0 // linux/resource.h + ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK) ) // MemoryInfoExStat is different between OSes @@ -194,7 +200,7 @@ func (p *Process) IOnice() (int32, error) { // Rlimit returns Resource Limits. func (p *Process) Rlimit() ([]RlimitStat, error) { - return nil, common.ErrNotImplementedError + return p.fillFromLimits() } // IOCounters returns IO Counters. @@ -403,6 +409,111 @@ func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) { ** Internal functions **/ +func limitToInt(val string) (int32, error) { + if val == "unlimited" { + return math.MaxInt32, nil + } else { + res, err := strconv.ParseInt(val, 10, 32) + if err != nil { + return 0, err + } + return int32(res), nil + } +} + +// Get num_fds from /proc/(pid)/limits +func (p *Process) fillFromLimits() ([]RlimitStat, error) { + pid := p.Pid + limitsFile := common.HostProc(strconv.Itoa(int(pid)), "limits") + d, err := os.Open(limitsFile) + if err != nil { + return nil, err + } + defer d.Close() + + var limitStats []RlimitStat + + limitsScanner := bufio.NewScanner(d) + for limitsScanner.Scan() { + var statItem RlimitStat + + str := strings.Fields(limitsScanner.Text()) + + // Remove the header line + if strings.Contains(str[len(str)-1], "Units") { + continue + } + + // Assert that last item is a Hard limit + statItem.Hard, err = limitToInt(str[len(str)-1]) + if err != nil { + // On error remove last item an try once again since it can be unit or header line + str = str[:len(str)-1] + statItem.Hard, err = limitToInt(str[len(str)-1]) + if err != nil { + return nil, err + } + } + // Remove last item from string + str = str[:len(str)-1] + + //Now last item is a Soft limit + statItem.Soft, err = limitToInt(str[len(str)-1]) + if err != nil { + return nil, err + } + // Remove last item from string + str = str[:len(str)-1] + + //The rest is a stats name + resourceName := strings.Join(str, " ") + switch resourceName { + case "Max cpu time": + statItem.Resource = RLIMIT_CPU + case "Max file size": + statItem.Resource = RLIMIT_FSIZE + case "Max data size": + statItem.Resource = RLIMIT_DATA + case "Max stack size": + statItem.Resource = RLIMIT_STACK + case "Max core file size": + statItem.Resource = RLIMIT_CORE + case "Max resident set": + statItem.Resource = RLIMIT_RSS + case "Max processes": + statItem.Resource = RLIMIT_NPROC + case "Max open files": + statItem.Resource = RLIMIT_NOFILE + case "Max locked memory": + statItem.Resource = RLIMIT_MEMLOCK + case "Max address space": + statItem.Resource = RLIMIT_AS + case "Max file locks": + statItem.Resource = RLIMIT_LOCKS + case "Max pending signals": + statItem.Resource = RLIMIT_SIGPENDING + case "Max msgqueue size": + statItem.Resource = RLIMIT_MSGQUEUE + case "Max nice priority": + statItem.Resource = RLIMIT_NICE + case "Max realtime priority": + statItem.Resource = RLIMIT_RTPRIO + case "Max realtime timeout": + statItem.Resource = RLIMIT_RTTIME + default: + continue + } + + limitStats = append(limitStats, statItem) + } + + if err := limitsScanner.Err(); err != nil { + return nil, err + } + + return limitStats, nil +} + // Get num_fds from /proc/(pid)/fd func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) { pid := p.Pid @@ -609,6 +720,18 @@ func (p *Process) fillFromStatus() error { switch strings.TrimRight(tabParts[0], ":") { case "Name": p.name = strings.Trim(value, " \t") + if len(p.name) >= 15 { + cmdlineSlice, err := p.CmdlineSlice() + if err != nil { + return err + } + if len(cmdlineSlice) > 0 { + extendedName := filepath.Base(cmdlineSlice[0]) + if strings.HasPrefix(extendedName, p.name) { + p.name = extendedName + } + } + } case "State": p.status = value[0:1] case "PPid", "Ppid": diff --git a/vendor/github.com/shirou/gopsutil/process/process_linux_386.go b/vendor/github.com/shirou/gopsutil/process/process_linux_386.go deleted file mode 100644 index 541b854c753..00000000000 --- a/vendor/github.com/shirou/gopsutil/process/process_linux_386.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build linux -// +build 386 - -package process - -const ( - ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK) - PageSize = 4096 // C.sysconf(C._SC_PAGE_SIZE) -) diff --git a/vendor/github.com/shirou/gopsutil/process/process_linux_amd64.go b/vendor/github.com/shirou/gopsutil/process/process_linux_amd64.go deleted file mode 100644 index b4a4ce8b7c5..00000000000 --- a/vendor/github.com/shirou/gopsutil/process/process_linux_amd64.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build linux -// +build amd64 - -package process - -const ( - ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK) - PageSize = 4096 // C.sysconf(C._SC_PAGE_SIZE) -) diff --git a/vendor/github.com/shirou/gopsutil/process/process_linux_arm.go b/vendor/github.com/shirou/gopsutil/process/process_linux_arm.go deleted file mode 100644 index c6123a4891c..00000000000 --- a/vendor/github.com/shirou/gopsutil/process/process_linux_arm.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build linux -// +build arm - -package process - -const ( - ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK) - PageSize = 4096 // C.sysconf(C._SC_PAGE_SIZE) -) diff --git a/vendor/github.com/shirou/gopsutil/process/process_linux_arm64.go b/vendor/github.com/shirou/gopsutil/process/process_linux_arm64.go deleted file mode 100644 index 529aeaa9ada..00000000000 --- a/vendor/github.com/shirou/gopsutil/process/process_linux_arm64.go +++ /dev/null @@ -1,9 +0,0 @@ -// +build linux -// +build arm64 - -package process - -const ( - ClockTicks = 100 // C.sysconf(C._SC_CLK_TCK) - PageSize = 4096 // C.sysconf(C._SC_PAGE_SIZE) -) diff --git a/vendor/github.com/shirou/gopsutil/process/process_openbsd.go b/vendor/github.com/shirou/gopsutil/process/process_openbsd.go new file mode 100644 index 00000000000..b51826ce1a9 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/process/process_openbsd.go @@ -0,0 +1,362 @@ +// +build openbsd + +package process + +import ( + "C" + "bytes" + "encoding/binary" + "strings" + "syscall" + "unsafe" + + cpu "github.com/shirou/gopsutil/cpu" + "github.com/shirou/gopsutil/internal/common" + mem "github.com/shirou/gopsutil/mem" + net "github.com/shirou/gopsutil/net" +) + +// MemoryInfoExStat is different between OSes +type MemoryInfoExStat struct { +} + +type MemoryMapsStat struct { +} + +func Pids() ([]int32, error) { + var ret []int32 + procs, err := processes() + if err != nil { + return ret, nil + } + + for _, p := range procs { + ret = append(ret, p.Pid) + } + + return ret, nil +} + +func (p *Process) Ppid() (int32, error) { + k, err := p.getKProc() + if err != nil { + return 0, err + } + + return k.Ppid, nil +} +func (p *Process) Name() (string, error) { + k, err := p.getKProc() + if err != nil { + return "", err + } + + return common.IntToString(k.Comm[:]), nil +} +func (p *Process) Exe() (string, error) { + return "", common.ErrNotImplementedError +} + +func (p *Process) CmdlineSlice() ([]string, error) { + mib := []int32{CTLKern, KernProcArgs, p.Pid, KernProcArgv} + buf, _, err := common.CallSyscall(mib) + + if err != nil { + return nil, err + } + + argc := 0 + argvp := unsafe.Pointer(&buf[0]) + argv := *(**C.char)(unsafe.Pointer(argvp)) + size := unsafe.Sizeof(argv) + var strParts []string + + for argv != nil { + strParts = append(strParts, C.GoString(argv)) + + argc++ + argv = *(**C.char)(unsafe.Pointer(uintptr(argvp) + uintptr(argc)*size)) + } + return strParts, nil +} + +func (p *Process) Cmdline() (string, error) { + argv, err := p.CmdlineSlice() + if err != nil { + return "", err + } + return strings.Join(argv, " "), nil +} + +func (p *Process) CreateTime() (int64, error) { + return 0, common.ErrNotImplementedError +} +func (p *Process) Cwd() (string, error) { + return "", common.ErrNotImplementedError +} +func (p *Process) Parent() (*Process, error) { + return p, common.ErrNotImplementedError +} +func (p *Process) Status() (string, error) { + k, err := p.getKProc() + if err != nil { + return "", err + } + var s string + switch k.Stat { + case SIDL: + case SRUN: + case SONPROC: + s = "R" + case SSLEEP: + s = "S" + case SSTOP: + s = "T" + case SDEAD: + s = "Z" + } + + return s, nil +} +func (p *Process) Uids() ([]int32, error) { + k, err := p.getKProc() + if err != nil { + return nil, err + } + + uids := make([]int32, 0, 3) + + uids = append(uids, int32(k.Ruid), int32(k.Uid), int32(k.Svuid)) + + return uids, nil +} +func (p *Process) Gids() ([]int32, error) { + k, err := p.getKProc() + if err != nil { + return nil, err + } + + gids := make([]int32, 0, 3) + gids = append(gids, int32(k.Rgid), int32(k.Ngroups), int32(k.Svgid)) + + return gids, nil +} +func (p *Process) Terminal() (string, error) { + k, err := p.getKProc() + if err != nil { + return "", err + } + + ttyNr := uint64(k.Tdev) + + termmap, err := getTerminalMap() + if err != nil { + return "", err + } + + return termmap[ttyNr], nil +} +func (p *Process) Nice() (int32, error) { + k, err := p.getKProc() + if err != nil { + return 0, err + } + return int32(k.Nice), nil +} +func (p *Process) IOnice() (int32, error) { + return 0, common.ErrNotImplementedError +} +func (p *Process) Rlimit() ([]RlimitStat, error) { + var rlimit []RlimitStat + return rlimit, common.ErrNotImplementedError +} +func (p *Process) IOCounters() (*IOCountersStat, error) { + k, err := p.getKProc() + if err != nil { + return nil, err + } + return &IOCountersStat{ + ReadCount: uint64(k.Uru_inblock), + WriteCount: uint64(k.Uru_oublock), + }, nil +} +func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) { + return nil, common.ErrNotImplementedError +} +func (p *Process) NumFDs() (int32, error) { + return 0, common.ErrNotImplementedError +} +func (p *Process) NumThreads() (int32, error) { + /* not supported, just return 1 */ + return 1, nil +} +func (p *Process) Threads() (map[string]string, error) { + ret := make(map[string]string, 0) + return ret, common.ErrNotImplementedError +} +func (p *Process) Times() (*cpu.TimesStat, error) { + k, err := p.getKProc() + if err != nil { + return nil, err + } + return &cpu.TimesStat{ + CPU: "cpu", + User: float64(k.Uutime_sec) + float64(k.Uutime_usec)/1000000, + System: float64(k.Ustime_sec) + float64(k.Ustime_usec)/1000000, + }, nil +} +func (p *Process) CPUAffinity() ([]int32, error) { + return nil, common.ErrNotImplementedError +} +func (p *Process) MemoryInfo() (*MemoryInfoStat, error) { + k, err := p.getKProc() + if err != nil { + return nil, err + } + pageSize, err := mem.GetPageSize() + if err != nil { + return nil, err + } + + return &MemoryInfoStat{ + RSS: uint64(k.Vm_rssize) * pageSize, + VMS: uint64(k.Vm_tsize) + uint64(k.Vm_dsize) + + uint64(k.Vm_ssize), + }, nil +} +func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) { + return nil, common.ErrNotImplementedError +} + +func (p *Process) Children() ([]*Process, error) { + pids, err := common.CallPgrep(invoke, p.Pid) + if err != nil { + return nil, err + } + ret := make([]*Process, 0, len(pids)) + for _, pid := range pids { + np, err := NewProcess(pid) + if err != nil { + return nil, err + } + ret = append(ret, np) + } + return ret, nil +} + +func (p *Process) OpenFiles() ([]OpenFilesStat, error) { + return nil, common.ErrNotImplementedError +} + +func (p *Process) Connections() ([]net.ConnectionStat, error) { + return nil, common.ErrNotImplementedError +} + +func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) { + return nil, common.ErrNotImplementedError +} + +func (p *Process) IsRunning() (bool, error) { + return true, common.ErrNotImplementedError +} +func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) { + var ret []MemoryMapsStat + return &ret, common.ErrNotImplementedError +} + +func processes() ([]Process, error) { + results := make([]Process, 0, 50) + + buf, length, err := CallKernProcSyscall(KernProcAll, 0) + + if err != nil { + return results, err + } + + // get kinfo_proc size + count := int(length / uint64(sizeOfKinfoProc)) + + // parse buf to procs + for i := 0; i < count; i++ { + b := buf[i*sizeOfKinfoProc : (i+1)*sizeOfKinfoProc] + k, err := parseKinfoProc(b) + if err != nil { + continue + } + p, err := NewProcess(int32(k.Pid)) + if err != nil { + continue + } + + results = append(results, *p) + } + + return results, nil +} + +func parseKinfoProc(buf []byte) (KinfoProc, error) { + var k KinfoProc + br := bytes.NewReader(buf) + err := common.Read(br, binary.LittleEndian, &k) + return k, err +} + +func (p *Process) getKProc() (*KinfoProc, error) { + buf, length, err := CallKernProcSyscall(KernProcPID, p.Pid) + if err != nil { + return nil, err + } + if length != sizeOfKinfoProc { + return nil, err + } + + k, err := parseKinfoProc(buf) + if err != nil { + return nil, err + } + return &k, nil +} + +func NewProcess(pid int32) (*Process, error) { + p := &Process{Pid: pid} + + return p, nil +} + +func CallKernProcSyscall(op int32, arg int32) ([]byte, uint64, error) { + mib := []int32{CTLKern, KernProc, op, arg, sizeOfKinfoProc, 0} + mibptr := unsafe.Pointer(&mib[0]) + miblen := uint64(len(mib)) + length := uint64(0) + _, _, err := syscall.Syscall6( + syscall.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + 0, + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + return nil, length, err + } + + count := int32(length / uint64(sizeOfKinfoProc)) + mib = []int32{CTLKern, KernProc, op, arg, sizeOfKinfoProc, count} + mibptr = unsafe.Pointer(&mib[0]) + miblen = uint64(len(mib)) + // get proc info itself + buf := make([]byte, length) + _, _, err = syscall.Syscall6( + syscall.SYS___SYSCTL, + uintptr(mibptr), + uintptr(miblen), + uintptr(unsafe.Pointer(&buf[0])), + uintptr(unsafe.Pointer(&length)), + 0, + 0) + if err != 0 { + return buf, length, err + } + + return buf, length, nil +} diff --git a/vendor/github.com/shirou/gopsutil/process/process_openbsd_amd64.go b/vendor/github.com/shirou/gopsutil/process/process_openbsd_amd64.go new file mode 100644 index 00000000000..8607422b5f5 --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/process/process_openbsd_amd64.go @@ -0,0 +1,200 @@ +// Created by cgo -godefs - DO NOT EDIT +// cgo -godefs types_openbsd.go + +package process + +const ( + CTLKern = 1 + KernProc = 66 + KernProcAll = 0 + KernProcPID = 1 + KernProcProc = 8 + KernProcPathname = 12 + KernProcArgs = 55 + KernProcArgv = 1 + KernProcEnv = 3 +) + +const ( + ArgMax = 256 * 1024 +) + +const ( + sizeofPtr = 0x8 + sizeofShort = 0x2 + sizeofInt = 0x4 + sizeofLong = 0x8 + sizeofLongLong = 0x8 +) + +const ( + sizeOfKinfoVmentry = 0x50 + sizeOfKinfoProc = 0x268 +) + +const ( + SIDL = 1 + SRUN = 2 + SSLEEP = 3 + SSTOP = 4 + SZOMB = 5 + SDEAD = 6 + SONPROC = 7 +) + +type ( + _C_short int16 + _C_int int32 + _C_long int64 + _C_long_long int64 +) + +type Timespec struct { + Sec int64 + Nsec int64 +} + +type Timeval struct { + Sec int64 + Usec int64 +} + +type Rusage struct { + Utime Timeval + Stime Timeval + Maxrss int64 + Ixrss int64 + Idrss int64 + Isrss int64 + Minflt int64 + Majflt int64 + Nswap int64 + Inblock int64 + Oublock int64 + Msgsnd int64 + Msgrcv int64 + Nsignals int64 + Nvcsw int64 + Nivcsw int64 +} + +type Rlimit struct { + Cur uint64 + Max uint64 +} + +type KinfoProc struct { + Forw uint64 + Back uint64 + Paddr uint64 + Addr uint64 + Fd uint64 + Stats uint64 + Limit uint64 + Vmspace uint64 + Sigacts uint64 + Sess uint64 + Tsess uint64 + Ru uint64 + Eflag int32 + Exitsig int32 + Flag int32 + Pid int32 + Ppid int32 + Sid int32 + X_pgid int32 + Tpgid int32 + Uid uint32 + Ruid uint32 + Gid uint32 + Rgid uint32 + Groups [16]uint32 + Ngroups int16 + Jobc int16 + Tdev uint32 + Estcpu uint32 + Rtime_sec uint32 + Rtime_usec uint32 + Cpticks int32 + Pctcpu uint32 + Swtime uint32 + Slptime uint32 + Schedflags int32 + Uticks uint64 + Sticks uint64 + Iticks uint64 + Tracep uint64 + Traceflag int32 + Holdcnt int32 + Siglist int32 + Sigmask uint32 + Sigignore uint32 + Sigcatch uint32 + Stat int8 + Priority uint8 + Usrpri uint8 + Nice uint8 + Xstat uint16 + Acflag uint16 + Comm [24]int8 + Wmesg [8]int8 + Wchan uint64 + Login [32]int8 + Vm_rssize int32 + Vm_tsize int32 + Vm_dsize int32 + Vm_ssize int32 + Uvalid int64 + Ustart_sec uint64 + Ustart_usec uint32 + Uutime_sec uint32 + Uutime_usec uint32 + Ustime_sec uint32 + Ustime_usec uint32 + Pad_cgo_0 [4]byte + Uru_maxrss uint64 + Uru_ixrss uint64 + Uru_idrss uint64 + Uru_isrss uint64 + Uru_minflt uint64 + Uru_majflt uint64 + Uru_nswap uint64 + Uru_inblock uint64 + Uru_oublock uint64 + Uru_msgsnd uint64 + Uru_msgrcv uint64 + Uru_nsignals uint64 + Uru_nvcsw uint64 + Uru_nivcsw uint64 + Uctime_sec uint32 + Uctime_usec uint32 + Psflags int32 + Spare int32 + Svuid uint32 + Svgid uint32 + Emul [8]int8 + Rlim_rss_cur uint64 + Cpuid uint64 + Vm_map_size uint64 + Tid int32 + Rtableid uint32 +} + +type Priority struct{} + +type KinfoVmentry struct { + Start uint64 + End uint64 + Guard uint64 + Fspace uint64 + Fspace_augment uint64 + Offset uint64 + Wired_count int32 + Etype int32 + Protection int32 + Max_protection int32 + Advice int32 + Inheritance int32 + Flags uint8 + Pad_cgo_0 [7]byte +} diff --git a/vendor/github.com/shirou/gopsutil/process/process_posix.go b/vendor/github.com/shirou/gopsutil/process/process_posix.go index 0751f68606d..ef4b676dd8a 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_posix.go +++ b/vendor/github.com/shirou/gopsutil/process/process_posix.go @@ -1,4 +1,4 @@ -// +build linux freebsd darwin +// +build linux freebsd openbsd darwin package process @@ -6,6 +6,7 @@ import ( "os" "os/exec" "os/user" + "path/filepath" "strconv" "strings" "syscall" @@ -31,15 +32,22 @@ func getTerminalMap() (map[uint64]string, error) { } } + var ptsnames []string ptsd, err := os.Open("/dev/pts") if err != nil { - return nil, err + ptsnames, _ = filepath.Glob("/dev/ttyp*") + if ptsnames == nil { + return nil, err + } } - defer ptsd.Close() - - ptsnames, err := ptsd.Readdirnames(-1) - for _, ptsname := range ptsnames { - termfiles = append(termfiles, "/dev/pts/"+ptsname) + if ptsnames == nil { + defer ptsd.Close() + ptsnames, err = ptsd.Readdirnames(-1) + for _, ptsname := range ptsnames { + termfiles = append(termfiles, "/dev/pts/"+ptsname) + } + } else { + termfiles = ptsnames } for _, name := range termfiles { diff --git a/vendor/github.com/shirou/gopsutil/process/process_windows.go b/vendor/github.com/shirou/gopsutil/process/process_windows.go index 8982a9559ba..7507ab036f7 100644 --- a/vendor/github.com/shirou/gopsutil/process/process_windows.go +++ b/vendor/github.com/shirou/gopsutil/process/process_windows.go @@ -308,9 +308,20 @@ func (p *Process) Suspend() error { func (p *Process) Resume() error { return common.ErrNotImplementedError } + func (p *Process) Terminate() error { - return common.ErrNotImplementedError + // PROCESS_TERMINATE = 0x0001 + proc := w32.OpenProcess(0x0001, false, uint32(p.Pid)) + ret := w32.TerminateProcess(proc, 0) + w32.CloseHandle(proc) + + if ret == false { + return syscall.GetLastError() + } else { + return nil + } } + func (p *Process) Kill() error { return common.ErrNotImplementedError } diff --git a/vendor/github.com/shirou/gopsutil/process/types_openbsd.go b/vendor/github.com/shirou/gopsutil/process/types_openbsd.go new file mode 100644 index 00000000000..09ac590288a --- /dev/null +++ b/vendor/github.com/shirou/gopsutil/process/types_openbsd.go @@ -0,0 +1,103 @@ +// +build ignore + +// We still need editing by hands. +// go tool cgo -godefs types_openbsd.go | sed 's/\*int64/int64/' | sed 's/\*byte/int64/' > process_openbsd_amd64.go + +/* +Input to cgo -godefs. +*/ + +// +godefs map struct_pargs int64 /* pargs */ +// +godefs map struct_proc int64 /* proc */ +// +godefs map struct_user int64 /* user */ +// +godefs map struct_vnode int64 /* vnode */ +// +godefs map struct_vnode int64 /* vnode */ +// +godefs map struct_filedesc int64 /* filedesc */ +// +godefs map struct_vmspace int64 /* vmspace */ +// +godefs map struct_pcb int64 /* pcb */ +// +godefs map struct_thread int64 /* thread */ +// +godefs map struct___sigset [16]byte /* sigset */ + +package process + +/* +#include +#include +#include + +enum { + sizeofPtr = sizeof(void*), +}; + + +*/ +import "C" + +// Machine characteristics; for internal use. + +const ( + CTLKern = 1 // "high kernel": proc, limits + KernProc = 66 // struct: process entries + KernProcAll = 0 + KernProcPID = 1 // by process id + KernProcProc = 8 // only return procs + KernProcPathname = 12 // path to executable + KernProcArgs = 55 // get/set arguments/proctitle + KernProcArgv = 1 + KernProcEnv = 3 +) + +const ( + ArgMax = 256 * 1024 // sys/syslimits.h:#define ARG_MAX +) + +const ( + sizeofPtr = C.sizeofPtr + sizeofShort = C.sizeof_short + sizeofInt = C.sizeof_int + sizeofLong = C.sizeof_long + sizeofLongLong = C.sizeof_longlong +) + +const ( + sizeOfKinfoVmentry = C.sizeof_struct_kinfo_vmentry + sizeOfKinfoProc = C.sizeof_struct_kinfo_proc +) + +// from sys/proc.h +const ( + SIDL = 1 /* Process being created by fork. */ + SRUN = 2 /* Currently runnable. */ + SSLEEP = 3 /* Sleeping on an address. */ + SSTOP = 4 /* Process debugging or suspension. */ + SZOMB = 5 /* Awaiting collection by parent. */ + SDEAD = 6 /* Thread is almost gone */ + SONPROC = 7 /* Thread is currently on a CPU. */ +) + +// Basic types + +type ( + _C_short C.short + _C_int C.int + _C_long C.long + _C_long_long C.longlong +) + +// Time + +type Timespec C.struct_timespec + +type Timeval C.struct_timeval + +// Processes + +type Rusage C.struct_rusage + +type Rlimit C.struct_rlimit + +type KinfoProc C.struct_kinfo_proc + +type Priority C.struct_priority + +type KinfoVmentry C.struct_kinfo_vmentry diff --git a/vendor/vendor.json b/vendor/vendor.json index 4b43c9828a8..b4f69fad01d 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -983,52 +983,46 @@ "revisionTime": "2016-04-29T17:20:22Z" }, { - "checksumSHA1": "Y13016ky4eYYAcgajHFtgxkkoW8=", - "path": "github.com/shirou/gopsutil", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" - }, - { - "checksumSHA1": "ToLFWWpwBceipBQRASIxs36Glok=", + "checksumSHA1": "zW2k8E1gkuySzTz2eXuSEDhpffY=", "path": "github.com/shirou/gopsutil/cpu", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" + "revision": "77b5d0080adb6f028e457906f1944d9fcca34442", + "revisionTime": "2017-02-02T00:16:45Z" }, { - "checksumSHA1": "NOh16yOqf+hH+0XMJp3uV1Kb9FA=", + "checksumSHA1": "EHW4AH6SCfTJGTrnqZ56PiOrJ7o=", "path": "github.com/shirou/gopsutil/disk", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" + "revision": "77b5d0080adb6f028e457906f1944d9fcca34442", + "revisionTime": "2017-02-02T00:16:45Z" }, { - "checksumSHA1": "h0VVpxfeH65DnrSUtatFdvDS+RU=", + "checksumSHA1": "j1sK6Ka83ypdYZzmuU+nTPXLPT0=", "path": "github.com/shirou/gopsutil/host", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" + "revision": "77b5d0080adb6f028e457906f1944d9fcca34442", + "revisionTime": "2017-02-02T00:16:45Z" }, { - "checksumSHA1": "UnT7JW8ZDcUVJUYOPBfW6SToB0k=", + "checksumSHA1": "hz9RxkaV3Tnju2eiHBWO/Yv7n5c=", "path": "github.com/shirou/gopsutil/internal/common", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" + "revision": "77b5d0080adb6f028e457906f1944d9fcca34442", + "revisionTime": "2017-02-02T00:16:45Z" }, { - "checksumSHA1": "icZu8CrEyx4utr0MSc8CfTgQ1tU=", + "checksumSHA1": "XQwjGKI51Y3aQ3/jNyRh9Gnprgg=", "path": "github.com/shirou/gopsutil/mem", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" + "revision": "77b5d0080adb6f028e457906f1944d9fcca34442", + "revisionTime": "2017-02-02T00:16:45Z" }, { - "checksumSHA1": "hk7C6mEL2gyz79NfGa/s8YxPMUE=", + "checksumSHA1": "OSvOZs5uK5iolCOeS46nB2InVy8=", "path": "github.com/shirou/gopsutil/net", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" + "revision": "77b5d0080adb6f028e457906f1944d9fcca34442", + "revisionTime": "2017-02-02T00:16:45Z" }, { - "checksumSHA1": "cjLXT38Rtk5H/Sx+05PEqU8ta5Y=", + "checksumSHA1": "JX0bRK/BdKVfbm4XOxMducVdY58=", "path": "github.com/shirou/gopsutil/process", - "revision": "859c81da50839c6829da58c9e90e1fff1edd8194", - "revisionTime": "2016-08-29T23:42:49Z" + "revision": "77b5d0080adb6f028e457906f1944d9fcca34442", + "revisionTime": "2017-02-02T00:16:45Z" }, { "checksumSHA1": "Nve7SpDmjsv6+rhkXAkfg/UQx94=", From f15fe698ccd8626f36fdaa477e6d7e0d95e88265 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 1 Feb 2017 22:43:15 -0800 Subject: [PATCH 7/8] Update `github.com/StackExchange/wmi` --- vendor/github.com/StackExchange/wmi/wmi.go | 59 ++++++++++++++++------ vendor/vendor.json | 4 +- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/vendor/github.com/StackExchange/wmi/wmi.go b/vendor/github.com/StackExchange/wmi/wmi.go index b931ca57afc..5cb56ff1ec9 100644 --- a/vendor/github.com/StackExchange/wmi/wmi.go +++ b/vendor/github.com/StackExchange/wmi/wmi.go @@ -45,9 +45,15 @@ var l = log.New(os.Stdout, "", log.LstdFlags) var ( ErrInvalidEntityType = errors.New("wmi: invalid entity type") - lock sync.Mutex + // ErrNilCreateObject is the error returned if CreateObject returns nil even + // if the error was nil. + ErrNilCreateObject = errors.New("wmi: create object returned nil") + lock sync.Mutex ) +// S_FALSE is returned by CoInitializeEx if it was already called on this thread. +const S_FALSE = 0x00000001 + // QueryNamespace invokes Query with the given namespace on the local machine. func QueryNamespace(query string, dst interface{}, namespace string) error { return Query(query, dst, nil, namespace) @@ -126,21 +132,18 @@ func (c *Client) Query(query string, dst interface{}, connectServerArgs ...inter err := ole.CoInitializeEx(0, ole.COINIT_MULTITHREADED) if err != nil { - oleerr := err.(*ole.OleError) - // S_FALSE = 0x00000001 // CoInitializeEx was already called on this thread - if oleerr.Code() != ole.S_OK && oleerr.Code() != 0x00000001 { + oleCode := err.(*ole.OleError).Code() + if oleCode != ole.S_OK && oleCode != S_FALSE { return err } - } else { - // Only invoke CoUninitialize if the thread was not initizlied before. - // This will allow other go packages based on go-ole play along - // with this library. - defer ole.CoUninitialize() } + defer ole.CoUninitialize() unknown, err := oleutil.CreateObject("WbemScripting.SWbemLocator") if err != nil { return err + } else if unknown == nil { + return ErrNilCreateObject } defer unknown.Release() @@ -171,19 +174,34 @@ func (c *Client) Query(query string, dst interface{}, connectServerArgs ...inter return err } + enumProperty, err := result.GetProperty("_NewEnum") + if err != nil { + return err + } + defer enumProperty.Clear() + + enum, err := enumProperty.ToIUnknown().IEnumVARIANT(ole.IID_IEnumVariant) + if err != nil { + return err + } + if enum == nil { + return fmt.Errorf("can't get IEnumVARIANT, enum is nil") + } + defer enum.Release() + // Initialize a slice with Count capacity dv.Set(reflect.MakeSlice(dv.Type(), 0, int(count))) var errFieldMismatch error - for i := int64(0); i < count; i++ { + for itemRaw, length, err := enum.Next(1); length > 0; itemRaw, length, err = enum.Next(1) { + if err != nil { + return err + } + err := func() error { // item is a SWbemObject, but really a Win32_Process - itemRaw, err := oleutil.CallMethod(result, "ItemIndex", i) - if err != nil { - return err - } item := itemRaw.ToIDispatch() - defer itemRaw.Clear() + defer item.Release() ev := reflect.New(elemType) if err = c.loadEntity(ev.Interface(), item); err != nil { @@ -332,6 +350,17 @@ func (c *Client) loadEntity(dst interface{}, src *ole.IDispatch) (errFieldMismat Reason: "not a bool", } } + case float32: + switch f.Kind() { + case reflect.Float32: + f.SetFloat(float64(val)) + default: + return &ErrFieldMismatch{ + StructType: of.Type(), + FieldName: n, + Reason: "not a Float32", + } + } default: typeof := reflect.TypeOf(val) if typeof == nil && (isPtr || c.NonePtrZero) { diff --git a/vendor/vendor.json b/vendor/vendor.json index b4f69fad01d..6aeaf8eeef5 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -36,8 +36,10 @@ "revision": "4b6ea7319e214d98c938f12692336f7ca9348d6b" }, { + "checksumSHA1": "9NR0rrcAT5J76C5xMS4AVksS9o0=", "path": "github.com/StackExchange/wmi", - "revision": "f3e2bae1e0cb5aef83e319133eabfee30013a4a5" + "revision": "e54cbda6595d7293a7a468ccf9525f6bc8887f99", + "revisionTime": "2016-08-11T21:45:55Z" }, { "path": "github.com/armon/circbuf", From b07a622ff9f5e708e6420a261df4268fb231311c Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Wed, 1 Feb 2017 22:51:03 -0800 Subject: [PATCH 8/8] Update `github.com/go-ole/go-ole` and remove a bit of cruft. --- vendor/github.com/go-ole/go-ole/.travis.yml | 9 - vendor/github.com/go-ole/go-ole/ChangeLog.md | 49 ---- vendor/github.com/go-ole/go-ole/README.md | 46 ---- vendor/github.com/go-ole/go-ole/appveyor.yml | 63 ------ .../go-ole/go-ole/build/compile-go.bat | 5 - .../go-ole/go-ole/build/register-assembly.bat | 8 - .../go-ole/go-ole/data/screenshot.png | Bin 14362 -> 0 bytes .../go-ole/go-ole/example/excel/excel.go | 31 --- .../go-ole/go-ole/example/excel2/excel.go | 96 -------- .../github.com/go-ole/go-ole/example/ie/ie.go | 33 --- .../go-ole/go-ole/example/itunes/itunes.go | 47 ---- .../go-ole/example/mediaplayer/mediaplayer.go | 29 --- .../go-ole/go-ole/example/msagent/msagent.go | 24 -- .../go-ole/go-ole/example/msxml/rssreader.go | 49 ---- .../go-ole/go-ole/example/outlook/outlook.go | 29 --- .../go-ole/go-ole/example/winsock/winsock.go | 140 ------------ vendor/github.com/go-ole/go-ole/guid.go | 210 ++++++++++++++++-- .../go-ole/go-ole/idispatch_windows.go | 13 +- .../go-ole/go-ole/iinspectable_windows.go | 2 +- .../go-ole/oleutil/connection_windows.go | 1 + .../go-ole/go-ole/safearray_func.go | 8 +- vendor/vendor.json | 4 +- 22 files changed, 204 insertions(+), 692 deletions(-) delete mode 100644 vendor/github.com/go-ole/go-ole/.travis.yml delete mode 100644 vendor/github.com/go-ole/go-ole/ChangeLog.md delete mode 100644 vendor/github.com/go-ole/go-ole/README.md delete mode 100644 vendor/github.com/go-ole/go-ole/appveyor.yml delete mode 100644 vendor/github.com/go-ole/go-ole/build/compile-go.bat delete mode 100644 vendor/github.com/go-ole/go-ole/build/register-assembly.bat delete mode 100644 vendor/github.com/go-ole/go-ole/data/screenshot.png delete mode 100644 vendor/github.com/go-ole/go-ole/example/excel/excel.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/excel2/excel.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/ie/ie.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/itunes/itunes.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/mediaplayer/mediaplayer.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/msagent/msagent.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/msxml/rssreader.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/outlook/outlook.go delete mode 100644 vendor/github.com/go-ole/go-ole/example/winsock/winsock.go diff --git a/vendor/github.com/go-ole/go-ole/.travis.yml b/vendor/github.com/go-ole/go-ole/.travis.yml deleted file mode 100644 index 0c2c02bdf2e..00000000000 --- a/vendor/github.com/go-ole/go-ole/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: go -sudo: false - -go: - - 1.1 - - 1.2 - - 1.3 - - 1.4 - - tip diff --git a/vendor/github.com/go-ole/go-ole/ChangeLog.md b/vendor/github.com/go-ole/go-ole/ChangeLog.md deleted file mode 100644 index 4ba6a8c64d0..00000000000 --- a/vendor/github.com/go-ole/go-ole/ChangeLog.md +++ /dev/null @@ -1,49 +0,0 @@ -# Version 1.x.x - -* **Add more test cases and reference new test COM server project.** (Placeholder for future additions) - -# Version 1.2.0-alphaX - -**Minimum supported version is now Go 1.4. Go 1.1 support is deprecated, but should still build.** - - * Added CI configuration for Travis-CI and AppVeyor. - * Added test InterfaceID and ClassID for the COM Test Server project. - * Added more inline documentation (#83). - * Added IEnumVARIANT implementation (#88). - * Added IEnumVARIANT test cases (#99, #100, #101). - * Added support for retrieving `time.Time` from VARIANT (#92). - * Added test case for IUnknown (#64). - * Added test case for IDispatch (#64). - * Added test cases for scalar variants (#64, #76). - -# Version 1.1.1 - - * Fixes for Linux build. - * Fixes for Windows build. - -# Version 1.1.0 - -The change to provide building on all platforms is a new feature. The increase in minor version reflects that and allows those who wish to stay on 1.0.x to continue to do so. Support for 1.0.x will be limited to bug fixes. - - * Move GUID out of variables.go into its own file to make new documentation available. - * Move OleError out of ole.go into its own file to make new documentation available. - * Add documentation to utility functions. - * Add documentation to variant receiver functions. - * Add documentation to ole structures. - * Make variant available to other systems outside of Windows. - * Make OLE structures available to other systems outside of Windows. - -## New Features - - * Library should now be built on all platforms supported by Go. Library will NOOP on any platform that is not Windows. - * More functions are now documented and available on godoc.org. - -# Version 1.0.1 - - 1. Fix package references from repository location change. - -# Version 1.0.0 - -This version is stable enough for use. The COM API is still incomplete, but provides enough functionality for accessing COM servers using IDispatch interface. - -There is no changelog for this version. Check commits for history. diff --git a/vendor/github.com/go-ole/go-ole/README.md b/vendor/github.com/go-ole/go-ole/README.md deleted file mode 100644 index 0ea9db33c79..00000000000 --- a/vendor/github.com/go-ole/go-ole/README.md +++ /dev/null @@ -1,46 +0,0 @@ -#Go OLE - -[![Build status](https://ci.appveyor.com/api/projects/status/qr0u2sf7q43us9fj?svg=true)](https://ci.appveyor.com/project/jacobsantos/go-ole-jgs28) -[![Build Status](https://travis-ci.org/go-ole/go-ole.svg?branch=master)](https://travis-ci.org/go-ole/go-ole) -[![GoDoc](https://godoc.org/github.com/go-ole/go-ole?status.svg)](https://godoc.org/github.com/go-ole/go-ole) - -Go bindings for Windows COM using shared libraries instead of cgo. - -By Yasuhiro Matsumoto. - -## Install - -To experiment with go-ole, you can just compile and run the example program: - -``` -go get github.com/go-ole/go-ole -cd /path/to/go-ole/ -go test - -cd /path/to/go-ole/example/excel -go run excel.go -``` - -## Continuous Integration - -Continuous integration configuration has been added for both Travis-CI and AppVeyor. You will have to add these to your own account for your fork in order for it to run. - -**Travis-CI** - -Travis-CI was added to check builds on Linux to ensure that `go get` works when cross building. Currently, Travis-CI is not used to test cross-building, but this may be changed in the future. It is also not currently possible to test the library on Linux, since COM API is specific to Windows and it is not currently possible to run a COM server on Linux or even connect to a remote COM server. - -**AppVeyor** - -AppVeyor is used to build on Windows using the (in-development) test COM server. It is currently only used to test the build and ensure that the code works on Windows. It will be used to register a COM server and then run the test cases based on the test COM server. - -The tests currently do run and do pass and this should be maintained with commits. - -##Versioning - -Go OLE uses [semantic versioning](http://semver.org) for version numbers, which is similar to the version contract of the Go language. Which means that the major version will always maintain backwards compatibility with minor versions. Minor versions will only add new additions and changes. Fixes will always be in patch. - -This contract should allow you to upgrade to new minor and patch versions without breakage or modifications to your existing code. Leave a ticket, if there is breakage, so that it could be fixed. - -##LICENSE - -Under the MIT License: http://mattn.mit-license.org/2013 diff --git a/vendor/github.com/go-ole/go-ole/appveyor.yml b/vendor/github.com/go-ole/go-ole/appveyor.yml deleted file mode 100644 index e66dd31a1db..00000000000 --- a/vendor/github.com/go-ole/go-ole/appveyor.yml +++ /dev/null @@ -1,63 +0,0 @@ -# Notes: -# - Minimal appveyor.yml file is an empty file. All sections are optional. -# - Indent each level of configuration with 2 spaces. Do not use tabs! -# - All section names are case-sensitive. -# - Section names should be unique on each level. - -version: "1.3.0.{build}-alpha-{branch}" - -os: Windows Server 2012 R2 - -branches: - only: - - master - - v1.2 - - v1.1 - - v1.0 - -skip_tags: true - -clone_folder: c:\gopath\src\github.com\go-ole\go-ole - -environment: - GOPATH: c:\gopath - matrix: - - GOARCH: amd64 - GOVERSION: 1.4 - GOROOT: c:\go - DOWNLOADPLATFORM: "x64" - -install: - - choco install mingw - - SET PATH=c:\tools\mingw64\bin;%PATH% - # - Download COM Server - - ps: Start-FileDownload "https://github.com/go-ole/test-com-server/releases/download/v1.0.2/test-com-server-${env:DOWNLOADPLATFORM}.zip" - - 7z e test-com-server-%DOWNLOADPLATFORM%.zip -oc:\gopath\src\github.com\go-ole\go-ole > NUL - - c:\gopath\src\github.com\go-ole\go-ole\build\register-assembly.bat - # - set - - go version - - go env - - c:\gopath\src\github.com\go-ole\go-ole\build\compile-go.bat - - go tool dist install -v cmd/8a - - go tool dist install -v cmd/8c - - go tool dist install -v cmd/8g - - go tool dist install -v cmd/8l - - go tool dist install -v cmd/6a - - go tool dist install -v cmd/6c - - go tool dist install -v cmd/6g - - go tool dist install -v cmd/6l - - go get -u golang.org/x/tools/cmd/cover - - go get -u golang.org/x/tools/cmd/godoc - - go get -u golang.org/x/tools/cmd/stringer - -build_script: - - cd c:\gopath\src\github.com\go-ole\go-ole - - go get -v -t ./... - - go build - - go test -v -cover ./... - -# disable automatic tests -test: off - -# disable deployment -deploy: off diff --git a/vendor/github.com/go-ole/go-ole/build/compile-go.bat b/vendor/github.com/go-ole/go-ole/build/compile-go.bat deleted file mode 100644 index 61eed9496a8..00000000000 --- a/vendor/github.com/go-ole/go-ole/build/compile-go.bat +++ /dev/null @@ -1,5 +0,0 @@ -@echo OFF - -echo "BUILD GOLANG" -cd "%GOROOT%\src" -./make.bat --dist-tool diff --git a/vendor/github.com/go-ole/go-ole/build/register-assembly.bat b/vendor/github.com/go-ole/go-ole/build/register-assembly.bat deleted file mode 100644 index e2ca87fe522..00000000000 --- a/vendor/github.com/go-ole/go-ole/build/register-assembly.bat +++ /dev/null @@ -1,8 +0,0 @@ -@ECHO OFF - -IF "x86" == "%DOWNLOADPLATFORM%" ( - CALL c:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll -) -IF "x64" == "%DOWNLOADPLATFORM%" ( - CALL c:\Windows\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe /codebase /nologo c:\gopath\src\github.com\go-ole\go-ole\TestCOMServer.dll -) diff --git a/vendor/github.com/go-ole/go-ole/data/screenshot.png b/vendor/github.com/go-ole/go-ole/data/screenshot.png deleted file mode 100644 index f61344b6005864217cfdf2b0d822b0575597c64e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 14362 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] + b[1] = hextable[byte(v>>24)&0x0f] + b[2] = hextable[byte(v>>16)>>4] + b[3] = hextable[byte(v>>16)&0x0f] + b[4] = hextable[byte(v>>8)>>4] + b[5] = hextable[byte(v>>8)&0x0f] + b[6] = hextable[byte(v)>>4] + b[7] = hextable[byte(v)&0x0f] +} + +func putUint16Hex(b []byte, v uint16) { + b[0] = hextable[byte(v>>8)>>4] + b[1] = hextable[byte(v>>8)&0x0f] + b[2] = hextable[byte(v)>>4] + b[3] = hextable[byte(v)&0x0f] +} + +func putByteHex(dst, src []byte) { + for i := 0; i < len(src); i++ { + dst[i*2] = hextable[src[i]>>4] + dst[i*2+1] = hextable[src[i]&0x0f] + } +} + // IsEqualGUID compares two GUID. // // Not constant time comparison. diff --git a/vendor/github.com/go-ole/go-ole/idispatch_windows.go b/vendor/github.com/go-ole/go-ole/idispatch_windows.go index 10b1ae46494..bb736903825 100644 --- a/vendor/github.com/go-ole/go-ole/idispatch_windows.go +++ b/vendor/github.com/go-ole/go-ole/idispatch_windows.go @@ -180,17 +180,14 @@ func invoke(disp *IDispatch, dispid int32, dispatch int16, params ...interface{} if hr != 0 { err = NewErrorWithSubError(hr, BstrToString(excepInfo.bstrDescription), excepInfo) } - for _, varg := range vargs { + for i, varg := range vargs { + n := len(params) - i - 1 if varg.VT == VT_BSTR && varg.Val != 0 { SysFreeString(((*int16)(unsafe.Pointer(uintptr(varg.Val))))) } - /* - if varg.VT == (VT_BSTR|VT_BYREF) && varg.Val != 0 { - *(params[n].(*string)) = LpOleStrToString((*uint16)(unsafe.Pointer(uintptr(varg.Val)))) - println(*(params[n].(*string))) - fmt.Fprintln(os.Stderr, *(params[n].(*string))) - } - */ + if varg.VT == (VT_BSTR|VT_BYREF) && varg.Val != 0 { + *(params[n].(*string)) = LpOleStrToString(*(**uint16)(unsafe.Pointer(uintptr(varg.Val)))) + } } return } diff --git a/vendor/github.com/go-ole/go-ole/iinspectable_windows.go b/vendor/github.com/go-ole/go-ole/iinspectable_windows.go index b19dde5b57c..4519a4aa449 100644 --- a/vendor/github.com/go-ole/go-ole/iinspectable_windows.go +++ b/vendor/github.com/go-ole/go-ole/iinspectable_windows.go @@ -30,7 +30,7 @@ func (v *IInspectable) GetIids() (iids []*GUID, err error) { slicehdr := reflect.SliceHeader{Data: array, Len: int(byteCount), Cap: int(byteCount)} byteSlice := *(*[]byte)(unsafe.Pointer(&slicehdr)) reader := bytes.NewReader(byteSlice) - for i, _ := range iids { + for i := range iids { guid := GUID{} err = binary.Read(reader, binary.LittleEndian, &guid) if err != nil { diff --git a/vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go b/vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go index 6b5c0599936..ab9c0d8dcbd 100644 --- a/vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go +++ b/vendor/github.com/go-ole/go-ole/oleutil/connection_windows.go @@ -49,6 +49,7 @@ func ConnectObject(disp *ole.IDispatch, iid *ole.GUID, idisp interface{}) (cooki point.Release() return } + return } container.Release() diff --git a/vendor/github.com/go-ole/go-ole/safearray_func.go b/vendor/github.com/go-ole/go-ole/safearray_func.go index c261a0078c7..8ff0baa41dd 100644 --- a/vendor/github.com/go-ole/go-ole/safearray_func.go +++ b/vendor/github.com/go-ole/go-ole/safearray_func.go @@ -2,6 +2,10 @@ package ole +import ( + "unsafe" +) + // safeArrayAccessData returns raw array pointer. // // AKA: SafeArrayAccessData in Windows API. @@ -120,8 +124,8 @@ func safeArrayGetElementSize(safearray *SafeArray) (*uint32, error) { } // safeArrayGetElement retrieves element at given index. -func safeArrayGetElement(safearray *SafeArray, index int64) (uintptr, error) { - return uintptr(0), NewError(E_NOTIMPL) +func safeArrayGetElement(safearray *SafeArray, index int64, pv unsafe.Pointer) error { + return NewError(E_NOTIMPL) } // safeArrayGetElement retrieves element at given index and converts to string. diff --git a/vendor/vendor.json b/vendor/vendor.json index 6aeaf8eeef5..2ff2e9b60ef 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -484,9 +484,11 @@ "revision": "6ec4abd8f8d587536da56f730858f0e27aeb4126" }, { + "checksumSHA1": "wDZdTaY9JiqqqnF4c3pHP71nWmk=", "comment": "v1.2.0-4-g5005588", "path": "github.com/go-ole/go-ole", - "revision": "50055884d646dd9434f16bbb5c9801749b9bafe4" + "revision": "5e9c030faf78847db7aa77e3661b9cc449de29b7", + "revisionTime": "2016-11-16T06:46:58Z" }, { "comment": "v1.2.0-4-g5005588",