mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 05:47:27 -08:00
Refactor and simplify rule_group_interval_seconds (#6711)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
This commit is contained in:
parent
8b49c9285d
commit
f82d55e79f
|
@ -50,15 +50,6 @@ const (
|
||||||
// Constants for instrumentation.
|
// Constants for instrumentation.
|
||||||
const namespace = "prometheus"
|
const namespace = "prometheus"
|
||||||
|
|
||||||
var (
|
|
||||||
groupInterval = prometheus.NewDesc(
|
|
||||||
prometheus.BuildFQName(namespace, "", "rule_group_interval_seconds"),
|
|
||||||
"The interval of a rule group.",
|
|
||||||
[]string{"rule_group"},
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// Metrics for rule evaluation.
|
// Metrics for rule evaluation.
|
||||||
type Metrics struct {
|
type Metrics struct {
|
||||||
evalDuration prometheus.Summary
|
evalDuration prometheus.Summary
|
||||||
|
@ -67,6 +58,7 @@ type Metrics struct {
|
||||||
iterationDuration prometheus.Summary
|
iterationDuration prometheus.Summary
|
||||||
iterationsMissed prometheus.Counter
|
iterationsMissed prometheus.Counter
|
||||||
iterationsScheduled prometheus.Counter
|
iterationsScheduled prometheus.Counter
|
||||||
|
groupInterval *prometheus.GaugeVec
|
||||||
groupLastEvalTime *prometheus.GaugeVec
|
groupLastEvalTime *prometheus.GaugeVec
|
||||||
groupLastDuration *prometheus.GaugeVec
|
groupLastDuration *prometheus.GaugeVec
|
||||||
groupRules *prometheus.GaugeVec
|
groupRules *prometheus.GaugeVec
|
||||||
|
@ -111,6 +103,14 @@ func NewGroupMetrics(reg prometheus.Registerer) *Metrics {
|
||||||
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.",
|
||||||
}),
|
}),
|
||||||
|
groupInterval: prometheus.NewGaugeVec(
|
||||||
|
prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Name: "rule_group_interval_seconds",
|
||||||
|
Help: "The interval of a rule group.",
|
||||||
|
},
|
||||||
|
[]string{"rule_group"},
|
||||||
|
),
|
||||||
groupLastEvalTime: prometheus.NewGaugeVec(
|
groupLastEvalTime: prometheus.NewGaugeVec(
|
||||||
prometheus.GaugeOpts{
|
prometheus.GaugeOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
|
@ -145,6 +145,7 @@ func NewGroupMetrics(reg prometheus.Registerer) *Metrics {
|
||||||
m.iterationDuration,
|
m.iterationDuration,
|
||||||
m.iterationsMissed,
|
m.iterationsMissed,
|
||||||
m.iterationsScheduled,
|
m.iterationsScheduled,
|
||||||
|
m.groupInterval,
|
||||||
m.groupLastEvalTime,
|
m.groupLastEvalTime,
|
||||||
m.groupLastDuration,
|
m.groupLastDuration,
|
||||||
m.groupRules,
|
m.groupRules,
|
||||||
|
@ -248,6 +249,7 @@ func NewGroup(name, file string, interval time.Duration, rules []Rule, shouldRes
|
||||||
metrics.groupLastEvalTime.WithLabelValues(groupKey(file, name))
|
metrics.groupLastEvalTime.WithLabelValues(groupKey(file, name))
|
||||||
metrics.groupLastDuration.WithLabelValues(groupKey(file, name))
|
metrics.groupLastDuration.WithLabelValues(groupKey(file, name))
|
||||||
metrics.groupRules.WithLabelValues(groupKey(file, name)).Set(float64(len(rules)))
|
metrics.groupRules.WithLabelValues(groupKey(file, name)).Set(float64(len(rules)))
|
||||||
|
metrics.groupInterval.WithLabelValues(groupKey(file, name)).Set(interval.Seconds())
|
||||||
|
|
||||||
return &Group{
|
return &Group{
|
||||||
name: name,
|
name: name,
|
||||||
|
@ -826,10 +828,6 @@ func NewManager(o *ManagerOptions) *Manager {
|
||||||
logger: o.Logger,
|
logger: o.Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.Registerer != nil {
|
|
||||||
o.Registerer.MustRegister(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
o.Metrics.iterationsMissed.Inc()
|
o.Metrics.iterationsMissed.Inc()
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -904,6 +902,7 @@ func (m *Manager) Update(interval time.Duration, files []string, externalLabels
|
||||||
for n, oldg := range m.groups {
|
for n, oldg := range m.groups {
|
||||||
oldg.stop()
|
oldg.stop()
|
||||||
if m := oldg.metrics; m != nil {
|
if m := oldg.metrics; m != nil {
|
||||||
|
m.groupInterval.DeleteLabelValues(n)
|
||||||
m.groupLastEvalTime.DeleteLabelValues(n)
|
m.groupLastEvalTime.DeleteLabelValues(n)
|
||||||
m.groupLastDuration.DeleteLabelValues(n)
|
m.groupLastDuration.DeleteLabelValues(n)
|
||||||
m.groupRules.DeleteLabelValues(n)
|
m.groupRules.DeleteLabelValues(n)
|
||||||
|
@ -1022,18 +1021,3 @@ func (m *Manager) AlertingRules() []*AlertingRule {
|
||||||
|
|
||||||
return alerts
|
return alerts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Describe implements prometheus.Collector.
|
|
||||||
func (m *Manager) Describe(ch chan<- *prometheus.Desc) {
|
|
||||||
ch <- groupInterval
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect implements prometheus.Collector.
|
|
||||||
func (m *Manager) Collect(ch chan<- prometheus.Metric) {
|
|
||||||
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