From 2830fb46e603823628b8fd404dbde7895979cdd1 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Mon, 1 Oct 2018 15:31:13 +0300 Subject: [PATCH] Adds diagnostics CPUArch field --- diagnostics.go | 11 +++++++++++ gopsutil/systeminfo.go | 7 +++++++ gopsutil/systeminfo_test.go | 16 +++++----------- server.go | 1 + 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/diagnostics.go b/diagnostics.go index cad7725d7..673fb0c7f 100644 --- a/diagnostics.go +++ b/diagnostics.go @@ -174,6 +174,11 @@ func (d *diagnosticsCollector) logErr(err error) bool { return false } +// EnrichWithCPUInfo adds CPU information to the diagnostics payload. +func (d *diagnosticsCollector) EnrichWithCPUInfo() { + d.Set("CPUArch", d.server.systemInfo.CPUArch()) +} + // EnrichWithOSInfo adds OS information to the diagnostics payload. func (d *diagnosticsCollector) EnrichWithOSInfo() { uptime, err := d.server.systemInfo.Uptime() @@ -265,6 +270,7 @@ type SystemInfo interface { MemFree() (uint64, error) MemTotal() (uint64, error) MemUsed() (uint64, error) + CPUArch() string } // newNopSystemInfo creates a no-op implementation of SystemInfo. @@ -315,3 +321,8 @@ func (n *nopSystemInfo) MemTotal() (uint64, error) { func (n *nopSystemInfo) MemUsed() (uint64, error) { return 0, nil } + +// CPUArch returns the CPU architecture, such as amd64 +func (n *nopSystemInfo) CPUArch() string { + return "" +} diff --git a/gopsutil/systeminfo.go b/gopsutil/systeminfo.go index 8cdd77778..290e1278c 100644 --- a/gopsutil/systeminfo.go +++ b/gopsutil/systeminfo.go @@ -15,6 +15,8 @@ package gopsutil import ( + "runtime" + "github.com/pilosa/pilosa" "github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/mem" @@ -109,6 +111,11 @@ func (s *systemInfo) KernelVersion() (string, error) { return host.KernelVersion() } +// CPUArch returns the CPU architecture, such as amd64 +func (s *systemInfo) CPUArch() string { + return runtime.GOARCH +} + // NewSystemInfo is a constructor for the gopsutil implementation of SystemInfo. func NewSystemInfo() *systemInfo { return &systemInfo{} diff --git a/gopsutil/systeminfo_test.go b/gopsutil/systeminfo_test.go index 0f76b62da..28d09e66a 100644 --- a/gopsutil/systeminfo_test.go +++ b/gopsutil/systeminfo_test.go @@ -15,7 +15,6 @@ package gopsutil_test import ( - "log" "testing" "github.com/pilosa/pilosa" @@ -25,15 +24,6 @@ import ( func TestSystemInfo(t *testing.T) { var systemInfo pilosa.SystemInfo = gopsutil.NewSystemInfo() - // Uptime()(uint64, error) - // Platform()(string, error) - // Family()(string, error) - // OSVersion()(string, error) - // KernelVersion()(string, error) - // MemFree()(uint64, error) - // MemTotal()(uint64, error) - // MemUsed()(uint64, error) - // uptime, err := systemInfo.Uptime() if err != nil || uptime == 0 { t.Fatalf("Error collecting uptime (error: %v)", err) @@ -70,8 +60,12 @@ func TestSystemInfo(t *testing.T) { } memtotal, err := systemInfo.MemTotal() - log.Println(memtotal) if err != nil { t.Fatalf("Error getting memtotal. (memtotal: %v, error: %v)", memtotal, err) } + + cpuArch := systemInfo.CPUArch() + if cpuArch == "" { + t.Fatalf("Error getting CPU arch.") + } } diff --git a/server.go b/server.go index 61e4838a1..3bb3ce1b2 100644 --- a/server.go +++ b/server.go @@ -675,6 +675,7 @@ func (s *Server) monitorDiagnostics() { s.diagnostics.Set("NumCPU", runtime.NumCPU()) s.diagnostics.Set("NodeID", s.nodeID) s.diagnostics.Set("ClusterID", s.cluster.id) + s.diagnostics.EnrichWithCPUInfo() s.diagnostics.EnrichWithOSInfo() // Flush the diagnostics metrics at startup, then on each tick interval