added more stats fields

This commit is contained in:
hyung-hwan 2024-12-08 17:40:15 +09:00
parent ebfc4010e7
commit 29180a7969
2 changed files with 24 additions and 0 deletions

View File

@ -71,6 +71,12 @@ type json_out_client_peer struct {
type json_out_client_stats struct { type json_out_client_stats struct {
CPUs int `json:"cpus"` CPUs int `json:"cpus"`
Goroutines int `json:"goroutines"` Goroutines int `json:"goroutines"`
NumGCs uint32 `json:"num-gcs"`
HeapAllocBytes uint64 `json:"memory-alloc-bytes"`
MemAllocs uint64 `json:"memory-num-allocs"`
MemFrees uint64 `json:"memory-num-frees"`
ClientConns int64 `json:"client-conns"` ClientConns int64 `json:"client-conns"`
ClientRoutes int64 `json:"client-routes"` ClientRoutes int64 `json:"client-routes"`
ClientPeers int64 `json:"client-peers"` ClientPeers int64 `json:"client-peers"`
@ -657,8 +663,14 @@ func (ctl *client_ctl_stats) ServeHTTP(w http.ResponseWriter, req *http.Request)
switch req.Method { switch req.Method {
case http.MethodGet: case http.MethodGet:
var stats json_out_client_stats var stats json_out_client_stats
var mstat runtime.MemStats
runtime.ReadMemStats(&mstat)
stats.CPUs = runtime.NumCPU() stats.CPUs = runtime.NumCPU()
stats.Goroutines = runtime.NumGoroutine() stats.Goroutines = runtime.NumGoroutine()
stats.NumGCs = mstat.NumGC
stats.HeapAllocBytes = mstat.HeapAlloc
stats.MemAllocs = mstat.Mallocs
stats.MemFrees = mstat.Frees
stats.ClientConns = c.stats.conns.Load() stats.ClientConns = c.stats.conns.Load()
stats.ClientRoutes = c.stats.routes.Load() stats.ClientRoutes = c.stats.routes.Load()
stats.ClientPeers = c.stats.peers.Load() stats.ClientPeers = c.stats.peers.Load()

View File

@ -23,6 +23,12 @@ type json_out_server_route struct {
type json_out_server_stats struct { type json_out_server_stats struct {
CPUs int `json:"cpus"` CPUs int `json:"cpus"`
Goroutines int `json:"goroutines"` Goroutines int `json:"goroutines"`
NumGCs uint32 `json:"num-gcs"`
HeapAllocBytes uint64 `json:"memory-alloc-bytes"`
MemAllocs uint64 `json:"memory-num-allocs"`
MemFrees uint64 `json:"memory-num-frees"`
ServerConns int64 `json:"server-conns"` ServerConns int64 `json:"server-conns"`
ServerRoutes int64 `json:"server-routes"` ServerRoutes int64 `json:"server-routes"`
ServerPeers int64 `json:"server-peers"` ServerPeers int64 `json:"server-peers"`
@ -235,8 +241,14 @@ func (ctl *server_ctl_stats) ServeHTTP(w http.ResponseWriter, req *http.Request)
switch req.Method { switch req.Method {
case http.MethodGet: case http.MethodGet:
var stats json_out_server_stats var stats json_out_server_stats
var mstat runtime.MemStats
runtime.ReadMemStats(&mstat)
stats.CPUs = runtime.NumCPU() stats.CPUs = runtime.NumCPU()
stats.Goroutines = runtime.NumGoroutine() stats.Goroutines = runtime.NumGoroutine()
stats.NumGCs = mstat.NumGC
stats.HeapAllocBytes = mstat.HeapAlloc
stats.MemAllocs = mstat.Mallocs
stats.MemFrees = mstat.Frees
stats.ServerConns = s.stats.conns.Load() stats.ServerConns = s.stats.conns.Load()
stats.ServerRoutes = s.stats.routes.Load() stats.ServerRoutes = s.stats.routes.Load()
stats.ServerPeers = s.stats.peers.Load() stats.ServerPeers = s.stats.peers.Load()