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.

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