From 368a64546c97abdc7019f98cbc97eecdbda2b6a5 Mon Sep 17 00:00:00 2001 From: Igor Drozdov Date: Wed, 21 Jul 2021 11:24:00 +0300 Subject: Prometheus metrics for HTTP requests A RoundTripper for tracking the duration of an http request is introduced --- internal/metrics/metrics.go | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 internal/metrics/metrics.go (limited to 'internal/metrics/metrics.go') diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go new file mode 100644 index 0000000..6174bca --- /dev/null +++ b/internal/metrics/metrics.go @@ -0,0 +1,63 @@ +package metrics + +import ( + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" +) + +const ( + namespace = "gitlab_shell" + sshdSubsystem = "sshd" + httpSubsystem = "http" +) + +var ( + SshdConnectionDuration = promauto.NewHistogram( + prometheus.HistogramOpts{ + Namespace: namespace, + Subsystem: sshdSubsystem, + Name: "connection_duration_seconds", + Help: "A histogram of latencies for connections to gitlab-shell sshd.", + Buckets: []float64{ + 0.005, /* 5ms */ + 0.025, /* 25ms */ + 0.1, /* 100ms */ + 0.5, /* 500ms */ + 1.0, /* 1s */ + 10.0, /* 10s */ + 30.0, /* 30s */ + 60.0, /* 1m */ + 300.0, /* 5m */ + }, + }, + ) + + SshdHitMaxSessions = promauto.NewCounter( + prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: sshdSubsystem, + Name: "concurrent_limited_sessions_total", + Help: "The number of times the concurrent sessions limit was hit in gitlab-shell sshd.", + }, + ) + + HttpRequestDuration = promauto.NewHistogramVec( + prometheus.HistogramOpts{ + Namespace: namespace, + Subsystem: httpSubsystem, + Name: "request_seconds", + Help: "A histogram of latencies for gitlab-shell http requests", + Buckets: []float64{ + 0.01, /* 10ms */ + 0.05, /* 50ms */ + 0.1, /* 100ms */ + 0.25, /* 250ms */ + 0.5, /* 500ms */ + 1.0, /* 1s */ + 5.0, /* 5s */ + 10.0, /* 10s */ + }, + }, + []string{"code", "method"}, + ) +) -- cgit v1.2.1