Overloaded (#1364)

* plugin/health: add 'overloaded metrics'

Query our on health endpoint and record (and export as a metric) the
time it takes. The Get has a 5s timeout, that, when reached, will set
the metric duration to 5s. The actually call "I'm I overloaded" is left
to an external entity.

* README

* golint and govet

* and the tests
This commit is contained in:
Miek Gieben
2018-01-10 11:41:22 +00:00
committed by GitHub
parent cced1a4c12
commit 48059a6c3e
5 changed files with 90 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/mholt/caddy"
)
@@ -23,7 +24,7 @@ func setup(c *caddy.Controller) error {
return plugin.Error("health", err)
}
h := &health{Addr: addr}
h := &health{Addr: addr, stop: make(chan bool)}
c.OnStartup(func() error {
plugins := dnsserver.GetConfig(c).Handlers()
@@ -36,6 +37,7 @@ func setup(c *caddy.Controller) error {
})
c.OnStartup(func() error {
// Poll all middleware every second.
h.poll()
go func() {
for {
@@ -46,8 +48,21 @@ func setup(c *caddy.Controller) error {
return nil
})
c.OnStartup(h.Startup)
c.OnFinalShutdown(h.Shutdown)
c.OnStartup(func() error {
onceMetric.Do(func() {
m := dnsserver.GetConfig(c).Handler("prometheus")
if m == nil {
return
}
if x, ok := m.(*metrics.Metrics); ok {
x.MustRegister(HealthDuration)
}
})
return nil
})
c.OnStartup(h.OnStartup)
c.OnFinalShutdown(h.OnShutdown)
// Don't do AddPlugin, as health is not *really* a plugin just a separate webserver running.
return nil