forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
39 lines (33 loc) · 845 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package server
import (
"fmt"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
http_utils "www.velocidex.com/golang/velociraptor/utils/http"
)
var (
httpErrorStatusCounters = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "frontend_http_status",
Help: "Count of various http status.",
},
[]string{"status"},
)
)
func RecordHTTPStats(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Ignore Websocket connections
if is_ws_connection(r) {
next.ServeHTTP(w, r)
return
}
rec := &http_utils.StatusRecorder{
w,
w.(http.Flusher),
200, nil}
next.ServeHTTP(rec, r)
status := fmt.Sprintf("%v", rec.Status)
httpErrorStatusCounters.WithLabelValues(status).Inc()
})
}