Added entrypoint metrics to influxdb
This commit is contained in:
parent
0a41cd43a5
commit
b91ae71241
2 changed files with 52 additions and 13 deletions
|
@ -25,9 +25,18 @@ type influxDBWriter struct {
|
||||||
var influxDBTicker *time.Ticker
|
var influxDBTicker *time.Ticker
|
||||||
|
|
||||||
const (
|
const (
|
||||||
influxDBMetricsReqsName = "traefik.requests.total"
|
influxDBMetricsBackendReqsName = "traefik.backend.requests.total"
|
||||||
influxDBMetricsLatencyName = "traefik.request.duration"
|
influxDBMetricsBackendLatencyName = "traefik.backend.request.duration"
|
||||||
influxDBRetriesTotalName = "traefik.backend.retries.total"
|
influxDBRetriesTotalName = "traefik.backend.retries.total"
|
||||||
|
influxDBConfigReloadsName = "traefik.config.reload.total"
|
||||||
|
influxDBConfigReloadsFailureName = influxDBConfigReloadsName + ".failure"
|
||||||
|
influxDBLastConfigReloadSuccessName = "traefik.config.reload.lastSuccessTimestamp"
|
||||||
|
influxDBLastConfigReloadFailureName = "traefik.config.reload.lastFailureTimestamp"
|
||||||
|
influxDBEntrypointReqsName = "traefik.entrypoint.requests.total"
|
||||||
|
influxDBEntrypointReqDurationName = "traefik.entrypoint.request.duration"
|
||||||
|
influxDBEntrypointOpenConnsName = "traefik.entrypoint.connections.open"
|
||||||
|
influxDBOpenConnsName = "traefik.backend.connections.open"
|
||||||
|
influxDBServerUpName = "traefik.backend.server.up"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterInfluxDB registers the metrics pusher if this didn't happen yet and creates a InfluxDB Registry instance.
|
// RegisterInfluxDB registers the metrics pusher if this didn't happen yet and creates a InfluxDB Registry instance.
|
||||||
|
@ -38,9 +47,18 @@ func RegisterInfluxDB(config *types.InfluxDB) Registry {
|
||||||
|
|
||||||
return &standardRegistry{
|
return &standardRegistry{
|
||||||
enabled: true,
|
enabled: true,
|
||||||
backendReqsCounter: influxDBClient.NewCounter(influxDBMetricsReqsName),
|
configReloadsCounter: influxDBClient.NewCounter(influxDBConfigReloadsName),
|
||||||
backendReqDurationHistogram: influxDBClient.NewHistogram(influxDBMetricsLatencyName),
|
configReloadsFailureCounter: influxDBClient.NewCounter(influxDBConfigReloadsFailureName),
|
||||||
|
lastConfigReloadSuccessGauge: influxDBClient.NewGauge(influxDBLastConfigReloadSuccessName),
|
||||||
|
lastConfigReloadFailureGauge: influxDBClient.NewGauge(influxDBLastConfigReloadFailureName),
|
||||||
|
entrypointReqsCounter: influxDBClient.NewCounter(influxDBEntrypointReqsName),
|
||||||
|
entrypointReqDurationHistogram: influxDBClient.NewHistogram(influxDBEntrypointReqDurationName),
|
||||||
|
entrypointOpenConnsGauge: influxDBClient.NewGauge(influxDBEntrypointOpenConnsName),
|
||||||
|
backendReqsCounter: influxDBClient.NewCounter(influxDBMetricsBackendReqsName),
|
||||||
|
backendReqDurationHistogram: influxDBClient.NewHistogram(influxDBMetricsBackendLatencyName),
|
||||||
backendRetriesCounter: influxDBClient.NewCounter(influxDBRetriesTotalName),
|
backendRetriesCounter: influxDBClient.NewCounter(influxDBRetriesTotalName),
|
||||||
|
backendOpenConnsGauge: influxDBClient.NewGauge(influxDBOpenConnsName),
|
||||||
|
backendServerUpGauge: influxDBClient.NewGauge(influxDBServerUpName),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,22 +23,43 @@ func TestInfluxDB(t *testing.T) {
|
||||||
t.Fatalf("InfluxDB registry must be enabled")
|
t.Fatalf("InfluxDB registry must be enabled")
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := []string{
|
expectedBackend := []string{
|
||||||
`(traefik\.requests\.total,code=200,method=GET,service=test count=1) [\d]{19}`,
|
`(traefik\.backend\.requests\.total,code=200,method=GET,service=test count=1) [\d]{19}`,
|
||||||
`(traefik\.requests\.total,code=404,method=GET,service=test count=1) [\d]{19}`,
|
`(traefik\.backend\.requests\.total,code=404,method=GET,service=test count=1) [\d]{19}`,
|
||||||
`(traefik\.request\.duration,code=200,method=GET,service=test p50=10000,p90=10000,p95=10000,p99=10000) [\d]{19}`,
|
`(traefik\.backend\.request\.duration(?:,backend=test)?,code=200,method=GET,service=test(?:,url=http://127.0.0.1)? p50=10000,p90=10000,p95=10000,p99=10000) [\d]{19}`,
|
||||||
`(traefik\.backend\.retries\.total(?:,code=[\d]{3},method=GET)?,service=test count=2) [\d]{19}`,
|
`(traefik\.backend\.retries\.total(?:,code=[\d]{3},method=GET)?,service=test count=2) [\d]{19}`,
|
||||||
|
`(traefik\.config\.reload\.total(?:[a-z=0-9A-Z,]+)? count=1) [\d]{19}`,
|
||||||
|
`(traefik\.config\.reload\.total\.failure(?:[a-z=0-9A-Z,]+)? count=1) [\d]{19}`,
|
||||||
|
`(traefik\.backend\.server\.up,backend=test(?:[a-z=0-9A-Z,]+)?,url=http://127.0.0.1 value=1) [\d]{19}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
msg := udp.ReceiveString(t, func() {
|
msgBackend := udp.ReceiveString(t, func() {
|
||||||
influxDBRegistry.BackendReqsCounter().With("service", "test", "code", strconv.Itoa(http.StatusOK), "method", http.MethodGet).Add(1)
|
influxDBRegistry.BackendReqsCounter().With("service", "test", "code", strconv.Itoa(http.StatusOK), "method", http.MethodGet).Add(1)
|
||||||
influxDBRegistry.BackendReqsCounter().With("service", "test", "code", strconv.Itoa(http.StatusNotFound), "method", http.MethodGet).Add(1)
|
influxDBRegistry.BackendReqsCounter().With("service", "test", "code", strconv.Itoa(http.StatusNotFound), "method", http.MethodGet).Add(1)
|
||||||
influxDBRegistry.BackendRetriesCounter().With("service", "test").Add(1)
|
influxDBRegistry.BackendRetriesCounter().With("service", "test").Add(1)
|
||||||
influxDBRegistry.BackendRetriesCounter().With("service", "test").Add(1)
|
influxDBRegistry.BackendRetriesCounter().With("service", "test").Add(1)
|
||||||
influxDBRegistry.BackendReqDurationHistogram().With("service", "test", "code", strconv.Itoa(http.StatusOK)).Observe(10000)
|
influxDBRegistry.BackendReqDurationHistogram().With("service", "test", "code", strconv.Itoa(http.StatusOK)).Observe(10000)
|
||||||
|
influxDBRegistry.ConfigReloadsCounter().Add(1)
|
||||||
|
influxDBRegistry.ConfigReloadsFailureCounter().Add(1)
|
||||||
|
influxDBRegistry.BackendServerUpGauge().With("backend", "test", "url", "http://127.0.0.1").Set(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
assertMessage(t, msg, expected)
|
assertMessage(t, msgBackend, expectedBackend)
|
||||||
|
|
||||||
|
expectedEntrypoint := []string{
|
||||||
|
`(traefik\.entrypoint\.requests\.total(?:,backend=test,code=[\d]{3})?,entrypoint=test(?:[a-z=0-9A-Z,:/.]+)? count=1) [\d]{19}`,
|
||||||
|
`(traefik\.entrypoint\.request\.duration(?:,backend=test,code=[\d]{3})?,entrypoint=test(?:[a-z=0-9A-Z,:/.]+)? p50=10000,p90=10000,p95=10000,p99=10000) [\d]{19}`,
|
||||||
|
`(traefik\.entrypoint\.connections\.open(?:[a-z=0-9A-Z,]+)?,entrypoint=test,(?:[a-z=0-9A-Z,:.//]+)? value=1) [\d]{19}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
msgEntrypoint := udp.ReceiveString(t, func() {
|
||||||
|
influxDBRegistry.EntrypointReqsCounter().With("entrypoint", "test").Add(1)
|
||||||
|
influxDBRegistry.EntrypointReqDurationHistogram().With("entrypoint", "test").Observe(10000)
|
||||||
|
influxDBRegistry.EntrypointOpenConnsGauge().With("entrypoint", "test").Set(1)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
assertMessage(t, msgEntrypoint, expectedEntrypoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertMessage(t *testing.T, msg string, patterns []string) {
|
func assertMessage(t *testing.T, msg string, patterns []string) {
|
||||||
|
|
Loading…
Reference in a new issue