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.

140 lines
4.0 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 filer 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 filer 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. addr, intervalSeconds := fnGetMetricsDest()
  93. pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  94. currentAddr := addr
  95. for {
  96. if currentAddr != "" {
  97. err := pusher.Push()
  98. if err != nil {
  99. glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
  100. }
  101. }
  102. if intervalSeconds <= 0 {
  103. intervalSeconds = 15
  104. }
  105. time.Sleep(time.Duration(intervalSeconds) * time.Second)
  106. addr, intervalSeconds = fnGetMetricsDest()
  107. if currentAddr != addr {
  108. pusher = push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  109. currentAddr = addr
  110. }
  111. }
  112. }
  113. func SourceName(port int) string {
  114. hostname, err := os.Hostname()
  115. if err != nil {
  116. return "unknown"
  117. }
  118. return fmt.Sprintf("%s:%d", hostname, port)
  119. }