From: Ryan Date: Mon, 4 Feb 2019 14:01:27 +0000 (-0500) Subject: Add metric successful_config_load (#413) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d47e1ee5560c36dbe7c77af3ecafe624ef1c7cfb;p=blackbox_exporter.git Add metric successful_config_load (#413) Signed-off-by: Ryan Shatford --- diff --git a/config/config.go b/config/config.go index ea92778..afb7ecf 100644 --- a/config/config.go +++ b/config/config.go @@ -10,9 +10,29 @@ import ( yaml "gopkg.in/yaml.v2" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/common/config" ) +var ( + configReloadSuccess = prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: "blackbox_exporter", + Name: "config_last_reload_successful", + Help: "Blackbox exporter config loaded successfully.", + }) + + configReloadSeconds = prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: "blackbox_exporter", + Name: "config_last_reload_success_timestamp_seconds", + Help: "Timestamp of the last successful configuration reload.", + }) +) + +func init() { + prometheus.MustRegister(configReloadSuccess) + prometheus.MustRegister(configReloadSeconds) +} + type Config struct { Modules map[string]Module `yaml:"modules"` } @@ -24,6 +44,14 @@ type SafeConfig struct { func (sc *SafeConfig) ReloadConfig(confFile string) (err error) { var c = &Config{} + defer func() { + if err != nil { + configReloadSuccess.Set(0) + } else { + configReloadSuccess.Set(1) + configReloadSeconds.SetToCurrentTime() + } + }() yamlFile, err := ioutil.ReadFile(confFile) if err != nil {