Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metric successful_config_load #413

Merged
merged 6 commits into from
Feb 4, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
ev1lm0nk3y marked this conversation as resolved.
Show resolved Hide resolved
configReloadSuccess = prometheus.NewGauge(prometheus.GaugeOpts{
ev1lm0nk3y marked this conversation as resolved.
Show resolved Hide resolved
Name: "successful_config_load",
ev1lm0nk3y marked this conversation as resolved.
Show resolved Hide resolved
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)
ev1lm0nk3y marked this conversation as resolved.
Show resolved Hide resolved
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