Log inSign up

Gather and search logs with Loki and Grafana Alloy

Install loki and alloy from the Grafana APT repository, give Loki a config that listens on 127.0.0.1:3100 with filesystem storage and a retention period, and point Alloy at the systemd journal and /var/log. Add Loki as a data source in Grafana to search logs with LogQL. Promtail, the older shipper, has reached end of life, so new setups use Alloy and existing Promtail configs can be converted.

Topic: Monitoring and logs · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13 · Updated 2026-12-03

How do Loki, Alloy and Promtail relate?

Loki stores log lines and indexes only their labels, such as host, job or unit, which keeps it cheap compared with full text search engines. A separate agent reads logs on each server and pushes them to Loki over HTTP. For years that agent was Promtail. It was deprecated in early 2025 in favour of Grafana Alloy and reached end of life in early 2026, so it no longer receives fixes. Existing Promtail installs keep working, but new servers should use Alloy, and the alloy convert command translates a Promtail YAML file into Alloy syntax.

You read the logs in Grafana, ideally next to the metrics from Prometheus, so a CPU spike and the matching error lines sit on one screen.

How do I add the repository and install the packages?

Loki and Alloy are in the same APT repository as Grafana. If you already set it up for Grafana, skip the first block.

sudo apt install -y wget gpg
sudo mkdir -p /etc/apt/keyrings
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt update
sudo apt install -y loki alloy
apt policy loki alloy
loki -version | head -n 1
alloy --version

Run this on Ubuntu 24.04 or 22.04, or Debian 12 or 13. Plan disk space carefully: logs from a busy web server add up quickly, and Loki should never fill the root filesystem.

How do I configure Loki for a single server?

Replace /etc/loki/config.yml with a compact single node config. It listens on loopback only, stores data under /var/lib/loki and deletes logs older than 14 days:

auth_enabled: false

server:
  http_listen_address: 127.0.0.1
  http_listen_port: 3100
  grpc_listen_address: 127.0.0.1
  grpc_listen_port: 9096

common:
  instance_addr: 127.0.0.1
  path_prefix: /var/lib/loki
  replication_factor: 1
  ring:
    kvstore:
      store: inmemory
  storage:
    filesystem:
      chunks_directory: /var/lib/loki/chunks
      rules_directory: /var/lib/loki/rules

schema_config:
  configs:
    - from: 2024-04-01
      store: tsdb
      object_store: filesystem
      schema: v13
      index:
        prefix: index_
        period: 24h

limits_config:
  retention_period: 336h

compactor:
  working_directory: /var/lib/loki/compactor
  retention_enabled: true
  delete_request_store: filesystem
sudo mkdir -p /var/lib/loki
sudo chown -R loki:loki /var/lib/loki
sudo systemctl restart loki
sudo systemctl enable loki
curl -s http://127.0.0.1:3100/ready

The last command prints ready after a few seconds. If Loki refuses to start, sudo journalctl -u loki -n 40 names the offending line.

How do I ship journal and file logs with Alloy?

Alloy uses its own block based configuration language. Write /etc/alloy/config.alloy:

loki.write "local" {
  endpoint {
    url = "http://127.0.0.1:3100/loki/api/v1/push"
  }
  external_labels = { host = "monitor" }
}

loki.source.journal "journal" {
  forward_to    = [loki.write.local.receiver]
  relabel_rules = loki.relabel.journal.rules
  labels        = { job = "journal" }
}

loki.relabel "journal" {
  forward_to = []
  rule {
    source_labels = ["__journal__systemd_unit"]
    target_label  = "unit"
  }
}

local.file_match "varlog" {
  path_targets = [{ "__path__" = "/var/log/nginx/*.log", "job" = "nginx" }]
}

loki.source.file "varlog" {
  targets    = local.file_match.varlog.targets
  forward_to = [loki.write.local.receiver]
}

Alloy runs as its own user, which needs read access to the journal and to files owned by the adm group:

