aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorJakob Borg <jakob@kastelo.net>2023-11-24 08:38:34 +0100
committerJakob Borg <jakob@kastelo.net>2023-11-27 08:24:59 +0100
commita8b90963535f2919ceea5994821472b85288a4dd (patch)
tree595a35c13d9608f4b29eb0f95fc8efb098c76821 /cmd
parent5328380691f2aa430873616a4e72bd8ef9b1c1e3 (diff)
downloadsyncthing-a8b90963535f2919ceea5994821472b85288a4dd.tar.gz
syncthing-a8b90963535f2919ceea5994821472b85288a4dd.zip
cmd/stcrashreceiver: Add metrics for incoming reports
Diffstat (limited to 'cmd')
-rw-r--r--cmd/stcrashreceiver/main.go8
-rw-r--r--cmd/stcrashreceiver/metrics.go25
-rw-r--r--cmd/stcrashreceiver/stcrashreceiver.go9
3 files changed, 42 insertions, 0 deletions
diff --git a/cmd/stcrashreceiver/main.go b/cmd/stcrashreceiver/main.go
index ec57e9e9b..4ea02da39 100644
--- a/cmd/stcrashreceiver/main.go
+++ b/cmd/stcrashreceiver/main.go
@@ -24,6 +24,7 @@ import (
"time"
"github.com/alecthomas/kong"
+ "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/syncthing/syncthing/lib/sha256"
"github.com/syncthing/syncthing/lib/ur"
@@ -72,6 +73,7 @@ func main() {
mux.HandleFunc("/ping", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("OK"))
})
+ mux.Handle("/metrics", promhttp.Handler())
if params.DSN != "" {
mux.HandleFunc("/newcrash/failure", handleFailureFn(params.DSN, filepath.Join(params.Dir, "failure_reports")))
@@ -85,6 +87,11 @@ func main() {
func handleFailureFn(dsn, failureDir string) func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, req *http.Request) {
+ result := "failure"
+ defer func() {
+ metricFailureReportsTotal.WithLabelValues(result).Inc()
+ }()
+
lr := io.LimitReader(req.Body, maxRequestSize)
bs, err := io.ReadAll(lr)
req.Body.Close()
@@ -135,6 +142,7 @@ func handleFailureFn(dsn, failureDir string) func(w http.ResponseWriter, req *ht
log.Println("Failed to send failure report:", err)
} else {
log.Println("Sent failure report:", r.Description)
+ result = "success"
}
}
}
diff --git a/cmd/stcrashreceiver/metrics.go b/cmd/stcrashreceiver/metrics.go
new file mode 100644
index 000000000..a7539d816
--- /dev/null
+++ b/cmd/stcrashreceiver/metrics.go
@@ -0,0 +1,25 @@
+// 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 main
+
+import (
+ "github.com/prometheus/client_golang/prometheus"
+ "github.com/prometheus/client_golang/prometheus/promauto"
+)
+
+var (
+ metricCrashReportsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
+ Namespace: "syncthing",
+ Subsystem: "crashreceiver",
+ Name: "crash_reports_total",
+ }, []string{"result"})
+ metricFailureReportsTotal = promauto.NewCounterVec(prometheus.CounterOpts{
+ Namespace: "syncthing",
+ Subsystem: "crashreceiver",
+ Name: "failure_reports_total",
+ }, []string{"result"})
+)
diff --git a/cmd/stcrashreceiver/stcrashreceiver.go b/cmd/stcrashreceiver/stcrashreceiver.go
index 0d01ca08d..d8c0d2965 100644
--- a/cmd/stcrashreceiver/stcrashreceiver.go
+++ b/cmd/stcrashreceiver/stcrashreceiver.go
@@ -71,6 +71,11 @@ func (r *crashReceiver) serveHead(reportID string, w http.ResponseWriter, _ *htt
// servePut accepts and stores the given report.
func (r *crashReceiver) servePut(reportID string, w http.ResponseWriter, req *http.Request) {
+ result := "receive_failure"
+ defer func() {
+ metricCrashReportsTotal.WithLabelValues(result).Inc()
+ }()
+
// Read at most maxRequestSize of report data.
log.Println("Receiving report", reportID)
lr := io.LimitReader(req.Body, maxRequestSize)
@@ -81,13 +86,17 @@ func (r *crashReceiver) servePut(reportID string, w http.ResponseWriter, req *ht
return
}
+ result = "success"
+
// Store the report
if !r.store.Put(reportID, bs) {
log.Println("Failed to store report (queue full):", reportID)
+ result = "queue_failure"
}
// Send the report to Sentry
if !r.sentry.Send(reportID, userIDFor(req), bs) {
log.Println("Failed to send report to sentry (queue full):", reportID)
+ result = "sentry_failure"
}
}