Пример #1
0
func (m *RuntimeWare) logSnapshot(interval time.Duration) {
	c := time.Tick(interval)
	for _ = range c {
		log.Infof("[RuntimeWare] Snapshot server_lived=%s, hits_total=%s, hits_1m=%s, 4xx_5m=%s, hits_5xx=%s, num_goroutine=%s, latency=%s",
			time.Since(m.serverStarted),
			m.hitsTotal, m.hitsQps, m.hits4xx, m.hits5xx, m.numGoroutine, m.hitsServed)
	}
}
Пример #2
0
// Run the server listen and server at the addr with graceful shutdown supports.
func (s *Server) Run(addr string) error {
	timeout := kGracefulTimeout * time.Second
	if s.debug {
		timeout = 0
	}
	s.srv = &graceful.Server{
		Timeout: timeout,
		Server: &http.Server{
			Addr:    addr,
			Handler: s.router,
		},
	}
	log.Infof("Server is listening on %s", addr)
	return s.srv.ListenAndServe()
}
Пример #3
0
// ServeHTTP implements the Middleware interface. Would log all the access, status and performance information.
func (m *StatWare) ServeHTTP(ctx context.Context, w http.ResponseWriter, r *http.Request, next Handler) context.Context {
	start := time.Now()
	newCtx := next(ctx, w, r)
	res := w.(ResponseWriter)
	urlPath := r.URL.Path
	if res.Status() >= 400 {
		log.Warnf("Request %q %q, status=%v, size=%d, duration=%v",
			r.Method, r.URL.Path, res.Status(), res.Size(), time.Since(start))
	} else {
		ignored := false
		for _, prefix := range m.ignoredPrefixes {
			if strings.HasPrefix(urlPath, prefix) {
				ignored = true
				break
			}
		}
		if !ignored {
			log.Infof("Request %q %q, status=%v, size=%d, duration=%v",
				r.Method, r.URL.Path, res.Status(), res.Size(), time.Since(start))
		}
	}
	return newCtx
}