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.6 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package stats
  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. VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
  55. }
  56. func StartPushingMetric(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
  57. if intervalSeconds == 0 || addr == "" {
  58. glog.V(0).Info("disable metrics reporting")
  59. return
  60. }
  61. glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds)
  62. go loopPushMetrics(name, instance, gatherer, addr, intervalSeconds)
  63. }
  64. func loopPushMetrics(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
  65. pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  66. for {
  67. err := pusher.Push()
  68. if err != nil {
  69. glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
  70. }
  71. time.Sleep(time.Duration(intervalSeconds) * time.Second)
  72. }
  73. }