You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

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