github.com/yandex/pandora@v0.5.32/cli/expvar.go (about) 1 package cli 2 3 import ( 4 "time" 5 6 "github.com/yandex/pandora/core/engine" 7 "github.com/yandex/pandora/lib/monitoring" 8 "go.uber.org/zap" 9 ) 10 11 func startReport(m engine.Metrics) { 12 evReqPS := monitoring.NewCounter("engine_ReqPS") 13 evResPS := monitoring.NewCounter("engine_ResPS") 14 evActiveUsers := monitoring.NewCounter("engine_ActiveUsers") 15 evActiveRequests := monitoring.NewCounter("engine_ActiveRequests") 16 evLastMaxActiveRequests := monitoring.NewCounter("engine_LastMaxActiveRequests") 17 requests := m.Request.Get() 18 responses := m.Response.Get() 19 go func() { 20 var requestsNew, responsesNew int64 21 // TODO(skipor): there is no guarantee, that we will run exactly after 1 second. 22 // So, when we get 1 sec +-10ms, we getting 990-1010 calculate intervals and +-2% RPS in reports. 23 // Consider using rcrowley/go-metrics.Meter. 24 for range time.NewTicker(1 * time.Second).C { 25 requestsNew = m.Request.Get() 26 responsesNew = m.Response.Get() 27 rps := responsesNew - responses 28 reqps := requestsNew - requests 29 activeUsers := m.InstanceStart.Get() - m.InstanceFinish.Get() 30 activeRequests := requestsNew - responsesNew 31 lastMaxActiveRequests := int64(m.BusyInstances.Flush()) 32 zap.S().Infof( 33 "[ENGINE] %d resp/s; %d req/s; %d users; %d active\n", 34 rps, reqps, activeUsers, lastMaxActiveRequests) 35 36 requests = requestsNew 37 responses = responsesNew 38 39 evActiveUsers.Set(activeUsers) 40 evActiveRequests.Set(activeRequests) 41 evLastMaxActiveRequests.Set(lastMaxActiveRequests) 42 evReqPS.Set(reqps) 43 evResPS.Set(rps) 44 } 45 }() 46 }