stats.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. )
  11. var (
  12. apiRequestsTotal = prometheus.NewCounterVec(
  13. prometheus.CounterOpts{
  14. Namespace: "syncthing",
  15. Subsystem: "discovery",
  16. Name: "api_requests_total",
  17. Help: "Number of API requests.",
  18. }, []string{"type", "result"})
  19. apiRequestsSeconds = prometheus.NewSummaryVec(
  20. prometheus.SummaryOpts{
  21. Namespace: "syncthing",
  22. Subsystem: "discovery",
  23. Name: "api_requests_seconds",
  24. Help: "Latency of API requests.",
  25. Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
  26. }, []string{"type"})
  27. lookupRequestsTotal = prometheus.NewCounterVec(
  28. prometheus.CounterOpts{
  29. Namespace: "syncthing",
  30. Subsystem: "discovery",
  31. Name: "lookup_requests_total",
  32. Help: "Number of lookup requests.",
  33. }, []string{"result"})
  34. announceRequestsTotal = prometheus.NewCounterVec(
  35. prometheus.CounterOpts{
  36. Namespace: "syncthing",
  37. Subsystem: "discovery",
  38. Name: "announcement_requests_total",
  39. Help: "Number of announcement requests.",
  40. }, []string{"result"})
  41. replicationSendsTotal = prometheus.NewCounterVec(
  42. prometheus.CounterOpts{
  43. Namespace: "syncthing",
  44. Subsystem: "discovery",
  45. Name: "replication_sends_total",
  46. Help: "Number of replication sends.",
  47. }, []string{"result"})
  48. replicationRecvsTotal = prometheus.NewCounterVec(
  49. prometheus.CounterOpts{
  50. Namespace: "syncthing",
  51. Subsystem: "discovery",
  52. Name: "replication_recvs_total",
  53. Help: "Number of replication receives.",
  54. }, []string{"result"})
  55. databaseKeys = prometheus.NewGaugeVec(
  56. prometheus.GaugeOpts{
  57. Namespace: "syncthing",
  58. Subsystem: "discovery",
  59. Name: "database_keys",
  60. Help: "Number of database keys at last count.",
  61. }, []string{"category"})
  62. databaseStatisticsSeconds = prometheus.NewGauge(
  63. prometheus.GaugeOpts{
  64. Namespace: "syncthing",
  65. Subsystem: "discovery",
  66. Name: "database_statistics_seconds",
  67. Help: "Time spent running the statistics routine.",
  68. })
  69. databaseOperations = prometheus.NewCounterVec(
  70. prometheus.CounterOpts{
  71. Namespace: "syncthing",
  72. Subsystem: "discovery",
  73. Name: "database_operations_total",
  74. Help: "Number of database operations.",
  75. }, []string{"operation", "result"})
  76. databaseOperationSeconds = prometheus.NewSummaryVec(
  77. prometheus.SummaryOpts{
  78. Namespace: "syncthing",
  79. Subsystem: "discovery",
  80. Name: "database_operation_seconds",
  81. Help: "Latency of database operations.",
  82. Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
  83. }, []string{"operation"})
  84. )
  85. const (
  86. dbOpGet = "get"
  87. dbOpPut = "put"
  88. dbOpMerge = "merge"
  89. dbOpDelete = "delete"
  90. dbResSuccess = "success"
  91. dbResNotFound = "not_found"
  92. dbResError = "error"
  93. dbResUnmarshalError = "unmarsh_err"
  94. )
  95. func init() {
  96. prometheus.MustRegister(apiRequestsTotal, apiRequestsSeconds,
  97. lookupRequestsTotal, announceRequestsTotal,
  98. replicationSendsTotal, replicationRecvsTotal,
  99. databaseKeys, databaseStatisticsSeconds,
  100. databaseOperations, databaseOperationSeconds)
  101. processCollectorOpts := prometheus.ProcessCollectorOpts{
  102. Namespace: "syncthing_discovery",
  103. PidFn: func() (int, error) {
  104. return os.Getpid(), nil
  105. },
  106. }
  107. prometheus.MustRegister(
  108. prometheus.NewProcessCollector(processCollectorOpts),
  109. )
  110. }