add build tag to disable metrics

This commit is contained in:
Nicola Murino
2020-06-19 17:08:51 +02:00
parent b30614e9d8
commit 23a80b01b6
29 changed files with 189 additions and 109 deletions

View File

@@ -1,3 +1,5 @@
// +build !nometrics
// Package metrics provides Prometheus metrics support
package metrics
@@ -6,6 +8,8 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/drakkan/sftpgo/version"
)
const (
@@ -15,9 +19,8 @@ const (
loginMethodKeyAndKeyboardInt = "publickey+keyboard-interactive"
)
// AddMetricsEndpoint exposes metrics to the specified endpoint
func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
handler.Handle(metricsPath, promhttp.Handler())
func init() {
version.AddFeature("+metrics")
}
var (
@@ -393,6 +396,11 @@ var (
})
)
// AddMetricsEndpoint exposes metrics to the specified endpoint
func AddMetricsEndpoint(metricsPath string, handler chi.Router) {
handler.Handle(metricsPath, promhttp.Handler())
}
// TransferCompleted updates metrics after an upload or a download
func TransferCompleted(bytesSent, bytesReceived int64, transferKind int, err error) {
if transferKind == 0 {