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.

89 lines
2.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package weed_server
  2. import (
  3. "time"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/prometheus/client_golang/prometheus"
  6. "github.com/prometheus/client_golang/prometheus/push"
  7. )
  8. var (
  9. filerGather = prometheus.NewRegistry()
  10. volumeServerGather = prometheus.NewRegistry()
  11. filerRequestCounter = prometheus.NewCounterVec(
  12. prometheus.CounterOpts{
  13. Namespace: "SeaweedFS",
  14. Subsystem: "filer",
  15. Name: "request_total",
  16. Help: "Counter of filer requests.",
  17. }, []string{"type"})
  18. filerRequestHistogram = prometheus.NewHistogramVec(
  19. prometheus.HistogramOpts{
  20. Namespace: "SeaweedFS",
  21. Subsystem: "filer",
  22. Name: "request_seconds",
  23. Help: "Bucketed histogram of filer request processing time.",
  24. Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
  25. }, []string{"type"})
  26. volumeServerRequestCounter = prometheus.NewCounterVec(
  27. prometheus.CounterOpts{
  28. Namespace: "SeaweedFS",
  29. Subsystem: "volumeServer",
  30. Name: "request_total",
  31. Help: "Counter of filer requests.",
  32. }, []string{"type"})
  33. volumeServerRequestHistogram = prometheus.NewHistogramVec(
  34. prometheus.HistogramOpts{
  35. Namespace: "SeaweedFS",
  36. Subsystem: "volumeServer",
  37. Name: "request_seconds",
  38. Help: "Bucketed histogram of filer request processing time.",
  39. Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
  40. }, []string{"type"})
  41. volumeServerVolumeCounter = prometheus.NewGauge(
  42. prometheus.GaugeOpts{
  43. Namespace: "SeaweedFS",
  44. Subsystem: "volumeServer",
  45. Name: "volumes",
  46. Help: "Number of volumes.",
  47. })
  48. )
  49. func init() {
  50. filerGather.MustRegister(filerRequestCounter)
  51. filerGather.MustRegister(filerRequestHistogram)
  52. volumeServerGather.MustRegister(volumeServerRequestCounter)
  53. volumeServerGather.MustRegister(volumeServerRequestHistogram)
  54. }
  55. func startPushingMetric(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
  56. if intervalSeconds == 0 || addr == "" {
  57. glog.V(0).Info("disable metrics reporting")
  58. return
  59. }
  60. glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds)
  61. go loopPushMetrics(name, gatherer, addr, intervalSeconds)
  62. }
  63. func loopPushMetrics(name string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
  64. pusher := push.New(addr, name).Gatherer(gatherer)
  65. for {
  66. err := pusher.Push()
  67. if err != nil {
  68. glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
  69. }
  70. time.Sleep(time.Duration(intervalSeconds) * time.Second)
  71. }
  72. }