Loki alerting rules with Alertmanager: when a log-based alert belongs in the ruler
If you want alerts on log patterns such as application errors, failed logins or missing heartbeats in a self-hosted Loki cluster, the path is Loki's ruler, which evaluates LogQL alert rules and forwards firing alerts to Alertmanager. The ruler is one of Loki's components, and where it runs depends on your deployment mode. In the monolithic mode it runs inside the single binary, while in the simple scalable and microservices modes it is a separate read or backend target, so your sizing and failure planning must account for it as its own workload.
The ruler path fits when you want the alert rules to live next to the log data in Loki and be stored as files your team can version, review and deploy with the rest of the stack. It also fits when Alertmanager is already your routing point for Prometheus alerts, so on-call teams receive log and metric alerts through one set of grouping, silencing and receiver rules. The alternative, Grafana-managed alerts, suits cases where one rule must combine several data sources or where you need fine control over no-data and error states in the Grafana interface. Confirm which Loki components your chosen deployment mode runs before you commit to this path, and check the current deployment mode guidance in the Loki deployment modes documentation.
Decide early which alerts you need and who owns them, because that decision determines where the rules are stored and how they are reviewed. A rule for failed logins that a security team maintains may belong in a different tenant or rule namespace than a platform team's heartbeat check. Confirm with your Loki and Alertmanager owners how tenant IDs map to alert routing before writing the first rule, since the ruler evaluates rules per tenant and Alertmanager routes by the labels you attach.
How a LogQL rule travels from Loki to Alertmanager
The flow starts with log writers sending entries through the Loki write path into object storage, where chunks and the index are kept. The ruler, a separate Loki component, reads rule groups from rule storage and evaluates each LogQL expression against the read path. Firing alerts leave the ruler for the Alertmanager cluster, which groups, silences and routes them to receivers. The dashed trust boundary marks what you must secure: the Loki cluster endpoints and every Alertmanager endpoint, which Prometheus-style senders must reach in full.
Log entries, rule evaluation and alert delivery across the Loki and Alertmanager trust boundaries.
How LogQL alert rules are structured: groups, expressions, for durations and labels
A LogQL alert rule has five keys that matter: alert, expr, for, labels and annotations. Rules sit inside a rule group, which is a named list that the Loki ruler evaluates together on one interval. The interval sets how often each rule's expr runs, so it controls how quickly a problem can be detected and how much query load the ruler adds. The expr must be a metric query, not a plain log query, because the ruler needs a numeric result per label set. Illustrative only, not a tested file: groups: [{name: app-auth, interval: 1m, rules: [{alert: HighAuthFailures, expr: 'sum by (service) (count_over_time({app="api"} |= "authentication failed" [5m])) > 20', for: 5m, labels: {severity: warning, team: platform}, annotations: {summary: 'Authentication failures high on {{ $labels.service }}'}}]}]. Confirm the group, interval and expression syntax against the Loki version you run, since the ruler file format is version-sensitive.
The for duration decides how long the condition must hold before the alert fires. When the expression first returns results, the alert is pending; it fires only after the condition has stayed true for the full for period. This is the main control against short spikes, such as a brief burst of failed logins during a deploy. A for value that is too short produces alerts that flap on and off, while one that is too long delays detection of a real incident. Choose the value per alert, based on what the signal means for your service, and test it against a period of known-bad logs before relying on it. Check how the Loki ruler handles pending state and resolved notifications in your version's documentation before you set alerting service levels around it.
Labels and annotations do different jobs. Labels are the routing keys: values such as severity and team are attached to the alert and matched by the route tree in Alertmanager, which decides who is notified and how alerts are grouped. Labels returned by the expr are carried through automatically, so keep those label sets small and consistent, or every distinct value creates a separate alert. Annotations such as summary and description are human-readable text for the notification and may include templated label values, but Alertmanager does not use them for routing or grouping. Agree on a shared label vocabulary with the teams that receive alerts before writing rules, and confirm which label names your Alertmanager configuration expects.
Configuration options and when each fits
The Loki ruler reads alerting rules from storage that you configure, and the choice shapes how rules are edited, backed up and reloaded. Object storage keeps rule files with the other data Loki depends on and suits clusters where several ruler replicas must read the same rule set. A local ruler directory is simpler to inspect on a single server, but each replica holds its own copy, so every change must reach every instance.
- Object storage: rules sit in a bucket that replicas can all read, giving one source of truth. Confirm the ruler storage keys for your release in the Loki storage documentation.
- Local ruler directory: rule files live on the ruler's filesystem, which suits Git-driven review but needs a sync step to each replica.
- Rule group files: each file holds named groups with evaluation intervals and rules, so splitting files by team or service keeps reviews small.
- Reload behavior: confirm how and when your release picks up changed rule files and whether a restart is required.
- Backup: include rule storage in your backup plan, because rules are operational configuration that is easy to lose.
Before relying on a rule for paging, check the storage key names, the bucket permissions and whether every ruler replica loads the same rules.
The ruler sends firing alerts to Alertmanager at addresses set in its configuration. Alertmanager's documentation describes running it as a cluster with its --cluster flags, and it recommends that senders point at every Alertmanager instance rather than at a load balancer. Whether the Loki ruler follows the same pattern depends on the release, so confirm the endpoint behavior before you design the path.
- Instance list: list each Alertmanager address so the sender reaches every instance, which is the pattern Alertmanager's documentation describes for Prometheus senders.
- Load balancer: confirm whether your Loki release documents a load balancer in front of Alertmanager before you add one.
- Cluster peering: Alertmanager instances peer through their cluster flags, which lets a cluster avoid sending the same notification once per instance.
- Network path: make sure the ruler can reach each Alertmanager port, and set any TLS or authentication options in the ruler configuration.
- Test alert: fire a deliberately failing rule and confirm the notification arrives once, not once per replica.
Verify the Alertmanager address key and the notification behavior for your Loki version in a test environment before go-live.
When auth_enabled is true, Loki identifies each request's tenant with the X-Scope-OrgID header, and rules follow the same tenant model. A rule evaluates against its tenant's logs, so a rule written for one team should not see another team's streams. Confirm how your release stores rules per tenant, including the path layout under rule storage, and how alerts carry tenant identity before they reach Alertmanager.
- Per-tenant rule sets: store each tenant's rules under its identifier so ownership is clear and changes stay within one team's scope.
- Tenant isolation test: confirm that a rule under one tenant returns only that tenant's log lines.
- Tenant label on alerts: add the tenant as a label so Alertmanager can route each team's alerts to its own receiver.
- Platform-wide checks: confirm how cross-tenant access is controlled in open-source Loki, since label-based access control is a feature of Grafana Enterprise Logs.
- Authentication in front: the X-Scope-OrgID header identifies a tenant but does not authenticate the caller, so an authenticating proxy must set or validate it.
Before onboarding a second team, test tenant isolation for rules and confirm that the tenant label reaches Alertmanager intact.
Alert routing decisions can live in two places: the labels and annotations set on each rule, and the routing tree, grouping, inhibition and silences configured in Alertmanager. Put stable identity such as service, team and severity into rule labels so every downstream system reads the same meaning. Keep notification destinations, timing and suppression in Alertmanager, where operators can change them without editing rules.
- Rule labels: set severity, team and service on the rule so any receiver can route on them.
- Annotations: place summaries and runbook references in annotations for the people reading a notification, not for routing decisions.
- Grouping: Alertmanager's grouping settings decide which alerts arrive together, which is the main lever for reducing notification noise.
- Inhibition and silences: suppress dependent alerts and planned maintenance in Alertmanager, where on-call staff can manage them during an incident.
- Shared vocabulary: agree label names across teams, because a mismatched label silently sends alerts to the wrong route.
Review the rule label set and the Alertmanager route tree together, and confirm that each test alert reaches exactly one intended team.
Ruler and Alertmanager settings compared
This table compares the ruler and Alertmanager settings that change how log alerts fire, group and reach people. Read each row as a question to answer for your environment: what the setting controls, when to change it, and what to check after the change. The main takeaway is that the evaluation interval, for duration and Alertmanager endpoints are the settings most often misconfigured in ways that only show up during an incident.
| Setting | What it controls | When to change it | What to verify |
|---|---|---|---|
| Evaluation interval | How often the Loki ruler runs each rule group's LogQL expressions | When alerts must fire faster, or when a heavy query is loading the query path and needs a longer interval | Rule evaluation duration and missed evaluations in ruler metrics, and the actual time between alert firings |
| For duration | How long a condition must stay true before an alert moves from pending to firing | When brief log bursts cause noisy pages, or when a sustained error pattern must page without delay | Test with a synthetic log burst in a non-production tenant and confirm the alert fires only after the chosen period |
| Group naming | The rule group name, which scopes evaluation and appears in alert metadata and rule file layout | When splitting rules by team, tenant or service so ownership and evaluation load are clear | Group names are unique within each file and the ruler loads every group without errors in its logs |
| Alertmanager endpoint list | Which Alertmanager instances the ruler sends firing alerts to | When adding Alertmanager instances to an HA cluster or moving to a new alert routing tier | Every Alertmanager instance in the list receives test alerts, since the Alertmanager docs say Prometheus should point at each instance rather than a load balancer |
| External labels | Labels attached to alerts that identify the source cluster or environment for routing and deduplication | When several Loki clusters send alerts to one Alertmanager and need to be told apart | Test alerts arrive with the expected cluster and environment labels, and routes match on them |
| Receiver routing | Which receiver gets an alert based on its labels, plus grouping, inhibition and silences in Alertmanager | When severity, team or tenant labels should decide who is paged or ticketed | Send a test alert for each severity and team pair and confirm the receiver, grouping and silence behavior |
| Alert annotations | The summary and description text shown to responders, often with links to a dashboard or runbook | When responders need context such as the LogQL query, tenant or runbook location | Annotation templates render with real label values in the notification the on-call engineer receives |
Setting up the ruler and Alertmanager in order
This sequence takes a team from an existing Loki deployment to a verified path where a LogQL alert rule is evaluated by the ruler, delivered to Alertmanager and routed to a receiver. Each step ends with a check so problems surface before the next layer is added.
Confirm deployment mode and ruler component
Your platform or Loki engineer confirms which deployment mode the cluster runs (monolithic, simple scalable or microservices) and whether the ruler is enabled and reachable as its own target or process. Deployment modes differ in how the ruler is packaged, so check the Loki deployment modes documentation for your version before editing any configuration. The step is done when you can name the ruler component, the target that runs it, and the version of Loki in use. Note that simple scalable mode is being deprecated and will be removed with Loki 4.0, so record that constraint now if you use it.
Choose and configure rule storage
Decide where rule files live: a local filesystem path for a single server, or object storage for a cluster where several ruler replicas must read the same rules. Your storage engineer sets the ruler storage block in the Loki configuration and creates the bucket or directory with the access rights the ruler needs. Confirm the exact configuration keys against the Loki storage documentation for your release, because key names change between versions. The step is done when the ruler starts cleanly and reports that it can list the rule namespace and tenant it is configured for.
Write and validate one rule group
Write a single rule group in a YAML file under the configured rule path. Include a group name, an evaluation interval, and one alerting rule with a LogQL expression, a
forduration, and labels and annotations that identify the service and the runbook. Start with a rule that matches a log pattern you already see in production so you can tell whether it fires for the right reason. Validate the file with the Loki tooling available in your release before loading it. The step is done when the rule group loads without parse errors and the ruler lists it as active for the tenant.Point the ruler at every Alertmanager instance
Add each Alertmanager instance address to the ruler's Alertmanager URL setting, one entry per instance. Prometheus guidance is to list every Alertmanager instance rather than place a load balancer in front of them, because Alertmanager clusters coordinate deduplication and silences between peers. Your platform engineer confirms that each instance is reachable from the ruler network path and that DNS or service discovery resolves all of them. The step is done when the ruler logs show successful connections to every listed instance, and Alertmanager's status page shows the expected cluster members.
Configure Alertmanager receivers and grouping
Define the route tree in Alertmanager with grouping labels that match how your on-call teams split work, such as service or team. Add at least one receiver, for example an email or chat integration your organization already operates, and set the default route and any child routes. If you run more than one Alertmanager, use the same configuration on each instance and confirm the cluster flags are set as the Alertmanager documentation describes. The step is done when Alertmanager accepts the configuration and the routing preview sends a sample label set to the intended receiver.
Fire a test alert end to end
Trigger the rule with a controlled log event in a non-production tenant, or temporarily lower the threshold for the test, and wait through the configured
forduration. Confirm the alert appears as firing in the ruler's rule view, then in Alertmanager, then arrives at the receiver with the expected labels and annotations. Record the time between the log event and the notification so you can compare it with later runs. Restore the production threshold and delete the test event afterward. The step is done when the notification arrives at the intended receiver with the correct routing, and the alert resolves once the condition clears.
Securing rule storage, tenant boundaries and Alertmanager access
Alert rules and the endpoints that evaluate and deliver them reveal how your systems behave and who gets paged. The cards below cover what to protect in rule storage, how tenant boundaries apply to rules, how to put authentication in front of the ruler and Alertmanager, where receiver credentials belong, and how to audit changes.
Rule files reveal internal detail
Alert rules often contain internal service names, hostnames, log label values, error strings and thresholds. Anyone who can read the rule files learns how your platform fails and which failures are considered urgent. Store rule files in a location with restricted read access, review them for sensitive content before they are committed, and keep descriptions generic where a reader outside the operations team could see them.
Loki storage docsTenant isolation for per-tenant rules
When auth_enabled is true, Loki identifies each tenant with the X-Scope-OrgID header, and rules can be scoped to a tenant. Check that one team cannot write or read another team's rule group, that rule names do not collide across tenants, and that the component sending rule API requests sets the tenant header from a trusted source rather than from client input.
Authenticating the ruler and Alertmanager
Loki has no built-in authentication layer, so the ruler API and any endpoint exposed for it must sit behind an authenticating reverse proxy such as nginx, HAProxy, OAuth2 Proxy or Pomerium. Confirm that no ruler or Alertmanager port is reachable from outside the cluster network, and that Alertmanager's own web and API endpoints are not published without authentication, since silences and configuration can be changed through them.
Loki authentication docsReceiver credentials and secret handling
Alertmanager receivers need credentials for chat, paging and ticketing webhooks, and these are often placed in plain text in the configuration file. Keep receiver tokens in a secrets store or in files mounted with restricted permissions, rotate them on a schedule your security team defines, and confirm that the Alertmanager configuration is not copied into shared dashboards, tickets or logs during troubleshooting.
Alertmanager endpoint exposure
Prometheus should point at every Alertmanager instance in a cluster rather than at a load balancer, which means the sending path from the ruler to Alertmanager runs over internal addresses. Verify which networks can reach Alertmanager's cluster port, confirm that cluster traffic is isolated from user networks, and check that a compromised rule evaluator cannot send arbitrary notifications to external receivers without review.
Alertmanager docsAudit trail for rule changes
Every change to a log alert rule should be traceable to an author, a reason and a review. Keep rule files in version control with required review, record deployment events, and retain Alertmanager and ruler logs long enough for your audit requirements. Ask your team which evidence an auditor would request, such as the approval history of a threshold change, and confirm that your setup can produce it.
Loki multi-tenancy docsQuestions teams ask before building Loki alert rules
What drives the cost of building Loki alert rules with Alertmanager?
The cost follows the written scope, and the main drivers are the number of rules, the size of the Loki deployment that evaluates them, the Alertmanager setup and the receivers that page people or open tickets. Each rule needs a LogQL expression tested against real log volume, a for duration that suits the signal, and labels and annotations that route and explain the alert. Alertmanager high availability adds work because Prometheus must point at every Alertmanager instance rather than a load balancer, and the cluster needs to be configured and tested. Ask any partner to split the quote into one-time build work (rule design, testing, routing, documentation) and recurring work (rule tuning, Loki and Alertmanager upgrades, on-call changes). The Loki and Alertmanager components themselves run on infrastructure you pay for. Prometheus has no paid enterprise edition, so license cost is not the driver.
How long does a first working Loki alert rule set take?
The timeline depends on how many alerts you need, how well the log labels are already structured and how many receivers must be wired up. A small set of rules against logs that already carry consistent labels is a far shorter job than a set that needs new log parsing, new label design and integration with several paging tools. Before work starts, confirm the Loki version you run and whether the ruler is already enabled, because those choices change the setup steps. Any duration a partner quotes should be written into the fixed scope with its assumptions listed, including who approves each rule and how many test cycles are included. The Prometheus release cycle is relevant only if you run Alertmanager alongside Prometheus metrics, so check which versions your environment already standardizes on.
What must our team provide before alert rules can be built?
You need to provide the log streams and their labels, the on-call routing rules, and access to the Alertmanager configuration and its receivers. Labels are the foundation: LogQL alerts select streams by label, so the team should list the labels that exist today (application, environment, namespace, tenant) and flag any that are inconsistent. On-call routing needs the teams, escalation paths, maintenance windows and the severity each alert should carry. The partner also needs a test environment or a safe window in production, read access to the Loki and Alertmanager configuration, and a named owner who can approve rule changes. Alertmanager access is needed to set grouping, inhibition and silences, and to confirm which instances Prometheus targets. Without these inputs, rules tend to be written from assumptions and then rewritten.
Can an internal platform team write and run these alert rules alone?
Yes, a team that already runs Loki and Alertmanager can write and operate its own rules, provided someone owns LogQL, the label scheme and the on-call routing. The main risks are untested expressions that fire too often, missing for durations that cause flapping, and routing that sends pages to the wrong people. Teams usually need time to learn how the ruler evaluates rules, where rule files are stored and how Alertmanager groups alerts before they can run the set without help. Decide who will review each rule, who holds the on-call escalation paths and who responds when a rule is noisy. A partner is useful when the team lacks that bandwidth or needs an outside review of the design. Ask any partner to state what it will hand over so your team can maintain the rules after the engagement ends.
How does Loki log alerting differ from a SIEM?
Loki alert rules watch operational log patterns, such as error rates, failed jobs or a service that stops logging, and send them to Alertmanager for routing to on-call teams. A SIEM collects security events from many sources, correlates them across time and users, and supports case management for investigations. LogQL alert rules can catch authentication failures or privilege changes in logs you already store, but they do not replace a SIEM's detection content, retention for investigations or correlation across products. Choose Loki for operational alerts and a simple set of security signals, and keep a SIEM where correlation and investigation workflows matter. If your compliance program depends on specific event coverage, confirm with your auditor and your SIEM vendor which system is the record of those detections.
What ongoing work follows after the alert rules go live?
Once rules are live, the recurring work is tuning noisy alerts, adding rules for new services, reviewing routing when on-call teams change and keeping Loki and Alertmanager on supported versions. Rule tuning usually takes the most attention in the first weeks, because real traffic shows which thresholds and for durations need adjusting. Upgrades matter too: Loki release notes and upgrade guides can change configuration, and Alertmanager changes can affect routing, so test each upgrade against your rule set. Ask any partner whether ongoing support is a retainer, what response it covers and who approves rule changes. Confirm your own support model before go-live, including who gets paged when the ruler or Alertmanager itself fails.
Where are the Loki alert rule files stored and how are they loaded?
Rule files are stored with the Loki ruler, and the storage location is a configuration decision your team must confirm for its Loki version and deployment mode. Teams commonly keep rule definitions in version control and deploy them through a pipeline, so that every change is reviewed and reversible. Confirm which storage backend the ruler reads from, how rule groups are organized and whether your deployment mode supports the ruler as you expect. Note that simple scalable deployment mode is being deprecated and will be removed with the Loki 4.0 release, so plan rule storage with that change in mind. Keep rule groups small and named by owning team so that alerts can be traced back to a person on call.
Operating alert rules after launch: testing, versioning and drift
The main risk after an alert rule goes live is not that it fails to deploy, but that nobody can say why it changed, what it was tested against, or whether it still matches the logs it watches. Keep every rule file in Git, so each change has an author, a review and a revision you can roll back to. Treat the ruler's rule storage as a deployment target, not an editing surface. If someone edits a rule through an API or a manual upload, the file in Git no longer describes what is running, and that gap is what drift means in practice. Confirm with your own pipeline whether a reconciliation step detects and reverts out-of-band changes, because the ruler will accept them.
Test each LogQL expression against historical logs before it is enabled. Run the query over a window that contains known incidents and known quiet periods, then count how often it would have fired. A rule that matched a failed login spike in one tenant may also match routine deploy noise in another, and only historical data shows that. Check the label set on each result, since the labels on a firing alert decide how Alertmanager groups it and who gets routed it. Record the window, the expected outcome and the result in the change request so the reviewer can repeat the check.
Review firing volume for a period after launch and use it to adjust the for duration, thresholds and label sets. A short for value turns brief spikes into pages, while a long one can hide a sustained fault until it is already costly. Tune against what the on-call team actually acts on, and note which alerts were acknowledged without action. For maintenance, create Alertmanager silences with a stated owner and expiry, and use inhibition rules for dependent alerts so one root cause does not produce a page for every symptom. Alertmanager can run as a cluster, and Prometheus should point at every instance rather than a load balancer, so confirm that your silences and inhibition rules are applied on each one. Expired silences should be reviewed, not left in place.
How DeployOpen scopes and delivers Loki alerting rules
DeployOpen plans Loki alerting rules as part of the wider log platform, starting from the alerts your teams need and the Alertmanager routing they already use. The work runs inside your own infrastructure, with rule files, routing and access handled as reviewable deliverables.
How we scope
- The written scope lists which log patterns become alerts, the owning team for each rule and the expected notification path.
- We confirm where rule files will live, which tenants or environments the ruler serves and who may change rules.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before any build work starts.
How we build
- We write LogQL alert rules in rule groups with for durations, labels and annotations reviewed against real log volume.
- We configure the ruler to send firing alerts to your Prometheus Alertmanager instances, covering every instance you run.
- We test each rule against known log samples, confirm routing, grouping and silences, and record the results.
How we hand over
- You receive rule files, Alertmanager configuration, a runbook for each alert and the test evidence behind them.
- We document how rule files are stored, versioned and deployed, so changes follow your existing review process.
- Handover includes a walkthrough with the operators who will receive alerts and maintain the rules afterward.
How we support
- Ongoing support, upgrades and continuous testing of alert rules are available as a retainer after handover.
- Retainers can cover rule tuning after noisy alerts, Loki and Alertmanager version upgrades and new alert requests.
- Ask any provider to confirm how rule changes, rollbacks and on-call notifications are handled during support.

