Merge pull request #1015 from yuce/988-989-diagnostics-os-mem-info

Adds CPU and mem info to the diagnostics payload. Implements #988, #989
This commit is contained in:
Yuce Tekol 2017-12-20 00:01:22 +03:00 committed by GitHub
commit d6fe6e18af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 2 deletions

22
Gopkg.lock generated
View file

@ -19,6 +19,12 @@
revision = "0ddda6bee21174ef6c4873647cb0d6ec9cba996f"
version = "1.1.0"
[[projects]]
branch = "master"
name = "github.com/StackExchange/wmi"
packages = ["."]
revision = "ea383cf3ba6ec950874b8486cd72356d007c768f"
[[projects]]
branch = "master"
name = "github.com/armon/go-metrics"
@ -43,6 +49,12 @@
revision = "629574ca2a5df945712d3079857300b5e4da0236"
version = "v1.4.2"
[[projects]]
name = "github.com/go-ole/go-ole"
packages = [".","oleutil"]
revision = "0e87ea779d9deb219633b828a023b32e1244dd57"
version = "v1.2.0"
[[projects]]
name = "github.com/gogo/protobuf"
packages = ["proto"]
@ -169,6 +181,12 @@
packages = ["."]
revision = "e2103e2c35297fb7e17febb81e49b312087a2372"
[[projects]]
name = "github.com/shirou/gopsutil"
packages = ["host","internal/common","mem","process"]
revision = "bfe3c2e8f406bf352bc8df81f98c752224867349"
version = "v2.17.11"
[[projects]]
name = "github.com/sony/gobreaker"
packages = ["."]
@ -226,7 +244,7 @@
[[projects]]
branch = "master"
name = "golang.org/x/sys"
packages = ["unix"]
packages = ["unix","windows"]
revision = "1e2299c37cc91a509f1b12369872d27be0ce98a6"
[[projects]]
@ -244,6 +262,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "210f654a7a072d5751f0814e4d71ef0758dd53b3dc59ed462619396ef8621d81"
inputs-digest = "ac5bf8adcbd75986cd1b3252a745167a5447602c575eaabd0e69f2ed6b0c57d2"
solver-name = "gps-cdcl"
solver-version = 1

View file

@ -5,3 +5,7 @@
[[constraint]]
name = "github.com/satori/go.uuid"
version = "1.1.0"
[[constraint]]
name = "github.com/shirou/gopsutil"
version = "2.17.11"

View file

@ -13,6 +13,8 @@ import (
"sync"
"time"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/mem"
"github.com/sony/gobreaker"
)
@ -203,6 +205,41 @@ func (d *Diagnostics) logger() *log.Logger {
return log.New(d.logOutput, "", log.LstdFlags)
}
// EnrichWithOSInfo adds OS information to the diagnostics payload.
func (d *Diagnostics) EnrichWithOSInfo() {
osInfo, err := host.Info()
if err != nil {
d.logOutput.Write([]byte(err.Error()))
}
d.Set("HostUptime", osInfo.Uptime)
platform, family, version, err := host.PlatformInformation()
if err != nil {
d.logOutput.Write([]byte(err.Error()))
}
d.Set("OSPlatform", platform)
d.Set("OSFamily", family)
d.Set("OSVersion", version)
kernelVersion, err := host.KernelVersion()
if err != nil {
d.logOutput.Write([]byte(err.Error()))
}
d.Set("OSKernelVersion", kernelVersion)
}
// EnrichWithMemoryInfo adds memory information to the diagnostics payload.
func (d *Diagnostics) EnrichWithMemoryInfo() {
memory, err := mem.VirtualMemory()
if err != nil {
d.logOutput.Write([]byte(err.Error()))
}
d.Set("MemFree", memory.Free)
d.Set("MemTotal", memory.Total)
d.Set("MemUsed", memory.Used)
}
// VersionSegments returns the numeric segments of the version as a slice of ints.
func VersionSegments(segments string) []int {
segments = strings.Trim(segments, "v")

View file

@ -581,6 +581,7 @@ func (s *Server) monitorDiagnostics() {
s.diagnostics.Set("NumCPU", runtime.NumCPU())
s.diagnostics.Set("LocalID", s.Holder.LocalID)
s.diagnostics.Set("ClusterID", s.ClusterID)
s.diagnostics.EnrichWithOSInfo()
// Flush the diagnostics metrics at startup, then on each tick interval
flush := func() {
@ -607,6 +608,7 @@ func (s *Server) monitorDiagnostics() {
s.diagnostics.Set("OpenFiles", openFiles)
}
s.diagnostics.Set("GoRoutines", runtime.NumGoroutine())
s.diagnostics.EnrichWithMemoryInfo()
s.diagnostics.CheckVersion()
s.diagnostics.Flush()
}