stats.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. "github.com/prometheus/client_golang/prometheus"
  9. )
  10. var (
  11. buildInfo = prometheus.NewGaugeVec(
  12. prometheus.GaugeOpts{
  13. Namespace: "syncthing",
  14. Subsystem: "discovery",
  15. Name: "build_info",
  16. Help: "A metric with a constant '1' value labeled by version, goversion, builduser and builddate from which stdiscosrv was built.",
  17. }, []string{"version", "goversion", "builduser", "builddate"})
  18. apiRequestsTotal = prometheus.NewCounterVec(
  19. prometheus.CounterOpts{
  20. Namespace: "syncthing",
  21. Subsystem: "discovery",
  22. Name: "api_requests_total",
  23. Help: "Number of API requests.",
  24. }, []string{"type", "result"})
  25. apiRequestsSeconds = prometheus.NewSummaryVec(
  26. prometheus.SummaryOpts{
  27. Namespace: "syncthing",
  28. Subsystem: "discovery",
  29. Name: "api_requests_seconds",
  30. Help: "Latency of API requests.",
  31. Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
  32. }, []string{"type"})
  33. lookupRequestsTotal = prometheus.NewCounterVec(
  34. prometheus.CounterOpts{
  35. Namespace: "syncthing",
  36. Subsystem: "discovery",
  37. Name: "lookup_requests_total",
  38. Help: "Number of lookup requests.",
  39. }, []string{"result"})
  40. announceRequestsTotal = prometheus.NewCounterVec(
  41. prometheus.CounterOpts{
  42. Namespace: "syncthing",
  43. Subsystem: "discovery",
  44. Name: "announcement_requests_total",
  45. Help: "Number of announcement requests.",
  46. }, []string{"result"})
  47. replicationSendsTotal = prometheus.NewCounterVec(
  48. prometheus.CounterOpts{
  49. Namespace: "syncthing",
  50. Subsystem: "discovery",
  51. Name: "replication_sends_total",
  52. Help: "Number of replication sends.",
  53. }, []string{"result"})
  54. replicationRecvsTotal = prometheus.NewCounterVec(
  55. prometheus.CounterOpts{
  56. Namespace: "syncthing",
  57. Subsystem: "discovery",
  58. Name: "replication_recvs_total",
  59. Help: "Number of replication receives.",
  60. }, []string{"result"})
  61. databaseKeys = prometheus.NewGaugeVec(
  62. prometheus.GaugeOpts{
  63. Namespace: "syncthing",
  64. Subsystem: "discovery",
  65. Name: "database_keys",
  66. Help: "Number of database keys at last count.",
  67. }, []string{"category"})
  68. databaseStatisticsSeconds = prometheus.NewGauge(
  69. prometheus.GaugeOpts{
  70. Namespace: "syncthing",
  71. Subsystem: "discovery",
  72. Name: "database_statistics_seconds",
  73. Help: "Time spent running the statistics routine.",
  74. })
  75. databaseOperations = prometheus.NewCounterVec(
  76. prometheus.CounterOpts{
  77. Namespace: "syncthing",
  78. Subsystem: "discovery",
  79. Name: "database_operations_total",
  80. Help: "Number of database operations.",
  81. }, []string{"operation", "result"})
  82. databaseOperationSeconds = prometheus.NewSummaryVec(
  83. prometheus.SummaryOpts{
  84. Namespace: "syncthing",
  85. Subsystem: "discovery",
  86. Name: "database_operation_seconds",
  87. Help: "Latency of database operations.",
  88. Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
  89. }, []string{"operation"})
  90. databaseWriteSeconds = prometheus.NewGauge(
  91. prometheus.GaugeOpts{
  92. Namespace: "syncthing",
  93. Subsystem: "discovery",
  94. Name: "database_write_seconds",
  95. Help: "Time spent writing the database.",
  96. })
  97. databaseLastWritten = prometheus.NewGauge(
  98. prometheus.GaugeOpts{
  99. Namespace: "syncthing",
  100. Subsystem: "discovery",
  101. Name: "database_last_written",
  102. Help: "Timestamp of the last successful database write.",
  103. })
  104. retryAfterLevel = prometheus.NewGaugeVec(
  105. prometheus.GaugeOpts{
  106. Namespace: "syncthing",
  107. Subsystem: "discovery",
  108. Name: "retry_after_seconds",
  109. Help: "Retry-After header value in seconds.",
  110. }, []string{"name"})
  111. )
  112. const (
  113. dbOpGet = "get"
  114. dbOpPut = "put"
  115. dbOpMerge = "merge"
  116. dbOpDelete = "delete"
  117. dbResSuccess = "success"
  118. dbResNotFound = "not_found"
  119. dbResError = "error"
  120. dbResUnmarshalError = "unmarsh_err"
  121. )
  122. func init() {
  123. prometheus.MustRegister(buildInfo,
  124. apiRequestsTotal, apiRequestsSeconds,
  125. lookupRequestsTotal, announceRequestsTotal,
  126. replicationSendsTotal, replicationRecvsTotal,
  127. databaseKeys, databaseStatisticsSeconds,
  128. databaseOperations, databaseOperationSeconds,
  129. databaseWriteSeconds, databaseLastWritten,
  130. retryAfterLevel)
  131. }