Minor changes to organization of http server and client metrics

This commit is contained in:
Nick Gerakines 2020-03-18 12:10:27 -04:00
parent d152d5520a
commit 9d1acae1d5
No known key found for this signature in database
GPG Key ID: 33D43D854F96B2E4
3 changed files with 24 additions and 10 deletions

View File

@ -35,7 +35,7 @@ func DefaultHTTPClient() *http.Client {
}
}
func InstrumentedDefaultHTTPClient(metricFactory promauto.Factory) *http.Client {
func InstrumentedDefaultHTTPClient(metricFactory promauto.Factory, namespace, subsystem string) *http.Client {
client := &http.Client{
Timeout: 10 * time.Second,
@ -46,13 +46,17 @@ func InstrumentedDefaultHTTPClient(metricFactory promauto.Factory) *http.Client
}
inFlightGauge := metricFactory.NewGauge(prometheus.GaugeOpts{
Name: "client_in_flight_requests",
Namespace: namespace,
Subsystem: subsystem,
Name: "in_flight_requests",
Help: "A gauge of in-flight requests for the wrapped client.",
})
counter := metricFactory.NewCounterVec(
prometheus.CounterOpts{
Name: "client_api_requests_total",
Namespace: namespace,
Subsystem: subsystem,
Name: "requests_total",
Help: "A counter for requests from the wrapped client.",
},
[]string{"code", "method"},
@ -60,6 +64,8 @@ func InstrumentedDefaultHTTPClient(metricFactory promauto.Factory) *http.Client
dnsLatencyVec := metricFactory.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "dns_duration_seconds",
Help: "Trace dns latency histogram.",
Buckets: []float64{.005, .01, .025, .05},
@ -69,6 +75,8 @@ func InstrumentedDefaultHTTPClient(metricFactory promauto.Factory) *http.Client
tlsLatencyVec := metricFactory.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "tls_duration_seconds",
Help: "Trace tls latency histogram.",
Buckets: []float64{.05, .1, .25, .5},
@ -78,6 +86,8 @@ func InstrumentedDefaultHTTPClient(metricFactory promauto.Factory) *http.Client
histVec := metricFactory.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Subsystem: subsystem,
Name: "request_duration_seconds",
Help: "A histogram of request latencies.",
Buckets: prometheus.DefBuckets,

View File

@ -211,7 +211,7 @@ func serverCommandAction(cliCtx *cli.Context) error {
return err
}
fact := promauto.With(registry)
httpClient :=common.InstrumentedDefaultHTTPClient(fact)
httpClient := common.InstrumentedDefaultHTTPClient(fact, "web", "client")
var svgConv SVGConverter
if svgerConfig.Enabled {
@ -237,7 +237,7 @@ func serverCommandAction(cliCtx *cli.Context) error {
configI18nMiddleware(sentryConfig, logger, utrans, domain, r)
mm := newMetricsMiddleware("tavern", promauto.With(registry))
mm := newMetricsMiddleware("web", "server", promauto.With(registry))
r.Use(func(c *gin.Context) {
start := time.Now()

View File

@ -14,33 +14,37 @@ type metricsMiddleware struct {
responseSize *prometheus.SummaryVec
}
func newMetricsMiddleware(namespace string, metricFactory promauto.Factory) metricsMiddleware {
func newMetricsMiddleware(namespace, subsystem string, metricFactory promauto.Factory) metricsMiddleware {
return metricsMiddleware{
requests: metricFactory.NewCounterVec(
prometheus.CounterOpts{
Namespace: namespace,
Name: "http_request_count_total",
Subsystem: subsystem,
Name: "request_total",
Help: "Total number of HTTP requests made.",
}, []string{"status", "endpoint", "method"},
),
totalTime: metricFactory.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: namespace,
Name: "http_request_duration_seconds",
Subsystem: subsystem,
Name: "request_duration",
Help: "HTTP request latencies in seconds.",
}, []string{"status", "endpoint", "method"},
),
requestSize: metricFactory.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Name: "http_request_size_bytes",
Subsystem: subsystem,
Name: "request_size",
Help: "HTTP request sizes in bytes.",
}, []string{"status", "endpoint", "method"},
),
responseSize: metricFactory.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
Name: "http_response_size_bytes",
Subsystem: subsystem,
Name: "response_size",
Help: "HTTP request sizes in bytes.",
}, []string{"status", "endpoint", "method"},
),