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.

34 lines
1.2 KiB

  1. package s3api
  2. import (
  3. "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"
  4. stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
  5. "github.com/seaweedfs/seaweedfs/weed/util"
  6. "net/http"
  7. "strconv"
  8. "time"
  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. }
  26. }
  27. func TimeToFirstByte(action string, start time.Time, r *http.Request) {
  28. bucket, _ := s3_constants.GetBucketAndObject(r)
  29. stats_collect.S3TimeToFirstByteHistogram.WithLabelValues(action, bucket).Observe(float64(time.Since(start).Milliseconds()))
  30. }