Improving instrumentation. (#1042)

This commit is contained in:
Alberto 2017-01-17 18:14:13 +01:00 committed by Vincent Demeester
parent 483ef486af
commit fa1090b6eb
5 changed files with 19 additions and 10 deletions

View file

@ -331,7 +331,7 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
// default Metrics
defaultWeb.Metrics = &types.Metrics{
Prometheus: &types.Prometheus{
Buckets: types.Buckets{100, 300, 1200, 5000},
Buckets: types.Buckets{0.1, 0.3, 1.2, 5},
},
}

View file

@ -544,6 +544,10 @@ address = ":8080"
# [web.statistics]
# RecentErrors = 10
#
# To enable Traefik to export internal metrics to Prometheus
# [web.metrics.prometheus]
# Buckets=[0.1,0.3,1.2,5]
#
# To enable basic auth on the webui
# with 2 user/pass: test:test and test2:test2
# Passwords can be encoded in MD5, SHA1 and BCrypt: you can use htpasswd to generate those ones
@ -718,7 +722,7 @@ $ curl -s "http://localhost:8080/api" | jq .
- `/metrics`: You can enable Traefik to export internal metrics to different monitoring systems (Only Prometheus is supported at the moment).
```bash
$ traefik --web.metrics.prometheus --web.metrics.prometheus.buckets="100,300"
$ traefik --web.metrics.prometheus --web.metrics.prometheus.buckets="0.1,0.3,1.2,5"
```
## Docker backend

View file

@ -37,7 +37,7 @@ func (m *MetricsWrapper) ServeHTTP(rw http.ResponseWriter, r *http.Request, next
next(prw, r)
labels := []string{"code", strconv.Itoa(prw.StatusCode()), "method", r.Method}
m.Impl.getReqsCounter().With(labels...).Add(1)
m.Impl.getLatencyHistogram().With(labels...).Observe(float64(time.Since(start).Nanoseconds()) / 1000000)
m.Impl.getLatencyHistogram().Observe(float64(time.Since(start).Seconds()))
}
func (rw *responseRecorder) StatusCode() int {

View file

@ -10,12 +10,12 @@ import (
)
const (
reqsName = "requests_total"
latencyName = "request_duration_milliseconds"
reqsName = "traefik_requests_total"
latencyName = "traefik_request_duration_seconds"
)
// Prometheus is an Implementation for Metrics that exposes prometheus metrics for the number of requests,
// the latency and the response size, partitioned by status code and method.
// Prometheus is an Implementation for Metrics that exposes prometheus metrics for the latency
// and the number of requests partitioned by status code and method.
type Prometheus struct {
reqsCounter metrics.Counter
latencyHistogram metrics.Histogram
@ -45,17 +45,17 @@ func NewPrometheus(name string, config *types.Prometheus) *Prometheus {
if config.Buckets != nil {
buckets = config.Buckets
} else {
buckets = []float64{100, 300, 1200, 5000}
buckets = []float64{0.1, 0.3, 1.2, 5}
}
m.latencyHistogram = prometheus.NewHistogramFrom(
stdprometheus.HistogramOpts{
Name: latencyName,
Help: "How long it took to process the request, partitioned by status code and method.",
Help: "How long it took to process the request.",
ConstLabels: stdprometheus.Labels{"service": name},
Buckets: buckets,
},
[]string{"code", "method"},
[]string{},
)
return &m
}

View file

@ -326,6 +326,11 @@
# Enable more detailed statistics
# [web.statistics]
# RecentErrors = 10
#
# To enable Traefik to export internal metrics to Prometheus
# [web.metrics.prometheus]
# Buckets=[0.1,0.3,1.2,5]
#
# To enable basic auth on the webui
# with 2 user/pass: test:test and test2:test2