Use method and path as labels
This commit is contained in:
parent
d7e3156972
commit
a1e698dcff
|
@ -233,29 +233,18 @@ func (s *HTTPServer) handler(enableDebug bool) http.Handler {
|
||||||
// handleFuncMetrics takes the given pattern and handler and wraps to produce
|
// handleFuncMetrics takes the given pattern and handler and wraps to produce
|
||||||
// metrics based on the pattern and request.
|
// metrics based on the pattern and request.
|
||||||
handleFuncMetrics := func(pattern string, handler http.HandlerFunc) {
|
handleFuncMetrics := func(pattern string, handler http.HandlerFunc) {
|
||||||
// Get the parts of the pattern. We omit any initial empty for the
|
// Tranform the pattern to a valid label by replacing the '/' by '_'.
|
||||||
// leading slash, and put an underscore as a "thing" placeholder if we
|
// Omit the leading slash.
|
||||||
// see a trailing slash, which means the part after is parsed. This lets
|
// Distinguish thing like /v1/query from /v1/query/<query_id> by having
|
||||||
// us distinguish from things like /v1/query and /v1/query/<query id>.
|
// an extra underscore.
|
||||||
var parts []string
|
path_label := strings.Replace(pattern[1:], "/", "_", -1)
|
||||||
for i, part := range strings.Split(pattern, "/") {
|
|
||||||
if part == "" {
|
|
||||||
if i == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
part = "_"
|
|
||||||
}
|
|
||||||
parts = append(parts, part)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register the wrapper, which will close over the expensive-to-compute
|
// Register the wrapper.
|
||||||
// parts from above.
|
|
||||||
// TODO (kyhavlov): Convert this to utilize metric labels in a major release
|
|
||||||
wrapper := func(resp http.ResponseWriter, req *http.Request) {
|
wrapper := func(resp http.ResponseWriter, req *http.Request) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
handler(resp, req)
|
handler(resp, req)
|
||||||
key := append([]string{"http", req.Method}, parts...)
|
labels := []metrics.Label{{Name: "method", Value: req.Method}, {Name: "path", Value: path_label}}
|
||||||
metrics.MeasureSince(key, start)
|
metrics.MeasureSinceWithLabels([]string{"http"}, start, labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
var gzipHandler http.Handler
|
var gzipHandler http.Handler
|
||||||
|
|
|
@ -177,7 +177,7 @@ This is a full list of metrics emitted by Consul.
|
||||||
| `consul.dns.stale_queries` | This increments when an agent serves a query within the allowed stale threshold. | queries | counter |
|
| `consul.dns.stale_queries` | This increments when an agent serves a query within the allowed stale threshold. | queries | counter |
|
||||||
| `consul.dns.ptr_query.` | This measures the time spent handling a reverse DNS query for the given node. | ms | timer |
|
| `consul.dns.ptr_query.` | This measures the time spent handling a reverse DNS query for the given node. | ms | timer |
|
||||||
| `consul.dns.domain_query.` | This measures the time spent handling a domain query for the given node. | ms | timer |
|
| `consul.dns.domain_query.` | This measures the time spent handling a domain query for the given node. | ms | timer |
|
||||||
| `consul.http..` | This tracks how long it takes to service the given HTTP request for the given verb and path. Paths do not include details like service or key names, for these an underscore will be present as a placeholder (eg. `consul.http.GET.v1.kv._`) | ms | timer |
|
| `consul.http` | This tracks how long it takes to service the given HTTP request for the given verb and path. Paths do not include details like service or key names, for these an underscore will be present as a placeholder (eg. label `path=v1_kv_`) | ms | timer |
|
||||||
|
|
||||||
## Server Health
|
## Server Health
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue