aboutsummaryrefslogtreecommitdiff
path: root/plugin/metrics/setup.go
diff options
context:
space:
mode:
authorGravatar Jiacheng Xu <xjcmaxwellcjx@gmail.com> 2019-03-23 10:43:15 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2019-03-23 09:43:15 +0000
commit0e137b23f152c70590e82f0b5985b2faf104c8e0 (patch)
treef2c492c823b7575957b0e51946fb22b9c935235d /plugin/metrics/setup.go
parenta3dd8cdf8de1a9aacc36fe8cf0f268e69bd8a45d (diff)
downloadcoredns-0e137b23f152c70590e82f0b5985b2faf104c8e0.tar.gz
coredns-0e137b23f152c70590e82f0b5985b2faf104c8e0.tar.zst
coredns-0e137b23f152c70590e82f0b5985b2faf104c8e0.zip
plugin/metrics: Add a metric to monitor which plugin(s) is(are) enabled (#2700)
* Add a GaugeVec for enabled plugins monitoring. Signed-off-by: Jiacheng Xu <xjcmaxwellcjx@gmail.com> * Add server label and zone label for enable_plugin matric. * Add a test for PluginEnabled metric * Add description for enabledPlugin metric. * Change the description for the enabledPlugin metric. * Reset the enabledPlugin metric when restart the server. * Add the bug session for enabledPlugin metric. * Remove the resolveTCPAddr
Diffstat (limited to 'plugin/metrics/setup.go')
-rw-r--r--plugin/metrics/setup.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/plugin/metrics/setup.go b/plugin/metrics/setup.go
index ffc0466f3..b50960211 100644
--- a/plugin/metrics/setup.go
+++ b/plugin/metrics/setup.go
@@ -7,6 +7,7 @@ import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/coremain"
"github.com/coredns/coredns/plugin"
+ "github.com/coredns/coredns/plugin/metrics/vars"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/uniq"
@@ -50,6 +51,23 @@ func setup(c *caddy.Controller) error {
return nil
})
+ c.OnRestart(func() error {
+ vars.PluginEnabled.Reset()
+ return nil
+ })
+
+ c.OnStartup(func() error {
+ conf := dnsserver.GetConfig(c)
+ plugins := conf.Handlers()
+ for _, h := range conf.ListenHosts {
+ addrstr := conf.Transport + "://" + net.JoinHostPort(h, conf.Port)
+ for _, p := range plugins {
+ vars.PluginEnabled.WithLabelValues(addrstr, conf.Zone, p.Name()).Set(1)
+ }
+ }
+ return nil
+
+ })
c.OnRestart(m.OnRestart)
c.OnFinalShutdown(m.OnFinalShutdown)