mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add metrics for rule group interval and last duration.
This commit is contained in:
parent
0a42a9fc8f
commit
b97f4cf48c
|
@ -241,6 +241,7 @@ func main() {
|
||||||
NotifyFunc: sendAlerts(notifier, cfg.web.ExternalURL.String()),
|
NotifyFunc: sendAlerts(notifier, cfg.web.ExternalURL.String()),
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
ExternalURL: cfg.web.ExternalURL,
|
ExternalURL: cfg.web.ExternalURL,
|
||||||
|
Registerer: prometheus.DefaultRegisterer,
|
||||||
Logger: log.With(logger, "component", "rule manager"),
|
Logger: log.With(logger, "component", "rule manager"),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,18 @@ var (
|
||||||
Name: "rule_group_iterations_total",
|
Name: "rule_group_iterations_total",
|
||||||
Help: "The total number of scheduled rule group evaluations, whether executed or missed.",
|
Help: "The total number of scheduled rule group evaluations, whether executed or missed.",
|
||||||
})
|
})
|
||||||
|
lastDuration = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, "", "rule_group_last_duration_seconds"),
|
||||||
|
"The duration of the last rule group evaulation.",
|
||||||
|
[]string{"rule_group"},
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
groupInterval = prometheus.NewDesc(
|
||||||
|
prometheus.BuildFQName(namespace, "", "rule_group_interval_seconds"),
|
||||||
|
"The interval of a rule group.",
|
||||||
|
[]string{"rule_group"},
|
||||||
|
nil,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -444,17 +456,22 @@ type ManagerOptions struct {
|
||||||
Context context.Context
|
Context context.Context
|
||||||
Appendable Appendable
|
Appendable Appendable
|
||||||
Logger log.Logger
|
Logger log.Logger
|
||||||
|
Registerer prometheus.Registerer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager returns an implementation of Manager, ready to be started
|
// NewManager returns an implementation of Manager, ready to be started
|
||||||
// by calling the Run method.
|
// by calling the Run method.
|
||||||
func NewManager(o *ManagerOptions) *Manager {
|
func NewManager(o *ManagerOptions) *Manager {
|
||||||
return &Manager{
|
m := &Manager{
|
||||||
groups: map[string]*Group{},
|
groups: map[string]*Group{},
|
||||||
opts: o,
|
opts: o,
|
||||||
block: make(chan struct{}),
|
block: make(chan struct{}),
|
||||||
logger: o.Logger,
|
logger: o.Logger,
|
||||||
}
|
}
|
||||||
|
if o.Registerer != nil {
|
||||||
|
o.Registerer.MustRegister(m)
|
||||||
|
}
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts processing of the rule manager.
|
// Run starts processing of the rule manager.
|
||||||
|
@ -627,3 +644,25 @@ func (m *Manager) AlertingRules() []*AlertingRule {
|
||||||
}
|
}
|
||||||
return alerts
|
return alerts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implements prometheus.Collector.
|
||||||
|
func (m *Manager) Describe(ch chan<- *prometheus.Desc) {
|
||||||
|
ch <- lastDuration
|
||||||
|
ch <- groupInterval
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implements prometheus.Collector.
|
||||||
|
func (m *Manager) Collect(ch chan<- prometheus.Metric) {
|
||||||
|
for _, g := range m.RuleGroups() {
|
||||||
|
ch <- prometheus.MustNewConstMetric(lastDuration,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
g.GetEvaluationTime().Seconds(),
|
||||||
|
groupKey(g.file, g.name))
|
||||||
|
}
|
||||||
|
for _, g := range m.RuleGroups() {
|
||||||
|
ch <- prometheus.MustNewConstMetric(groupInterval,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
g.interval.Seconds(),
|
||||||
|
groupKey(g.file, g.name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue