From ee809b6083235d7ed5eacd3cb75c1067e2c57fa9 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Tue, 9 Apr 2019 12:08:30 +0300 Subject: [PATCH] new: exporting hardware resources usage from api.rest --- session/session_json.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/session/session_json.go b/session/session_json.go index 1f91b3ea..f1dd17e8 100644 --- a/session/session_json.go +++ b/session/session_json.go @@ -35,11 +35,21 @@ type ifaceJSON struct { Addresses []addrJSON `json:"addresses"` } +type resourcesJSON struct { + NumCPU int `json:"cpus"` + MaxCPU int `json:"max_cpus"` + NumGoroutine int `json:"goroutines"` + Alloc uint64 `json:"alloc"` + Sys uint64 `json:"sys"` + NumGC uint32 `json:"gcs"` +} + type SessionJSON struct { Version string `json:"version"` OS string `json:"os"` Arch string `json:"arch"` GoVersion string `json:"goversion"` + Resources resourcesJSON `json:"resources"` Interfaces []ifaceJSON `json:"interfaces"` Options core.Options `json:"options"` Interface *network.Endpoint `json:"interface"` @@ -59,11 +69,23 @@ type SessionJSON struct { } func (s *Session) MarshalJSON() ([]byte, error) { + var m runtime.MemStats + + runtime.ReadMemStats(&m) + doc := SessionJSON{ - Version: core.Version, - OS: runtime.GOOS, - Arch: runtime.GOARCH, - GoVersion: runtime.Version(), + Version: core.Version, + OS: runtime.GOOS, + Arch: runtime.GOARCH, + GoVersion: runtime.Version(), + Resources: resourcesJSON{ + NumCPU: runtime.NumCPU(), + MaxCPU: runtime.GOMAXPROCS(0), + NumGoroutine: runtime.NumGoroutine(), + Alloc: m.Alloc, + Sys: m.Sys, + NumGC: m.NumGC, + }, Interfaces: make([]ifaceJSON, 0), Options: s.Options, Interface: s.Interface,