Class AlertRule
AlertRule backlog = Alert.named("queue-backing-up")
.on("rabbitmq_detailed_queue_messages_ready")
.above(1000)
.lasting(Duration.ofMinutes(5))
.severity(Severity.WARNING)
.because("a queue is deep and not draining")
.build();
List<AlertEvent> firing = backlog.evaluate(metrics); // now, in this process
String yaml = backlog.toPrometheusRule(); // and for Prometheus
Why both
The same rule evaluates in-process and renders as a Prometheus alerting rule. That is the point of the class: a deployment gate, a health endpoint and the on-call alert otherwise express the same intention in three places, in two languages, and drift apart — and the way you find out is an incident that nothing paged for because the threshold in Prometheus was changed a year ago and the health check was not.
What this is not
Not a replacement for Prometheus and Alertmanager. Evaluating here reads
one scrape, in one process, with no history, no deduplication, no silencing and no routing.
Alert.lasting(Duration) cannot be honoured by a single snapshot at all — it is carried
into the generated rule, where a real time-series database can evaluate it, and
evaluate(org.acemq.rabbitmq.admin.metrics.MetricsSnapshot) says so rather than pretending.
Use the in-process evaluation for a check with a clear answer now: is this deployment safe, is this broker healthy, should this CLI print red. Use the generated rule for the things that need to be true over time.
-
Method Summary
Modifier and TypeMethodDescriptionbecause()evaluate(MetricsSnapshot metrics) Checks this rule against one scrape.booleanisFiring(MetricsSnapshot metrics) lasting()metric()name()severity()Renders this rule as Prometheus alerting-rule YAML.toString()
-
Method Details
-
evaluate
Checks this rule against one scrape.- Parameters:
metrics- a snapshot- Returns:
- one event per label combination that breached — so one per queue, not one for the broker. An empty list means nothing is firing
-
isFiring
- Parameters:
metrics- a snapshot- Returns:
- whether anything breached
-
toPrometheusRule
Renders this rule as Prometheus alerting-rule YAML.The half that
evaluate(org.acemq.rabbitmq.admin.metrics.MetricsSnapshot)cannot do:for:needs history, and this is whereAlert.lasting(Duration)becomes real.- Returns:
- a YAML fragment for a
groups[].rules[]list
-
toAlertName
- Returns:
- the rule's name in the form Prometheus conventionally uses
-
name
-
metric
-
companionMetric
- Returns:
- the metric that must read zero alongside
metric(), or null if there is none
-
severity
-
because
- Returns:
- why this matters, in a sentence somebody woken at 3am can act on
-
conditionText
- Returns:
- how the threshold reads, for a message
-
lasting
- Returns:
- how long it must hold. Zero means "now", and only the generated rule can honour it
-
toString
-