mirror of
https://github.com/prometheus/prometheus
synced 2024-12-25 07:52:28 +00:00
Expose rules.NewGroupMetrics and rules.Metrics. (#5059)
Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
This commit is contained in:
parent
6e08029b56
commit
121603c417
@ -61,7 +61,8 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
type metrics struct {
|
||||
// Metrics for rule evaluation.
|
||||
type Metrics struct {
|
||||
evalDuration prometheus.Summary
|
||||
evalFailures prometheus.Counter
|
||||
evalTotal prometheus.Counter
|
||||
@ -72,8 +73,10 @@ type metrics struct {
|
||||
groupLastDuration *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
func newGroupMetrics(reg prometheus.Registerer) *metrics {
|
||||
m := &metrics{
|
||||
// NewGroupMetrics makes a new Metrics and registers them with then provided registerer,
|
||||
// if not nil.
|
||||
func NewGroupMetrics(reg prometheus.Registerer) *Metrics {
|
||||
m := &Metrics{
|
||||
evalDuration: prometheus.NewSummary(
|
||||
prometheus.SummaryOpts{
|
||||
Namespace: namespace,
|
||||
@ -220,14 +223,14 @@ type Group struct {
|
||||
|
||||
logger log.Logger
|
||||
|
||||
metrics *metrics
|
||||
metrics *Metrics
|
||||
}
|
||||
|
||||
// NewGroup makes a new Group with the given name, options, and rules.
|
||||
func NewGroup(name, file string, interval time.Duration, rules []Rule, shouldRestore bool, opts *ManagerOptions) *Group {
|
||||
metrics := opts.metrics
|
||||
metrics := opts.Metrics
|
||||
if metrics == nil {
|
||||
metrics = newGroupMetrics(opts.Registerer)
|
||||
metrics = NewGroupMetrics(opts.Registerer)
|
||||
}
|
||||
|
||||
metrics.groupLastEvalTime.WithLabelValues(groupKey(file, name))
|
||||
@ -684,14 +687,14 @@ type ManagerOptions struct {
|
||||
ForGracePeriod time.Duration
|
||||
ResendDelay time.Duration
|
||||
|
||||
metrics *metrics
|
||||
Metrics *Metrics
|
||||
}
|
||||
|
||||
// NewManager returns an implementation of Manager, ready to be started
|
||||
// by calling the Run method.
|
||||
func NewManager(o *ManagerOptions) *Manager {
|
||||
if o.metrics == nil {
|
||||
o.metrics = newGroupMetrics(o.Registerer)
|
||||
if o.Metrics == nil {
|
||||
o.Metrics = NewGroupMetrics(o.Registerer)
|
||||
}
|
||||
|
||||
m := &Manager{
|
||||
@ -705,7 +708,7 @@ func NewManager(o *ManagerOptions) *Manager {
|
||||
o.Registerer.MustRegister(m)
|
||||
}
|
||||
|
||||
o.metrics.iterationsMissed.Inc()
|
||||
o.Metrics.iterationsMissed.Inc()
|
||||
return m
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user