filer_server_handlers.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package weed_server
  2. import (
  3. "net/http"
  4. "time"
  5. "github.com/chrislusf/seaweedfs/weed/stats"
  6. )
  7. func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
  8. start := time.Now()
  9. switch r.Method {
  10. case "GET":
  11. stats.FilerRequestCounter.WithLabelValues("get").Inc()
  12. fs.GetOrHeadHandler(w, r, true)
  13. stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds())
  14. case "HEAD":
  15. stats.FilerRequestCounter.WithLabelValues("head").Inc()
  16. fs.GetOrHeadHandler(w, r, false)
  17. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  18. case "DELETE":
  19. stats.FilerRequestCounter.WithLabelValues("delete").Inc()
  20. fs.DeleteHandler(w, r)
  21. stats.FilerRequestHistogram.WithLabelValues("delete").Observe(time.Since(start).Seconds())
  22. case "PUT":
  23. stats.FilerRequestCounter.WithLabelValues("put").Inc()
  24. fs.PostHandler(w, r)
  25. stats.FilerRequestHistogram.WithLabelValues("put").Observe(time.Since(start).Seconds())
  26. case "POST":
  27. stats.FilerRequestCounter.WithLabelValues("post").Inc()
  28. fs.PostHandler(w, r)
  29. stats.FilerRequestHistogram.WithLabelValues("post").Observe(time.Since(start).Seconds())
  30. }
  31. }
  32. func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {
  33. start := time.Now()
  34. switch r.Method {
  35. case "GET":
  36. stats.FilerRequestCounter.WithLabelValues("get").Inc()
  37. fs.GetOrHeadHandler(w, r, true)
  38. stats.FilerRequestHistogram.WithLabelValues("get").Observe(time.Since(start).Seconds())
  39. case "HEAD":
  40. stats.FilerRequestCounter.WithLabelValues("head").Inc()
  41. fs.GetOrHeadHandler(w, r, false)
  42. stats.FilerRequestHistogram.WithLabelValues("head").Observe(time.Since(start).Seconds())
  43. }
  44. }