mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 05:34:05 -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()),
|
||||
Context: ctx,
|
||||
ExternalURL: cfg.web.ExternalURL,
|
||||
Registerer: prometheus.DefaultRegisterer,
|
||||
Logger: log.With(logger, "component", "rule manager"),
|
||||
})
|
||||
|
||||
|
|
|
@ -81,6 +81,18 @@ var (
|
|||
Name: "rule_group_iterations_total",
|
||||
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() {
|
||||
|
@ -444,17 +456,22 @@ type ManagerOptions struct {
|
|||
Context context.Context
|
||||
Appendable Appendable
|
||||
Logger log.Logger
|
||||
Registerer prometheus.Registerer
|
||||
}
|
||||
|
||||
// NewManager returns an implementation of Manager, ready to be started
|
||||
// by calling the Run method.
|
||||
func NewManager(o *ManagerOptions) *Manager {
|
||||
return &Manager{
|
||||
m := &Manager{
|
||||
groups: map[string]*Group{},
|
||||
opts: o,
|
||||
block: make(chan struct{}),
|
||||
logger: o.Logger,
|
||||
}
|
||||
if o.Registerer != nil {
|
||||
o.Registerer.MustRegister(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Run starts processing of the rule manager.
|
||||
|
@ -627,3 +644,25 @@ func (m *Manager) AlertingRules() []*AlertingRule {
|
|||
}
|
||||
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