plugin/reload: Add metrics (#2922)

* Issue 2920
- Add failed reload counter metrics

* typo fix

* Requested Changes
This commit is contained in:
Anshul Sharma 2019-06-26 09:38:46 +03:00 committed by Miek Gieben
parent cd176f859b
commit ad352cee88
3 changed files with 24 additions and 0 deletions

View file

@ -92,6 +92,12 @@ In general be careful with assigning new port and expecting reload to work fully
Also any `import` statement is not discovered by this plugin. This means if any of these imported files
changes the *reload* plugin is ignorant of that fact.
## Metrics
If monitoring is enabled (via the *prometheus* directive) then the following metric is exported:
* `coredns_reload_failed_count_total{}` - counts the number of failed reload attempts.
## Also See
See coredns-import(7) and corefile(5).

17
plugin/reload/metrics.go Normal file
View file

@ -0,0 +1,17 @@
package reload
import (
"github.com/coredns/coredns/plugin"
"github.com/prometheus/client_golang/prometheus"
)
// Metrics for the reload plugin
var (
FailedCount = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: plugin.Namespace,
Subsystem: "reload",
Name: "failed_count_total",
Help: "Counter of the number of failed reload attempts.",
})
)

View file

@ -83,6 +83,7 @@ func hook(event caddy.EventName, info interface{}) error {
_, err := instance.Restart(corefile)
if err != nil {
log.Errorf("Corefile changed but reload failed: %s", err)
FailedCount.Add(1)
continue
}
// we are done, if the plugin was not set used, then it is not.