Beispiel #1
0
func (s *statsManager) runStatsDumpLogger() {
	for {
		stats := s.stats.Get()
		if stats != nil {
			bytes, _ := stats.MarshalJSON()
			logging.Infof("PeriodicStats = %s", string(bytes))
		}

		time.Sleep(time.Second * time.Duration(platform.LoadUint64(&s.statsLogDumpInterval)))
	}
}
Beispiel #2
0
func (s *statsManager) handleStatsReq(w http.ResponseWriter, r *http.Request) {
	sync := false
	if r.Method == "POST" || r.Method == "GET" {
		if r.URL.Query().Get("async") == "false" {
			sync = true
		}
		stats := s.stats.Get()
		t0 := time.Now()
		s.tryUpdateStats(sync)

		if stats == nil {
			w.WriteHeader(500)
			w.Write([]byte("Indexer not ready"))
		} else {
			bytes, _ := stats.MarshalJSON()
			w.WriteHeader(200)
			w.Write(bytes)
			stats.statsResponse.Put(time.Since(t0))
		}
	} else {
		w.WriteHeader(400)
		w.Write([]byte("Unsupported method"))
	}
}