Skip to content

Commit

Permalink
Merge pull request #1056 from grafana/unregister_metrics
Browse files Browse the repository at this point in the history
Remove initialization of metrics from init functions
  • Loading branch information
SuperQ authored Apr 8, 2023
2 parents 46020dd + dd938b1 commit ae8455d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
10 changes: 3 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,18 @@ import (
"github.com/go-kit/log/level"
"github.com/miekg/dns"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/common/config"
)

var (
configReloadSuccess = prometheus.NewGauge(prometheus.GaugeOpts{
configReloadSuccess = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "blackbox_exporter",
Name: "config_last_reload_successful",
Help: "Blackbox exporter config loaded successfully.",
})

configReloadSeconds = prometheus.NewGauge(prometheus.GaugeOpts{
configReloadSeconds = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "blackbox_exporter",
Name: "config_last_reload_success_timestamp_seconds",
Help: "Timestamp of the last successful configuration reload.",
Expand Down Expand Up @@ -89,11 +90,6 @@ var (
}
)

func init() {
prometheus.MustRegister(configReloadSuccess)
prometheus.MustRegister(configReloadSeconds)
}

type Config struct {
Modules map[string]Module `yaml:"modules"`
}
Expand Down
7 changes: 2 additions & 5 deletions prober/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/go-kit/log/level"
"github.com/prometheus/blackbox_exporter/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/expfmt"
"gopkg.in/yaml.v2"
Expand All @@ -40,16 +41,12 @@ var (
"dns": ProbeDNS,
"grpc": ProbeGRPC,
}
moduleUnknownCounter = prometheus.NewCounter(prometheus.CounterOpts{
moduleUnknownCounter = promauto.NewCounter(prometheus.CounterOpts{
Name: "blackbox_module_unknown_total",
Help: "Count of unknown modules requested by probes",
})
)

func init() {
prometheus.MustRegister(moduleUnknownCounter)
}

func Handler(w http.ResponseWriter, r *http.Request, c *config.Config, logger log.Logger,
rh *ResultHistory, timeoutOffset float64, params url.Values) {
if params == nil {
Expand Down

0 comments on commit ae8455d

Please sign in to comment.