Skip to content

Commit

Permalink
Add metric successful_config_load (#413)
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Shatford <[email protected]>
  • Loading branch information
ev1lm0nk3y authored and brian-brazil committed Feb 4, 2019
1 parent 6958e6f commit d47e1ee
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand All @@ -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 {
Expand Down

0 comments on commit d47e1ee

Please sign in to comment.