vendor: update elastic/gosigar so that it compiles on OpenBSD (#16542)

This commit is contained in:
Fabian Raetz 2018-04-21 19:19:12 +02:00 committed by Felix Lange
parent b15eb665ee
commit 744428cb03
12 changed files with 98 additions and 7 deletions

View File

@ -8,10 +8,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Added missing runtime import for FreeBSD. #104
### Changed
### Deprecated
## [0.9.0]
### Added
- Added support for huge TLB pages on Linux #97
- Added support for big endian platform #100
### Fixed
- Add missing method for OpenBSD #99
## [0.8.0]
### Added

View File

@ -26,6 +26,7 @@ The features vary by operating system.
| FDUsage | X | | | | X |
| FileSystemList | X | X | X | X | X |
| FileSystemUsage | X | X | X | X | X |
| HugeTLBPages | X | | | | |
| LoadAverage | X | X | | X | X |
| Mem | X | X | X | X | X |
| ProcArgs | X | X | X | | X |

View File

@ -62,6 +62,12 @@ func (c *ConcreteSigar) GetSwap() (Swap, error) {
return s, err
}
func (c *ConcreteSigar) GetHugeTLBPages() (HugeTLBPages, error) {
p := HugeTLBPages{}
err := p.Get()
return p, err
}
func (c *ConcreteSigar) GetFileSystemUsage(path string) (FileSystemUsage, error) {
f := FileSystemUsage{}
err := f.Get(path)

View File

@ -91,6 +91,10 @@ func (self *Swap) Get() error {
return nil
}
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (self *Cpu) Get() error {
var count C.mach_msg_type_number_t = C.HOST_CPU_LOAD_INFO_COUNT
var cpuload C.host_cpu_load_info_data_t

View File

@ -4,6 +4,7 @@ package gosigar
import (
"io/ioutil"
"runtime"
"strconv"
"strings"
"unsafe"
@ -97,6 +98,10 @@ func (self *ProcFDUsage) Get(pid int) error {
return nil
}
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func parseCpuStat(self *Cpu, line string) error {
fields := strings.Fields(line)

View File

@ -26,6 +26,7 @@ type Sigar interface {
GetLoadAverage() (LoadAverage, error)
GetMem() (Mem, error)
GetSwap() (Swap, error)
GetHugeTLBPages(HugeTLBPages, error)
GetFileSystemUsage(string) (FileSystemUsage, error)
GetFDUsage() (FDUsage, error)
GetRusage(who int) (Rusage, error)
@ -82,6 +83,15 @@ type Swap struct {
Free uint64
}
type HugeTLBPages struct {
Total uint64
Free uint64
Reserved uint64
Surplus uint64
DefaultSize uint64
TotalAllocatedSize uint64
}
type CpuList struct {
List []Cpu
}

View File

@ -45,6 +45,30 @@ func (self *FDUsage) Get() error {
})
}
func (self *HugeTLBPages) Get() error {
table, err := parseMeminfo()
if err != nil {
return err
}
self.Total, _ = table["HugePages_Total"]
self.Free, _ = table["HugePages_Free"]
self.Reserved, _ = table["HugePages_Rsvd"]
self.Surplus, _ = table["HugePages_Surp"]
self.DefaultSize, _ = table["Hugepagesize"]
if totalSize, found := table["Hugetlb"]; found {
self.TotalAllocatedSize = totalSize
} else {
// If Hugetlb is not present, or huge pages of different sizes
// are used, this figure can be unaccurate.
// TODO (jsoriano): Extract information from /sys/kernel/mm/hugepages too
self.TotalAllocatedSize = (self.Total - self.Free + self.Reserved) * self.DefaultSize
}
return nil
}
func (self *ProcFDUsage) Get(pid int) error {
err := readFile(procFileName(pid, "limits"), func(line string) bool {
if strings.HasPrefix(line, "Max open files") {

View File

@ -379,12 +379,16 @@ func parseMeminfo() (map[string]uint64, error) {
return true // skip on errors
}
num := strings.TrimLeft(fields[1], " ")
val, err := strtoull(strings.Fields(num)[0])
valueUnit := strings.Fields(fields[1])
value, err := strtoull(valueUnit[0])
if err != nil {
return true // skip on errors
}
table[fields[0]] = val * 1024 //in bytes
if len(valueUnit) > 1 && valueUnit[1] == "kB" {
value *= 1024
}
table[fields[0]] = value
return true
})
@ -420,8 +424,18 @@ func procFileName(pid int, name string) string {
return Procd + "/" + strconv.Itoa(pid) + "/" + name
}
func readProcFile(pid int, name string) ([]byte, error) {
func readProcFile(pid int, name string) (content []byte, err error) {
path := procFileName(pid, name)
// Panics have been reported when reading proc files, let's recover and
// report the path if this happens
// See https://github.com/elastic/beats/issues/6692
defer func() {
if r := recover(); r != nil {
content = nil
err = fmt.Errorf("recovered panic when reading proc file '%s': %v", path, r)
}
}()
contents, err := ioutil.ReadFile(path)
if err != nil {

View File

@ -294,6 +294,10 @@ func (self *Swap) Get() error {
return nil
}
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (self *Cpu) Get() error {
load := [C.CPUSTATES]C.long{C.CP_USER, C.CP_NICE, C.CP_SYS, C.CP_INTR, C.CP_IDLE}
@ -381,6 +385,10 @@ func (self *ProcFDUsage) Get(pid int) error {
return ErrNotImplemented{runtime.GOOS}
}
func (self *Rusage) Get(pid int) error {
return ErrNotImplemented{runtime.GOOS}
}
func fillCpu(cpu *Cpu, load [C.CPUSTATES]C.long) {
cpu.User = uint64(load[0])
cpu.Nice = uint64(load[1])

View File

@ -22,6 +22,10 @@ func (s *Swap) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (s *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (f *FDUsage) Get() error {
return ErrNotImplemented{runtime.GOOS}
}

View File

@ -120,6 +120,10 @@ func (self *Swap) Get() error {
return nil
}
func (self *HugeTLBPages) Get() error {
return ErrNotImplemented{runtime.GOOS}
}
func (self *Cpu) Get() error {
idle, kernel, user, err := windows.GetSystemTimes()
if err != nil {

6
vendor/vendor.json vendored
View File

@ -93,10 +93,10 @@
"revisionTime": "2016-05-12T03:30:02Z"
},
{
"checksumSHA1": "Fc8BCxCoQ7ZmghDT6X1cASR10Ec=",
"checksumSHA1": "jElNoLEe7m/iaoF1vYIHyNaS2SE=",
"path": "github.com/elastic/gosigar",
"revision": "a3814ce5008e612a0c6d027608b54e1d0d9a5613",
"revisionTime": "2018-01-22T22:25:45Z"
"revision": "37f05ff46ffa7a825d1b24cf2b62d4a4c1a9d2e8",
"revisionTime": "2018-03-30T10:04:40Z"
},
{
"checksumSHA1": "qDsgp2kAeI9nhj565HUScaUyjU4=",