diff options
author | 2018-01-10 11:41:22 +0000 | |
---|---|---|
committer | 2018-01-10 11:41:22 +0000 | |
commit | 48059a6c3e33f34263c74a09630a85ae885e1178 (patch) | |
tree | 8cf9103a034df828ee3d7ee64c7b720e41e2de27 /plugin/health/setup.go | |
parent | cced1a4c12b3a6646e186d14ce89bf4f60a632f8 (diff) | |
download | coredns-48059a6c3e33f34263c74a09630a85ae885e1178.tar.gz coredns-48059a6c3e33f34263c74a09630a85ae885e1178.tar.zst coredns-48059a6c3e33f34263c74a09630a85ae885e1178.zip |
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
Diffstat (limited to 'plugin/health/setup.go')
-rw-r--r-- | plugin/health/setup.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/plugin/health/setup.go b/plugin/health/setup.go index 12dd29c84..d5285c55f 100644 --- a/plugin/health/setup.go +++ b/plugin/health/setup.go @@ -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 |