mirror of
https://github.com/restic/rest-server.git
synced 2025-12-06 17:15:45 -08:00
Make Server use the new repo.Handler
This contains all the glue to make Server use the new repo.Handler: - Remove all old handlers - Add ServeHTTP to make Server a single http.Handler - Remove Goji routing and replace by net/http and custom routing logic Additionally, this implements two-level backup repositories.
This commit is contained in:
committed by
Alexander Neumann
parent
55e549e92c
commit
1f593fafaf
31
metrics.go
31
metrics.go
@@ -1,6 +1,11 @@
|
||||
package restserver
|
||||
|
||||
import "github.com/prometheus/client_golang/prometheus"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/restic/rest-server/repo"
|
||||
)
|
||||
|
||||
var metricLabelList = []string{"user", "repo", "type"}
|
||||
|
||||
@@ -52,6 +57,30 @@ var metricBlobDeleteBytesTotal = prometheus.NewCounterVec(
|
||||
metricLabelList,
|
||||
)
|
||||
|
||||
// makeBlobMetricFunc creates a metrics callback function that increments the
|
||||
// Prometheus metrics.
|
||||
func makeBlobMetricFunc(username string, folderPath []string) repo.BlobMetricFunc {
|
||||
var f repo.BlobMetricFunc = func(objectType string, operation repo.BlobOperation, nBytes uint64) {
|
||||
labels := prometheus.Labels{
|
||||
"user": username,
|
||||
"repo": strings.Join(folderPath, ""),
|
||||
"type": objectType,
|
||||
}
|
||||
switch operation {
|
||||
case repo.BlobRead:
|
||||
metricBlobReadTotal.With(labels).Inc()
|
||||
metricBlobReadBytesTotal.With(labels).Add(float64(nBytes))
|
||||
case repo.BlobWrite:
|
||||
metricBlobWriteTotal.With(labels).Inc()
|
||||
metricBlobWriteBytesTotal.With(labels).Add(float64(nBytes))
|
||||
case repo.BlobDelete:
|
||||
metricBlobDeleteTotal.With(labels).Inc()
|
||||
metricBlobDeleteBytesTotal.With(labels).Add(float64(nBytes))
|
||||
}
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
func init() {
|
||||
// These are always initialized, but only updated if Config.Prometheus is set
|
||||
prometheus.MustRegister(metricBlobWriteTotal)
|
||||
|
||||
Reference in New Issue
Block a user