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.

121 lines
3.4 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. 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.NewGaugeVec(
  44. prometheus.GaugeOpts{
  45. Namespace: "SeaweedFS",
  46. Subsystem: "volumeServer",
  47. Name: "volumes",
  48. Help: "Number of volumes or shards.",
  49. }, []string{"collection", "type"})
  50. VolumeServerMaxVolumeCounter = prometheus.NewGauge(
  51. prometheus.GaugeOpts{
  52. Namespace: "SeaweedFS",
  53. Subsystem: "volumeServer",
  54. Name: "max_volumes",
  55. Help: "Maximum number of volumes.",
  56. })
  57. VolumeServerDiskSizeGauge = prometheus.NewGaugeVec(
  58. prometheus.GaugeOpts{
  59. Namespace: "SeaweedFS",
  60. Subsystem: "volumeServer",
  61. Name: "total_disk_size",
  62. Help: "Actual disk size used by volumes.",
  63. }, []string{"collection", "type"})
  64. )
  65. func init() {
  66. FilerGather.MustRegister(FilerRequestCounter)
  67. FilerGather.MustRegister(FilerRequestHistogram)
  68. VolumeServerGather.MustRegister(VolumeServerRequestCounter)
  69. VolumeServerGather.MustRegister(VolumeServerRequestHistogram)
  70. VolumeServerGather.MustRegister(VolumeServerVolumeCounter)
  71. VolumeServerGather.MustRegister(VolumeServerMaxVolumeCounter)
  72. VolumeServerGather.MustRegister(VolumeServerDiskSizeGauge)
  73. }
  74. func LoopPushingMetric(name, instance string, gatherer *prometheus.Registry, fnGetMetricsDest func() (addr string, intervalSeconds int)) {
  75. addr, intervalSeconds := fnGetMetricsDest()
  76. pusher := push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  77. currentAddr := addr
  78. for {
  79. if currentAddr != "" {
  80. err := pusher.Push()
  81. if err != nil {
  82. glog.V(0).Infof("could not push metrics to prometheus push gateway %s: %v", addr, err)
  83. }
  84. }
  85. if intervalSeconds <= 0 {
  86. intervalSeconds = 15
  87. }
  88. time.Sleep(time.Duration(intervalSeconds) * time.Second)
  89. addr, intervalSeconds = fnGetMetricsDest()
  90. if currentAddr != addr {
  91. pusher = push.New(addr, name).Gatherer(gatherer).Grouping("instance", instance)
  92. currentAddr = addr
  93. }
  94. }
  95. }
  96. func SourceName(port int) string {
  97. hostname, err := os.Hostname()
  98. if err != nil {
  99. return "unknown"
  100. }
  101. return fmt.Sprintf("%s:%d", hostname, port)
  102. }