Add metric successful_config_load (#413)
authorRyan <ev1lm0nk3y@users.noreply.github.com>
Mon, 4 Feb 2019 14:01:27 +0000 (09:01 -0500)
committerBrian Brazil <brian.brazil@robustperception.io>
Mon, 4 Feb 2019 14:01:27 +0000 (14:01 +0000)
Signed-off-by: Ryan Shatford <ryan.shatford@tapad.com>
config/config.go

index ea927785d19872920755b775527dde8f4b9ee45b..afb7ecf8c08082b9acb5ba31ba66fe5863c3f7a8 100644 (file)
@@ -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 {