Skip to content

Commit

Permalink
Add metric successful_config_load
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Shatford <[email protected]>
  • Loading branch information
Ryan Shatford committed Jan 31, 2019
1 parent 6958e6f commit 72a36fd
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (

yaml "gopkg.in/yaml.v2"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/config"
)

var configReloadSuccess prometheus.Gauge

type Config struct {
Modules map[string]Module `yaml:"modules"`
}
Expand All @@ -22,22 +25,34 @@ type SafeConfig struct {
C *Config
}

func init() {
configReloadSuccess = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "successful_config_load",
Help: "Blackbox exporter config loaded successfully",
})
prometheus.MustRegister(configReloadSuccess)
}

func (sc *SafeConfig) ReloadConfig(confFile string) (err error) {
var c = &Config{}

yamlFile, err := ioutil.ReadFile(confFile)
if err != nil {
configReloadSuccess.Set(0)
return fmt.Errorf("error reading config file: %s", err)
}

if err := yaml.UnmarshalStrict(yamlFile, c); err != nil {
configReloadSuccess.Set(0)
return fmt.Errorf("error parsing config file: %s", err)
}

sc.Lock()
sc.C = c
sc.Unlock()

configReloadSuccess.Set(1)

return nil
}

Expand Down

0 comments on commit 72a36fd

Please sign in to comment.