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.

144 lines
4.1 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
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. package stats
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/prometheus/client_golang/prometheus"
  8. "github.com/prometheus/client_golang/prometheus/push"
  9. )
  10. var (
  11. FilerGather = prometheus.NewRegistry()
  12. VolumeServerGather = prometheus.NewRegistry()
  13. FilerRequestCounter = prometheus.NewCounterVec(
  14. prometheus.CounterOpts{
  15. Namespace: "SeaweedFS",
  16. Subsystem: "filer",
  17. Name: "request_total",
  18. Help: "Counter of filer requests.",
  19. }, []string{"type"})
  20. FilerRequestHistogram = prometheus.NewHistogramVec(
  21. prometheus.HistogramOpts{
  22. Namespace: "SeaweedFS",
  23. Subsystem: "filer",
  24. Name: "request_seconds",
  25. Help: "Bucketed histogram of filer request processing time.",
  26. Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
  27. }, []string{"type"})
  28. FilerStoreCounter = prometheus.NewCounterVec(
  29. prometheus.CounterOpts{
  30. Namespace: "SeaweedFS",
  31. Subsystem: "filerStore",
  32. Name: "request_total",
  33. Help: "Counter of filer store requests.",
  34. }, []string{"store", "type"})
  35. FilerStoreHistogram = prometheus.NewHistogramVec(
  36. prometheus.HistogramOpts{
  37. Namespace: "SeaweedFS",
  38. Subsystem: "filerStore",
  39. Name: "request_seconds",
  40. Help: "Bucketed histogram of filer store request processing time.",
  41. Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
  42. }, []string{"store", "type"})
  43. VolumeServerRequestCounter = prometheus.NewCounterVec(
  44. prometheus.CounterOpts{
  45. Namespace: "SeaweedFS",
  46. Subsystem: "volumeServer",
  47. Name: "request_total",
  48. Help: "Counter of volume server requests.",
  49. }, []string{"type"})
  50. VolumeServerRequestHistogram = prometheus.NewHistogramVec(
  51. prometheus.HistogramOpts{
  52. Namespace: "SeaweedFS",
  53. Subsystem: "volumeServer",
  54. Name: "request_seconds",
  55. Help: "Bucketed histogram of volume server request processing time.",
  56. Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
  57. }, []string{"type"})
  58. VolumeServerVolumeCounter = prometheus.NewGaugeVec(
  59. prometheus.GaugeOpts{
  60. Namespace: "SeaweedFS",
  61. Subsystem: "volumeServer",
  62. Name: "volumes",
  63. Help: "Number of volumes or shards.",
  64. }, []string{"collection", "type"})
  65. VolumeServerMaxVolumeCounter = prometheus.NewGauge(
  66. prometheus.GaugeOpts{
  67. Namespace: "SeaweedFS",
  68. Subsystem: "volumeServer",
  69. Name: "max_volumes",
  70. Help: "Maximum number of volumes.",
  71. })
  72. VolumeServerDiskSizeGauge = prometheus.NewGaugeVec(
  73. prometheus.GaugeOpts{
  74. Namespace: "SeaweedFS",
  75. Subsystem: "volumeServer",
  76. Name: "total_disk_size",
  77. Help: "Actual disk size used by volumes.",
  78. }, []string{"collection", "type"})
  79. )
  80. func init() {
  81. FilerGather.MustRegister(FilerRequestCounter)
  82. FilerGather.MustRegister(FilerRequestHistogram)
  83. FilerGather.MustRegister(FilerStoreCounter)
  84. FilerGather.MustRegister(FilerStoreHistogram)
  85. VolumeServerGather.MustRegister(VolumeServerRequestCounter)
  86. VolumeServerGather.MustRegister(VolumeServerRequestHistogram)
  87. VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
  88. VolumeServerGather.MustRegister(VolumeServerMaxVolumeCounter)
  89. VolumeServerGather.MustRegister(VolumeServerDiskSizeGauge)
  90. }
  91. func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, fnGetMetricsDest func() (addr string, intervalSeconds int)) {
  92. if fnGetMetricsDest == nil {
  93. return
  94. }
  95. addr, intervalSeconds := fnGetMetricsDest()
  96. pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  97. currentAddr := addr
  98. for {
  99. if currentAddr != "" {
  100. err := pusher.Push()
  101. if err != nil {
  102. glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
  103. }
  104. }
  105. if intervalSeconds <= 0 {
  106. intervalSeconds = 15
  107. }
  108. time.Sleep(time.Duration(intervalSeconds) * time.Second)
  109. addr, intervalSeconds = fnGetMetricsDest()
  110. if currentAddr != addr {
  111. pusher = push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  112. currentAddr = addr
  113. }
  114. }
  115. }
  116. func SourceName(port int) string {
  117. hostname, err := os.Hostname()
  118. if err != nil {
  119. return "unknown"
  120. }
  121. return fmt.Sprintf("%s:%d", hostname, port)
  122. }