metrics.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 model
  7. import (
  8. "github.com/prometheus/client_golang/prometheus"
  9. "github.com/prometheus/client_golang/prometheus/promauto"
  10. )
  11. var (
  12. metricFolderState = promauto.NewGaugeVec(prometheus.GaugeOpts{
  13. Namespace: "syncthing",
  14. Subsystem: "model",
  15. Name: "folder_state",
  16. Help: "Current folder state",
  17. }, []string{"folder"})
  18. metricFolderSummary = promauto.NewGaugeVec(prometheus.GaugeOpts{ //nolint:promlinter
  19. Namespace: "syncthing",
  20. Subsystem: "model",
  21. Name: "folder_summary",
  22. Help: "Current folder summary data (counts for global/local/need files/directories/symlinks/deleted/bytes)",
  23. }, []string{"folder", "scope", "type"})
  24. metricFolderPulls = promauto.NewCounterVec(prometheus.CounterOpts{
  25. Namespace: "syncthing",
  26. Subsystem: "model",
  27. Name: "folder_pulls_total",
  28. Help: "Total number of folder pull iterations, per folder ID",
  29. }, []string{"folder"})
  30. metricFolderPullSeconds = promauto.NewCounterVec(prometheus.CounterOpts{
  31. Namespace: "syncthing",
  32. Subsystem: "model",
  33. Name: "folder_pull_seconds_total",
  34. Help: "Total time spent in folder pull iterations, per folder ID",
  35. }, []string{"folder"})
  36. metricFolderScans = promauto.NewCounterVec(prometheus.CounterOpts{
  37. Namespace: "syncthing",
  38. Subsystem: "model",
  39. Name: "folder_scans_total",
  40. Help: "Total number of folder scan iterations, per folder ID",
  41. }, []string{"folder"})
  42. metricFolderScanSeconds = promauto.NewCounterVec(prometheus.CounterOpts{
  43. Namespace: "syncthing",
  44. Subsystem: "model",
  45. Name: "folder_scan_seconds_total",
  46. Help: "Total time spent in folder scan iterations, per folder ID",
  47. }, []string{"folder"})
  48. metricFolderProcessedBytesTotal = promauto.NewCounterVec(prometheus.CounterOpts{
  49. Namespace: "syncthing",
  50. Subsystem: "model",
  51. Name: "folder_processed_bytes_total",
  52. Help: "Total amount of data processed during folder syncing, per folder ID and data source (network/local_origin/local_other/skipped)",
  53. }, []string{"folder", "source"})
  54. metricFolderConflictsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
  55. Namespace: "syncthing",
  56. Subsystem: "model",
  57. Name: "folder_conflicts_total",
  58. Help: "Total number of conflicts",
  59. }, []string{"folder"})
  60. )
  61. const (
  62. metricSourceNetwork = "network" // from the network
  63. metricSourceLocalOrigin = "local_origin" // from the existing version of the local file
  64. metricSourceLocalOther = "local_other" // from a different local file
  65. metricSourceSkipped = "skipped" // block of all zeroes, invented out of thin air
  66. metricScopeGlobal = "global"
  67. metricScopeLocal = "local"
  68. metricScopeNeed = "need"
  69. metricTypeFiles = "files"
  70. metricTypeDirectories = "directories"
  71. metricTypeSymlinks = "symlinks"
  72. metricTypeDeleted = "deleted"
  73. metricTypeBytes = "bytes"
  74. )
  75. func registerFolderMetrics(folderID string) {
  76. // Register metrics for this folder, so that counters are present even
  77. // when zero.
  78. metricFolderState.WithLabelValues(folderID)
  79. metricFolderPulls.WithLabelValues(folderID)
  80. metricFolderPullSeconds.WithLabelValues(folderID)
  81. metricFolderScans.WithLabelValues(folderID)
  82. metricFolderScanSeconds.WithLabelValues(folderID)
  83. metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceNetwork)
  84. metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceLocalOrigin)
  85. metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceLocalOther)
  86. metricFolderProcessedBytesTotal.WithLabelValues(folderID, metricSourceSkipped)
  87. metricFolderConflictsTotal.WithLabelValues(folderID)
  88. }