@@ -77,7 +77,7 @@ var standardMetrics = []*Metric{
77
77
}
78
78
79
79
/*
80
- RequestCounterURLLabelMappingFunc is a function which can be supplied to the middleware to control
80
+ RequestCounterLabelMappingFunc is a function which can be supplied to the middleware to control
81
81
the cardinality of the request counter's "url" label, which might be required in some contexts.
82
82
For instance, if for a "/customer/:name" route you don't want to generate a time series for every
83
83
possible customer name, you could use this function:
@@ -94,8 +94,9 @@ func(c echo.Context) string {
94
94
}
95
95
96
96
which would map "/customer/alice" and "/customer/bob" to their template "/customer/:name".
97
+ It can also be applied for the "Host" label
97
98
*/
98
- type RequestCounterURLLabelMappingFunc func (c echo.Context ) string
99
+ type RequestCounterLabelMappingFunc func (c echo.Context ) string
99
100
100
101
// Metric is a definition for the name, description, type, ID, and
101
102
// prometheus.Collector type (i.e. CounterVec, Summary, etc) of each metric
@@ -121,7 +122,8 @@ type Prometheus struct {
121
122
Subsystem string
122
123
Skipper middleware.Skipper
123
124
124
- RequestCounterURLLabelMappingFunc RequestCounterURLLabelMappingFunc
125
+ RequestCounterURLLabelMappingFunc RequestCounterLabelMappingFunc
126
+ RequestCounterHostLabelMappingFunc RequestCounterLabelMappingFunc
125
127
126
128
// Context string to use as a prometheus URL label
127
129
URLLabelFromContext string
@@ -165,6 +167,9 @@ func NewPrometheus(subsystem string, skipper middleware.Skipper, customMetricsLi
165
167
RequestCounterURLLabelMappingFunc : func (c echo.Context ) string {
166
168
return c .Path () // i.e. by default do nothing, i.e. return URL as is
167
169
},
170
+ RequestCounterHostLabelMappingFunc : func (c echo.Context ) string {
171
+ return c .Request ().Host
172
+ },
168
173
}
169
174
170
175
p .registerMetrics (subsystem )
@@ -390,7 +395,7 @@ func (p *Prometheus) HandlerFunc(next echo.HandlerFunc) echo.HandlerFunc {
390
395
url = u .(string )
391
396
}
392
397
393
- p .reqCnt .WithLabelValues (status , c .Request ().Method , c . Request (). Host , url ).Inc ()
398
+ p .reqCnt .WithLabelValues (status , c .Request ().Method , p . RequestCounterHostLabelMappingFunc ( c ) , url ).Inc ()
394
399
p .reqSz .WithLabelValues (status , c .Request ().Method , url ).Observe (float64 (reqSz ))
395
400
p .resSz .WithLabelValues (status , c .Request ().Method , url ).Observe (resSz )
396
401
0 commit comments