From 74cd3d85865c2b2ee0dd58766cb02b43f2f7d86e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9mi=20V=C3=A1nyi?= Date: Thu, 30 Nov 2017 19:57:13 +0100 Subject: [PATCH] Update elastic/gosigar to v0.6.0 (#5775) * update elastic/gosigar to v0.6.0 * update changelog to include fixes and update * update notice && more gosigar versions --- CHANGELOG.asciidoc | 3 + NOTICE.txt | 4 +- .../github.com/elastic/gosigar/CHANGELOG.md | 12 +++- .../elastic/gosigar/sigar_freebsd.go | 5 ++ .../elastic/gosigar/sigar_linux_common.go | 65 +++++++++++-------- .../elastic/gosigar/sigar_openbsd.go | 2 +- .../github.com/elastic/gosigar/sigar_stub.go | 35 ++++++++++ .../github.com/elastic/gosigar/sigar_unix.go | 2 +- vendor/vendor.json | 24 +++---- 9 files changed, 107 insertions(+), 45 deletions(-) create mode 100644 vendor/github.com/elastic/gosigar/sigar_stub.go diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 8b854023f400..175d628e43fd 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -71,6 +71,8 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Fix error `NotAuthenticated` in Vsphere module. {issue}4673[4673] - Fix connection leak in mongodb module. {issue}5688[5688] - Fix the include top N processes feature for cases where there are fewer processes than N. {pull}5729[5729] +- Fix `ProcState` on Linux and FreeBSD when process names contain parentheses. {pull}5775[5775] +- Fix incorrect `Mem.Used` calculation under linux. {pull}5775[5775] *Packetbeat* @@ -131,6 +133,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Add dashboard for Windows service metricset. {pull}5603[5603] - Add experimental Docker autodiscover functionality. {pull}5245[5245] - Add field network_names of hosts and virtual machines. {issue}5646[5646] +- Update gosigar to v0.6.0. {pull}5775[5775] *Packetbeat* diff --git a/NOTICE.txt b/NOTICE.txt index a021e677828e..701f087a58ba 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -370,8 +370,8 @@ Apache License 2.0 -------------------------------------------------------------------- Dependency: github.com/elastic/gosigar -Version: v0.5.0 -Revision: 306d51981789ccc65e5f1431d5c0d78d8c368f1b +Version: v0.6.0 +Revision: 5cb8fed1ceb7f0fd69e4ad61c715a80601dddfd2 License type (autodetected): Apache-2.0 ./vendor/github.com/elastic/gosigar/LICENSE: -------------------------------------------------------------------- diff --git a/vendor/github.com/elastic/gosigar/CHANGELOG.md b/vendor/github.com/elastic/gosigar/CHANGELOG.md index 16ca054c7be6..c659b5788472 100644 --- a/vendor/github.com/elastic/gosigar/CHANGELOG.md +++ b/vendor/github.com/elastic/gosigar/CHANGELOG.md @@ -2,15 +2,21 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). -## [Unreleased] +## [0.6.0] ### Added +- Added method stubs to enable compilation for operating systems that are not + supported by gosigar. All methods return `ErrNotImplemented` on these unsupported + operating systems. #83 +- FreeBSD returns `ErrNotImplemented` for `ProcTime.Get`. #83 ### Changed - -### Deprecated +- OpenBSD returns `ErrNotImplemented` for `ProcTime.Get` instead of `nil`. #83 +- Fixed incorrect `Mem.Used` calculation under linux. #82 +- Fixed `ProcState` on Linux and FreeBSD when process names contain parentheses. #81 ### Removed +- Remove NetBSD build from sigar_unix.go as it is not supported by gosigar. #83 ## [0.5.0] diff --git a/vendor/github.com/elastic/gosigar/sigar_freebsd.go b/vendor/github.com/elastic/gosigar/sigar_freebsd.go index 602b4a0aad91..0a31d0887c9d 100644 --- a/vendor/github.com/elastic/gosigar/sigar_freebsd.go +++ b/vendor/github.com/elastic/gosigar/sigar_freebsd.go @@ -4,6 +4,7 @@ package gosigar import ( "io/ioutil" + "runtime" "strconv" "strings" "unsafe" @@ -106,3 +107,7 @@ func parseCpuStat(self *Cpu, line string) error { self.Idle, _ = strtoull(fields[4]) return nil } + +func (self *ProcTime) Get(pid int) error { + return ErrNotImplemented{runtime.GOOS} +} diff --git a/vendor/github.com/elastic/gosigar/sigar_linux_common.go b/vendor/github.com/elastic/gosigar/sigar_linux_common.go index 3f490bf97129..8e5e7856f690 100644 --- a/vendor/github.com/elastic/gosigar/sigar_linux_common.go +++ b/vendor/github.com/elastic/gosigar/sigar_linux_common.go @@ -7,7 +7,6 @@ package gosigar import ( "bufio" "bytes" - "errors" "fmt" "io" "io/ioutil" @@ -71,7 +70,7 @@ func (self *Mem) Get() error { self.ActualFree = self.Free + buffers + cached } - self.Used = self.Total - self.ActualFree + self.Used = self.Total - self.Free self.ActualUsed = self.Total - self.ActualFree return nil @@ -181,44 +180,58 @@ func (self *ProcList) Get() error { } func (self *ProcState) Get(pid int) error { - contents, err := readProcFile(pid, "stat") + data, err := readProcFile(pid, "stat") if err != nil { return err } - headerAndStats := strings.SplitAfterN(string(contents), ")", 2) - pidAndName := headerAndStats[0] - fields := strings.Fields(headerAndStats[1]) - - name := strings.SplitAfterN(pidAndName, " ", 2)[1] - if name[0] == '(' && name[len(name)-1] == ')' { - self.Name = name[1 : len(name)-1] // strip ()'s - } else { - return errors.New(fmt.Sprintf("Malformed process stats for pid %d", pid)) + // Extract the comm value with is surrounded by parentheses. + lIdx := bytes.Index(data, []byte("(")) + rIdx := bytes.LastIndex(data, []byte(")")) + if lIdx < 0 || rIdx < 0 || lIdx >= rIdx || rIdx+2 >= len(data) { + return fmt.Errorf("failed to extract comm for pid %d from '%v'", pid, string(data)) } + self.Name = string(data[lIdx+1 : rIdx]) - self.State = RunState(fields[0][0]) - - self.Ppid, _ = strconv.Atoi(fields[1]) - - self.Pgid, _ = strconv.Atoi(fields[2]) - - self.Tty, _ = strconv.Atoi(fields[4]) - - self.Priority, _ = strconv.Atoi(fields[15]) - - self.Nice, _ = strconv.Atoi(fields[16]) + // Extract the rest of the fields that we are interested in. + fields := bytes.Fields(data[rIdx+2:]) + if len(fields) <= 36 { + return fmt.Errorf("expected more stat fields for pid %d from '%v'", pid, string(data)) + } - self.Processor, _ = strconv.Atoi(fields[36]) + interests := bytes.Join([][]byte{ + fields[0], // state + fields[1], // ppid + fields[2], // pgrp + fields[4], // tty_nr + fields[15], // priority + fields[16], // nice + fields[36], // processor (last processor executed on) + }, []byte(" ")) + + var state string + _, err = fmt.Fscan(bytes.NewBuffer(interests), + &state, + &self.Ppid, + &self.Pgid, + &self.Tty, + &self.Priority, + &self.Nice, + &self.Processor, + ) + if err != nil { + return fmt.Errorf("failed to parse stat fields for pid %d from '%v': %v", pid, string(data), err) + } + self.State = RunState(state[0]) // Read /proc/[pid]/status to get the uid, then lookup uid to get username. status, err := getProcStatus(pid) if err != nil { - return fmt.Errorf("failed to read process status for pid %d. %v", pid, err) + return fmt.Errorf("failed to read process status for pid %d: %v", pid, err) } uids, err := getUIDs(status) if err != nil { - return fmt.Errorf("failed to read process status for pid %d. %v", pid, err) + return fmt.Errorf("failed to read process status for pid %d: %v", pid, err) } user, err := user.LookupId(uids[0]) if err == nil { diff --git a/vendor/github.com/elastic/gosigar/sigar_openbsd.go b/vendor/github.com/elastic/gosigar/sigar_openbsd.go index abf967b8300f..4f1383a6ba93 100644 --- a/vendor/github.com/elastic/gosigar/sigar_openbsd.go +++ b/vendor/github.com/elastic/gosigar/sigar_openbsd.go @@ -370,7 +370,7 @@ func (self *ProcMem) Get(pid int) error { } func (self *ProcTime) Get(pid int) error { - return nil + return ErrNotImplemented{runtime.GOOS} } func (self *ProcExe) Get(pid int) error { diff --git a/vendor/github.com/elastic/gosigar/sigar_stub.go b/vendor/github.com/elastic/gosigar/sigar_stub.go new file mode 100644 index 000000000000..18beb3cf8693 --- /dev/null +++ b/vendor/github.com/elastic/gosigar/sigar_stub.go @@ -0,0 +1,35 @@ +// +build !darwin,!freebsd,!linux,!openbsd,!windows + +package gosigar + +import ( + "runtime" +) + +func (c *Cpu) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + +func (l *LoadAverage) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + +func (m *Mem) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + +func (s *Swap) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + +func (f *FDUsage) Get() error { + return ErrNotImplemented{runtime.GOOS} +} + +func (p *ProcTime) Get(int) error { + return ErrNotImplemented{runtime.GOOS} +} + +func (self *FileSystemUsage) Get(path string) error { + return ErrNotImplemented{runtime.GOOS} +} diff --git a/vendor/github.com/elastic/gosigar/sigar_unix.go b/vendor/github.com/elastic/gosigar/sigar_unix.go index 985c3720fb71..f11c156f513c 100644 --- a/vendor/github.com/elastic/gosigar/sigar_unix.go +++ b/vendor/github.com/elastic/gosigar/sigar_unix.go @@ -1,6 +1,6 @@ // Copyright (c) 2012 VMware, Inc. -// +build darwin freebsd linux netbsd +// +build darwin freebsd linux package gosigar diff --git a/vendor/vendor.json b/vendor/vendor.json index 510232c152f5..8313316cd6a2 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1,6 +1,6 @@ { "comment": "", - "ignore": "test github.com/elastic/beats/metricbeat/module github.com/elastic/beats/dev-tools", + "ignore": "test", "package": [ { "checksumSHA1": "AzjRkOQtVBTwIw4RJLTygFhJs3s=", @@ -479,36 +479,36 @@ "revisionTime": "2017-02-07T06:38:51Z" }, { - "checksumSHA1": "XCXFL46ybPz+NgKH+Pm9hW87wNA=", + "checksumSHA1": "VxEaRgCf+HRL7Sv5stNL9xprK/8=", "path": "github.com/elastic/gosigar", - "revision": "306d51981789ccc65e5f1431d5c0d78d8c368f1b", - "revisionTime": "2017-10-12T15:04:52Z", - "version": "v0.5.0", - "versionExact": "v0.5.0" + "revision": "5cb8fed1ceb7f0fd69e4ad61c715a80601dddfd2", + "revisionTime": "2017-11-17T13:55:06Z", + "version": "v0.6.0", + "versionExact": "v0.6.0" }, { "checksumSHA1": "jE0nhsyuGyQ7vWoyBRPEU63mQ4g=", "path": "github.com/elastic/gosigar/cgroup", "revision": "306d51981789ccc65e5f1431d5c0d78d8c368f1b", "revisionTime": "2017-10-12T15:04:52Z", - "version": "v0.5.0", - "versionExact": "v0.5.0" + "version": "v0.6.0", + "versionExact": "v0.6.0" }, { "checksumSHA1": "2VhOsaR4sv3S79HO6X+6dEphNKU=", "path": "github.com/elastic/gosigar/sys/linux", "revision": "306d51981789ccc65e5f1431d5c0d78d8c368f1b", "revisionTime": "2017-10-12T15:04:52Z", - "version": "v0.5.0", - "versionExact": "v0.5.0" + "version": "v0.6.0", + "versionExact": "v0.6.0" }, { "checksumSHA1": "qDsgp2kAeI9nhj565HUScaUyjU4=", "path": "github.com/elastic/gosigar/sys/windows", "revision": "306d51981789ccc65e5f1431d5c0d78d8c368f1b", "revisionTime": "2017-10-12T15:04:52Z", - "version": "v0.5.0", - "versionExact": "v0.5.0" + "version": "v0.6.0", + "versionExact": "v0.6.0" }, { "checksumSHA1": "P0CvGmmAM8uYPSE2ix4th/L9c/8=",