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.

124 lines
3.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
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. VolumeServerRequestCounter = prometheus.NewCounterVec(
  29. prometheus.CounterOpts{
  30. Namespace: "SeaweedFS",
  31. Subsystem: "volumeServer",
  32. Name: "request_total",
  33. Help: "Counter of filer requests.",
  34. }, []string{"type"})
  35. VolumeServerRequestHistogram = prometheus.NewHistogramVec(
  36. prometheus.HistogramOpts{
  37. Namespace: "SeaweedFS",
  38. Subsystem: "volumeServer",
  39. Name: "request_seconds",
  40. Help: "Bucketed histogram of filer request processing time.",
  41. Buckets: prometheus.ExponentialBuckets(0.0001, 2, 24),
  42. }, []string{"type"})
  43. VolumeServerVolumeCounter = prometheus.NewGauge(
  44. prometheus.GaugeOpts{
  45. Namespace: "SeaweedFS",
  46. Subsystem: "volumeServer",
  47. Name: "volumes",
  48. Help: "Number of volumes.",
  49. })
  50. VolumeServerEcShardCounter = prometheus.NewGauge(
  51. prometheus.GaugeOpts{
  52. Namespace: "SeaweedFS",
  53. Subsystem: "volumeServer",
  54. Name: "ecShards",
  55. Help: "Number of EC shards.",
  56. })
  57. VolumeServerVolumeSizeGauge = prometheus.NewGauge(
  58. prometheus.GaugeOpts{
  59. Namespace: "SeaweedFS",
  60. Subsystem: "volumeServer",
  61. Name: "totalVolumeSize",
  62. Help: "Actual disk size used by volumes.",
  63. })
  64. VolumeServerEcShardSizeGauge = prometheus.NewGauge(
  65. prometheus.GaugeOpts{
  66. Namespace: "SeaweedFS",
  67. Subsystem: "volumeServer",
  68. Name: "totalEcShardSize",
  69. Help: "Actual disk size used by ec shards.",
  70. })
  71. )
  72. func init() {
  73. FilerGather.MustRegister(FilerRequestCounter)
  74. FilerGather.MustRegister(FilerRequestHistogram)
  75. VolumeServerGather.MustRegister(VolumeServerRequestCounter)
  76. VolumeServerGather.MustRegister(VolumeServerRequestHistogram)
  77. VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
  78. VolumeServerGather.MustRegister(VolumeServerEcShardCounter)
  79. VolumeServerGather.MustRegister(VolumeServerVolumeSizeGauge)
  80. VolumeServerGather.MustRegister(VolumeServerEcShardSizeGauge)
  81. }
  82. func StartPushingMetric(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
  83. if intervalSeconds == 0 || addr == "" {
  84. glog.V(0).Info("disable metrics reporting")
  85. return
  86. }
  87. glog.V(0).Infof("push metrics to %s every %d seconds", addr, intervalSeconds)
  88. go loopPushMetrics(name, instance, gatherer, addr, intervalSeconds)
  89. }
  90. func loopPushMetrics(name, instance string, gatherer *prometheus.Registry, addr string, intervalSeconds int) {
  91. pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  92. for {
  93. err := pusher.Push()
  94. if err != nil {
  95. glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
  96. }
  97. time.Sleep(time.Duration(intervalSeconds) * time.Second)
  98. }
  99. }
  100. func SourceName(port int) string {
  101. hostname, err := os.Hostname()
  102. if err != nil {
  103. return "unknown"
  104. }
  105. return fmt.Sprintf("%s_%d", hostname, port)
  106. }