From d47e1ee5560c36dbe7c77af3ecafe624ef1c7cfb Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 4 Feb 2019 09:01:27 -0500 Subject: [PATCH] Add metric successful_config_load (#413) Signed-off-by: Ryan Shatford --- config/config.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) 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 { -- 2.25.1