mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
debbe726e0
### Purpose Adds a new metric `syncthing_connections_active` which equals to the amount of active connections per device. Fixes #9527 <!-- Describe the purpose of this change. If there is an existing issue that is resolved by this pull request, ensure that the commit subject is on the form `Some short description (fixes #1234)` where 1234 is the issue number. --> ### Testing I've manually tested it by running syncthing with these changes locally and examining the returned metrics from `/metrics`. I've done the following things: - Connect & disconnect a device - Increase & decrease the number of connections and verify that the value of the metric matches with the amount displayed in the GUI. ### Documentation https://github.com/syncthing/docs/blob/main/includes/metrics-list.rst needs to be regenerated with [find-metrics.go](https://github.com/syncthing/docs/blob/main/_script/find-metrics/find-metrics.go) ## Authorship Your name and email will be added automatically to the AUTHORS file based on the commit metadata. --------- Co-authored-by: Jakob Borg <jakob@kastelo.net>
64 lines
2.3 KiB
Go
64 lines
2.3 KiB
Go
// Copyright (C) 2023 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package protocol
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
metricDeviceSentBytes = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "syncthing",
|
|
Subsystem: "protocol",
|
|
Name: "sent_bytes_total",
|
|
Help: "Total amount of data sent, per device",
|
|
}, []string{"device"})
|
|
metricDeviceSentUncompressedBytes = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "syncthing",
|
|
Subsystem: "protocol",
|
|
Name: "sent_uncompressed_bytes_total",
|
|
Help: "Total amount of data sent, before compression, per device",
|
|
}, []string{"device"})
|
|
metricDeviceSentMessages = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "syncthing",
|
|
Subsystem: "protocol",
|
|
Name: "sent_messages_total",
|
|
Help: "Total number of messages sent, per device",
|
|
}, []string{"device"})
|
|
|
|
metricDeviceRecvBytes = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "syncthing",
|
|
Subsystem: "protocol",
|
|
Name: "recv_bytes_total",
|
|
Help: "Total amount of data received, per device",
|
|
}, []string{"device"})
|
|
metricDeviceRecvDecompressedBytes = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "syncthing",
|
|
Subsystem: "protocol",
|
|
Name: "recv_decompressed_bytes_total",
|
|
Help: "Total amount of data received, after decompression, per device",
|
|
}, []string{"device"})
|
|
metricDeviceRecvMessages = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "syncthing",
|
|
Subsystem: "protocol",
|
|
Name: "recv_messages_total",
|
|
Help: "Total number of messages received, per device",
|
|
}, []string{"device"})
|
|
)
|
|
|
|
func registerDeviceMetrics(deviceID string) {
|
|
// Register metrics for this device, so that counters are present even
|
|
// when zero.
|
|
metricDeviceSentBytes.WithLabelValues(deviceID)
|
|
metricDeviceSentUncompressedBytes.WithLabelValues(deviceID)
|
|
metricDeviceSentMessages.WithLabelValues(deviceID)
|
|
metricDeviceRecvBytes.WithLabelValues(deviceID)
|
|
metricDeviceRecvDecompressedBytes.WithLabelValues(deviceID)
|
|
metricDeviceRecvMessages.WithLabelValues(deviceID)
|
|
}
|