mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-10-18 18:49:05 +02:00
Split alerts/alerts.libsonnet into one file per collector under alerts/, like kubernetes-mixin. Each rule is a plain Prometheus alerting rule with the PromQL written out in an expr block and %(name)s placeholders for the _config values; lib/alerts.libsonnet keeps the collector and per-alert gating and keep_firing_for. The pagefile, diskdrive and license alerts get groups of their own so that one file is one group. The rendered default rules are unchanged apart from expr block scalars. Signed-off-by: Jan-Otto Kröpke <mail@jkroepke.de>
24 lines
1.4 KiB
Jsonnet
24 lines
1.4 KiB
Jsonnet
// Helpers shared by the alert files in alerts/. Takes the mixin _config.
|
|
function(c)
|
|
{
|
|
// A collector missing from a replaced collectors object counts as disabled;
|
|
// an alert missing from a replaced alerts object counts as enabled.
|
|
collectorEnabled(collector): std.get(c.collectors, collector, false),
|
|
alertEnabled(name): std.get(c.alerts, name, true),
|
|
// group renders the rules of one collector as a rule group, or nothing
|
|
// when none of them is enabled. Each rule is a plain Prometheus alerting
|
|
// rule plus two hidden fields: collectors:: lists the collectors the rule
|
|
// reads when it differs from the group's, and state:: true marks state
|
|
// alerts (== 0, == 1) and one-shot alerts, which must resolve at once.
|
|
// Every other alert is a threshold alert and keeps firing for
|
|
// keepFiringFor after its condition clears, so a value oscillating around
|
|
// the threshold does not flap.
|
|
group(name, collectors, rules):
|
|
local enabled = [
|
|
rule + (if c.keepFiringFor != '' && !std.get(rule, 'state', false) then { keep_firing_for: c.keepFiringFor } else {})
|
|
for rule in rules
|
|
if self.alertEnabled(rule.alert) && std.all([self.collectorEnabled(collector) for collector in std.get(rule, 'collectors', collectors)])
|
|
];
|
|
if std.length(enabled) > 0 then [{ name: name, rules: enabled }] else [],
|
|
}
|