stats.go 1008 B

1234567891011121314151617181920212223242526272829
  1. package s3api
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
  4. stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
  5. "net/http"
  6. "strconv"
  7. "time"
  8. )
  9. func track(f http.HandlerFunc, action string) http.HandlerFunc {
  10. return func(w http.ResponseWriter, r *http.Request) {
  11. bucket, _ := s3_constants.GetBucketAndObject(r)
  12. w.Header().Set("Server", "SeaweedFS S3")
  13. recorder := stats_collect.NewStatusResponseWriter(w)
  14. start := time.Now()
  15. f(recorder, r)
  16. if recorder.Status == http.StatusForbidden {
  17. bucket = ""
  18. }
  19. stats_collect.S3RequestHistogram.WithLabelValues(action, bucket).Observe(time.Since(start).Seconds())
  20. stats_collect.S3RequestCounter.WithLabelValues(action, strconv.Itoa(recorder.Status), bucket).Inc()
  21. }
  22. }
  23. func TimeToFirstByte(action string, start time.Time, r *http.Request) {
  24. bucket, _ := s3_constants.GetBucketAndObject(r)
  25. stats_collect.S3TimeToFirstByteHistogram.WithLabelValues(action, bucket).Observe(float64(time.Since(start).Milliseconds()))
  26. }