metrics.go 892 B

12345678910111213141516171819202122232425262728
  1. // Copyright (C) 2024 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 connections
  7. import (
  8. "github.com/prometheus/client_golang/prometheus"
  9. "github.com/prometheus/client_golang/prometheus/promauto"
  10. )
  11. var (
  12. metricDeviceActiveConnections = promauto.NewGaugeVec(prometheus.GaugeOpts{
  13. Namespace: "syncthing",
  14. Subsystem: "connections",
  15. Name: "active",
  16. Help: "Number of currently active connections, per device. If value is 0, the device is disconnected.",
  17. }, []string{"device"})
  18. )
  19. func registerDeviceMetrics(deviceID string) {
  20. // Register metrics for this device, so that counters & gauges are present even
  21. // when zero.
  22. metricDeviceActiveConnections.WithLabelValues(deviceID)
  23. }