metrics.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (C) 2023 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 protocol
  7. import (
  8. "github.com/prometheus/client_golang/prometheus"
  9. "github.com/prometheus/client_golang/prometheus/promauto"
  10. )
  11. var (
  12. metricDeviceSentBytes = promauto.NewCounterVec(prometheus.CounterOpts{
  13. Namespace: "syncthing",
  14. Subsystem: "protocol",
  15. Name: "sent_bytes_total",
  16. Help: "Total amount of data sent, per device",
  17. }, []string{"device"})
  18. metricDeviceSentUncompressedBytes = promauto.NewCounterVec(prometheus.CounterOpts{
  19. Namespace: "syncthing",
  20. Subsystem: "protocol",
  21. Name: "sent_uncompressed_bytes_total",
  22. Help: "Total amount of data sent, before compression, per device",
  23. }, []string{"device"})
  24. metricDeviceSentMessages = promauto.NewCounterVec(prometheus.CounterOpts{
  25. Namespace: "syncthing",
  26. Subsystem: "protocol",
  27. Name: "sent_messages_total",
  28. Help: "Total number of messages sent, per device",
  29. }, []string{"device"})
  30. metricDeviceRecvBytes = promauto.NewCounterVec(prometheus.CounterOpts{
  31. Namespace: "syncthing",
  32. Subsystem: "protocol",
  33. Name: "recv_bytes_total",
  34. Help: "Total amount of data received, per device",
  35. }, []string{"device"})
  36. metricDeviceRecvDecompressedBytes = promauto.NewCounterVec(prometheus.CounterOpts{
  37. Namespace: "syncthing",
  38. Subsystem: "protocol",
  39. Name: "recv_decompressed_bytes_total",
  40. Help: "Total amount of data received, after decompression, per device",
  41. }, []string{"device"})
  42. metricDeviceRecvMessages = promauto.NewCounterVec(prometheus.CounterOpts{
  43. Namespace: "syncthing",
  44. Subsystem: "protocol",
  45. Name: "recv_messages_total",
  46. Help: "Total number of messages received, per device",
  47. }, []string{"device"})
  48. )
  49. func registerDeviceMetrics(deviceID string) {
  50. // Register metrics for this device, so that counters are present even
  51. // when zero.
  52. metricDeviceSentBytes.WithLabelValues(deviceID)
  53. metricDeviceSentUncompressedBytes.WithLabelValues(deviceID)
  54. metricDeviceSentMessages.WithLabelValues(deviceID)
  55. metricDeviceRecvBytes.WithLabelValues(deviceID)
  56. metricDeviceRecvMessages.WithLabelValues(deviceID)
  57. }