Monitorex.Alerts
(monitorex v0.6.0)
Copy Markdown
Threshold-based alert evaluation for Monitorex.
Runs during the Collector cleanup cycle and fires notifiers when
metrics exceed configured thresholds. Debounce prevents repeated
alerts within a configurable min_interval.
Configuration
config :monitorex, :alerts, [
%{
name: "High error rate",
metric: :error_rate,
op: :gt,
threshold: 0.05,
window_seconds: 300,
min_interval_seconds: 300,
notifiers: [
webhook: "https://hooks.example.com/alerts",
slack: "https://hooks.slack.com/services/...",
discord: "https://discord.com/api/webhooks/...",
email: "ops@example.com"
]
}
]Supported metrics
:error_rate— host-level error rate (errors / requests, float 0.0–1.0):avg_latency_ms— host-level average latency in ms:p99_latency_ms— host-level p99 latency in ms:requests_per_min— host-level request rate:host_down— no events from a host forwindow_seconds
Supported operators
:gt— greater than threshold:lt— less than threshold
Runtime API
list_rules/0— list current alert rulesadd_rule/1— add a rule at runtimeremove_rule/1— remove by name
Summary
Functions
Add an alert rule at runtime.
Returns a specification to start this module under a supervisor.
Evaluate all configured alerts against current ETS data.
List all current alert rules (config + runtime).
Remove a runtime alert rule by name.
Functions
@spec add_rule(map()) :: :ok
Add an alert rule at runtime.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec evaluate() :: [map()]
Evaluate all configured alerts against current ETS data.
Returns a list of triggered alert maps (or empty list).
Only fires alerts that haven't fired within their min_interval_seconds.
@spec list_rules() :: [map()]
List all current alert rules (config + runtime).
@spec remove_rule(String.t()) :: :ok | :not_found
Remove a runtime alert rule by name.