sudo usermod -aG systemd-journal,adm alloy
alloy fmt /etc/alloy/config.alloy > /dev/null && echo syntax ok
sudo systemctl restart alloy
sudo systemctl enable alloy

Alloy has a debug UI on 127.0.0.1:12345; reach it through an SSH tunnel to see every component and whether it is healthy.

How do I check that logs arrive?

Ask Loki directly before adding Grafana. This lists the label values it has seen and fetches a few recent journal lines:

curl -s http://127.0.0.1:3100/loki/api/v1/label/job/values
curl -G -s http://127.0.0.1:3100/loki/api/v1/query_range \
  --data-urlencode 'query={job="journal"}' \
  --data-urlencode 'limit=5' | head -c 600

Then in Grafana add a data source of type Loki with URL http://127.0.0.1:3100 and open Explore. Useful LogQL to start with:

{job="journal", unit="ssh.service"} |= "Failed password"
sum by (unit) (count_over_time({job="journal"} |~ "(?i)error" [5m]))

The first shows failed SSH logins, the second counts lines with "error" per systemd unit, which works well as an alert rule.

How do I send logs from other servers securely?

Remote pushes travel over public IPs because there is no private network between our servers, so never open port 3100 directly. Put Loki behind Caddy on the central server so every request needs HTTPS and a password:

logs.example.net {
    basic_auth {
        web1 PASTE_HASH_FROM_caddy_hash-password
    }
    reverse_proxy 127.0.0.1:3100
}

On each remote server, install only Alloy, store the plain password in /etc/alloy/loki.pass (owner alloy, mode 600) and point its writer at the HTTPS address:

loki.write "central" {
  endpoint {
    url = "https://logs.example.net/loki/api/v1/push"
    basic_auth {
      username      = "web1"
      password_file = "/etc/alloy/loki.pass"
    }
  }
  external_labels = { host = "web1" }
}

Give every server its own user so you can revoke one without touching the others. An SSH tunnel is an alternative for one or two machines, and Caddy HTTPS covers the certificate side.

How do I migrate from Promtail?

Convert the existing file, review the output, then swap services:

alloy convert --source-format=promtail --output=/tmp/config.alloy /etc/promtail/config.yml
sudo cp /tmp/config.alloy /etc/alloy/config.alloy
sudo systemctl disable --now promtail
sudo systemctl restart alloy

Keep the labels identical to what Promtail sent, or saved Grafana queries and alerts will stop matching. Remove the old package once Alloy has run cleanly for a day.

How do I keep Loki fast and small?

  • Few labels, low cardinality: use host, job and unit; never put user IDs, IPs or request paths in labels.
  • Watch disk: du -sh /var/lib/loki weekly, and shorten retention_period if needed.
  • Drop noise early: a loki.process stage with stage.drop in Alloy can discard health check lines before they are stored.
  • Out of order or rate limit errors: read journalctl -u alloy; raise ingestion_rate_mb in limits_config for busy hosts.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A2-4Loki, Alloy and Grafana on one host2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months
A4-8logs from many busy servers4 vCPU, 8 GB RAM, 180 GB NVMe$28.80/mo$86.40 for 3 months

Questions about Loki and Alloy for central logs

Is Promtail still usable?

Existing installs run, but Promtail has reached end of life and gets no more fixes. Use Grafana Alloy for new servers and convert old configs with alloy convert.

How much disk does Loki need?

It depends on log volume and retention. Measure a day of logs with du -sh /var/lib/loki and multiply by your retention days, with headroom.

Can Loki search full text?

Yes, with line filters such as |= and regular expressions, but it scans the selected streams rather than using a full text index. Narrow by labels first.

Should Loki run on the same server as Grafana?

For a small setup, yes; it keeps traffic on localhost. Split them when log volume needs more RAM or disk.

Where do I see server load at the same time?

Grafana with Prometheus shows inside metrics, and the console Usage graphs tab shows the provider view of the instance.