Commit a7db87e3 authored by Jacob Vosmaer's avatar Jacob Vosmaer

Track total and active requests

parent b48dca47
......@@ -6,7 +6,10 @@ import (
"log"
"net/http"
"os"
"strconv"
"time"
"gitlab.com/gitlab-org/gitlab-workhorse/internal/metrics"
)
var responseLogger *log.Logger
......@@ -27,6 +30,7 @@ type LoggingResponseWriter struct {
}
func NewLoggingResponseWriter(rw http.ResponseWriter) LoggingResponseWriter {
metrics.RequestsActive.Inc()
return LoggingResponseWriter{
rw: rw,
started: time.Now(),
......@@ -62,4 +66,7 @@ func (l *LoggingResponseWriter) Log(r *http.Request) {
fmt.Sprintf("%s %s %s", r.Method, r.RequestURI, r.Proto),
l.status, l.written, r.Referer(), r.UserAgent(), duration.Seconds(),
)
metrics.RequestsActive.Dec()
metrics.RequestsTotal.WithLabelValues(strconv.Itoa(l.status), r.Method).Inc()
}
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
RequestsActive = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "http_requests_active",
Help: "Number of HTTP requests currently being handled.",
})
RequestsTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "http_requests_total",
Help: "How many HTTP requests processed, partitioned by status code and HTTP method.",
},
[]string{"code", "method"},
)
)
func init() {
prometheus.MustRegister(RequestsActive)
prometheus.MustRegister(RequestsTotal)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment