stats.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2018 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package main
  7. import (
  8. "os"
  9. "github.com/prometheus/client_golang/prometheus"
  10. "github.com/prometheus/client_golang/prometheus/collectors"
  11. )
  12. var (
  13. apiRequestsTotal = prometheus.NewCounterVec(
  14. prometheus.CounterOpts{
  15. Namespace: "syncthing",
  16. Subsystem: "discovery",
  17. Name: "api_requests_total",
  18. Help: "Number of API requests.",
  19. }, []string{"type", "result"})
  20. apiRequestsSeconds = prometheus.NewSummaryVec(
  21. prometheus.SummaryOpts{
  22. Namespace: "syncthing",
  23. Subsystem: "discovery",
  24. Name: "api_requests_seconds",
  25. Help: "Latency of API requests.",
  26. Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
  27. }, []string{"type"})
  28. lookupRequestsTotal = prometheus.NewCounterVec(
  29. prometheus.CounterOpts{
  30. Namespace: "syncthing",
  31. Subsystem: "discovery",
  32. Name: "lookup_requests_total",
  33. Help: "Number of lookup requests.",
  34. }, []string{"result"})
  35. announceRequestsTotal = prometheus.NewCounterVec(
  36. prometheus.CounterOpts{
  37. Namespace: "syncthing",
  38. Subsystem: "discovery",
  39. Name: "announcement_requests_total",
  40. Help: "Number of announcement requests.",
  41. }, []string{"result"})
  42. replicationSendsTotal = prometheus.NewCounterVec(
  43. prometheus.CounterOpts{
  44. Namespace: "syncthing",
  45. Subsystem: "discovery",
  46. Name: "replication_sends_total",
  47. Help: "Number of replication sends.",
  48. }, []string{"result"})
  49. replicationRecvsTotal = prometheus.NewCounterVec(
  50. prometheus.CounterOpts{
  51. Namespace: "syncthing",
  52. Subsystem: "discovery",
  53. Name: "replication_recvs_total",
  54. Help: "Number of replication receives.",
  55. }, []string{"result"})
  56. databaseKeys = prometheus.NewGaugeVec(
  57. prometheus.GaugeOpts{
  58. Namespace: "syncthing",
  59. Subsystem: "discovery",
  60. Name: "database_keys",
  61. Help: "Number of database keys at last count.",
  62. }, []string{"category"})
  63. databaseStatisticsSeconds = prometheus.NewGauge(
  64. prometheus.GaugeOpts{
  65. Namespace: "syncthing",
  66. Subsystem: "discovery",
  67. Name: "database_statistics_seconds",
  68. Help: "Time spent running the statistics routine.",
  69. })
  70. databaseOperations = prometheus.NewCounterVec(
  71. prometheus.CounterOpts{
  72. Namespace: "syncthing",
  73. Subsystem: "discovery",
  74. Name: "database_operations_total",
  75. Help: "Number of database operations.",
  76. }, []string{"operation", "result"})
  77. databaseOperationSeconds = prometheus.NewSummaryVec(
  78. prometheus.SummaryOpts{
  79. Namespace: "syncthing",
  80. Subsystem: "discovery",
  81. Name: "database_operation_seconds",
  82. Help: "Latency of database operations.",
  83. Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
  84. }, []string{"operation"})
  85. )
  86. const (
  87. dbOpGet = "get"
  88. dbOpPut = "put"
  89. dbOpMerge = "merge"
  90. dbOpDelete = "delete"
  91. dbResSuccess = "success"
  92. dbResNotFound = "not_found"
  93. dbResError = "error"
  94. dbResUnmarshalError = "unmarsh_err"
  95. )
  96. func init() {
  97. prometheus.MustRegister(apiRequestsTotal, apiRequestsSeconds,
  98. lookupRequestsTotal, announceRequestsTotal,
  99. replicationSendsTotal, replicationRecvsTotal,
  100. databaseKeys, databaseStatisticsSeconds,
  101. databaseOperations, databaseOperationSeconds)
  102. processCollectorOpts := collectors.ProcessCollectorOpts{
  103. Namespace: "syncthing_discovery",
  104. PidFn: func() (int, error) {
  105. return os.Getpid(), nil
  106. },
  107. }
  108. prometheus.MustRegister(
  109. collectors.NewProcessCollector(processCollectorOpts),
  110. )
  111. }