Skip to content

Commit

Permalink
Merge pull request #393 from athomason/promauto-funcs
Browse files Browse the repository at this point in the history
promauto: add NewCounterFunc and NewGaugeFunc
  • Loading branch information
beorn7 authored Mar 19, 2018
2 parents c3324c1 + 660e690 commit 07e5c3c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions prometheus/promauto/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ func NewCounterVec(opts prometheus.CounterOpts, labelNames []string) *prometheus
return c
}

// NewCounterFunc works like the function of the same name in the prometheus
// package but it automatically registers the CounterFunc with the
// prometheus.DefaultRegisterer. If the registration fails, NewCounterFunc
// panics.
func NewCounterFunc(opts prometheus.CounterOpts, function func() float64) prometheus.CounterFunc {
g := prometheus.NewCounterFunc(opts, function)
prometheus.MustRegister(g)
return g
}

// NewGauge works like the function of the same name in the prometheus package
// but it automatically registers the Gauge with the
// prometheus.DefaultRegisterer. If the registration fails, NewGauge panics.
Expand All @@ -165,6 +175,15 @@ func NewGaugeVec(opts prometheus.GaugeOpts, labelNames []string) *prometheus.Gau
return g
}

// NewGaugeFunc works like the function of the same name in the prometheus
// package but it automatically registers the GaugeFunc with the
// prometheus.DefaultRegisterer. If the registration fails, NewGaugeFunc panics.
func NewGaugeFunc(opts prometheus.GaugeOpts, function func() float64) prometheus.GaugeFunc {
g := prometheus.NewGaugeFunc(opts, function)
prometheus.MustRegister(g)
return g
}

// NewSummary works like the function of the same name in the prometheus package
// but it automatically registers the Summary with the
// prometheus.DefaultRegisterer. If the registration fails, NewSummary panics.
Expand Down

0 comments on commit 07e5c3c

Please sign in to comment.