Build an Observability Stack for Your Home Lab with Docker Compose
A hands-on build of Prometheus, Loki, Grafana and Grafana Alloy with Docker Compose: metrics and logs for a home lab, with pinned versions, retention sizing, one useful alert, backups and a secured Grafana.
By Mark Poulton
Most home labs reach the same point. You have a dozen containers across a couple of hosts, a monitoring tool that shows green dots, and no quick way to answer the questions that come up when something breaks. Why did Home Assistant restart at 3 a.m.? Is the disk filling because of Plex metadata or a runaway log file? Which container has been slowly eating memory all week?
The Observability Deep Dive explains the ideas behind answering those questions. This guide builds a working stack you can run, in one compose.yaml, on any Docker host:
- Prometheus stores metrics: numbers over time, such as CPU use, memory and request counts.
- Loki stores logs: every line your containers and the host write.
- Grafana shows both in one place and sends alerts.
- Grafana Alloy collects logs from Docker and the host journal and pushes them to Loki.
- node-exporter and cAdvisor expose host and container metrics for Prometheus to collect.
It's the same stack I run in my own home lab. The gotchas section at the end lists the problems I actually hit.
Traces, the third signal, aren't covered here. Very few self-hosted apps emit them, so metrics and logs answer most home lab questions. Adding Tempo and an OpenTelemetry pipeline to this stack is the subject of a follow-up article.
What you'll need
- A Docker host with Docker Engine and the Compose plugin. If you're starting from scratch, Build a Properly Managed Docker Host walks through setting one up. This guide assumes Ubuntu Server, but any Linux host with systemd will work.
- Spare capacity of about 2 GB of RAM and 25 GB of disk. The stack idles well below that, but Prometheus and Loki use more memory when you run big queries.
- Comfort with Docker Compose. You should know what services, volumes and secrets are. The Docker Compose guide covers everything used here.
Allow two to three hours: one to build and start the stack, and the rest to explore Grafana, set up the alert and test a backup.
How the pieces fit together
Each signal has its own path from your host to Grafana. The table maps them, and links each part to the article that explains the idea behind it.
| Signal | Collected by | Stored in | Answers | Concept |
|---|---|---|---|---|
| Metrics | node-exporter, cAdvisor (pulled) | Prometheus | Is something wrong, and since when? | Logs, metrics and traces |
| Logs | Alloy, from Docker and journald | Loki | What exactly happened? | Logs, metrics and traces |
| Alerts | Grafana | n/a | Does a person need to act now? | Alert fatigue |
Figure 1. Metrics are pulled: Prometheus scrapes each target every 30 seconds. Logs are pushed: Alloy sends them to Loki as they arrive. Grafana reads from both, so it is the only part you need to open in a browser.
One design choice is worth explaining up front.
Alloy, not Promtail. Promtail, Loki's original log shipper, is deprecated, and Alloy replaces it. Alloy is also a distribution of the OpenTelemetry Collector, so the same container can receive traces when you add them later. It can also replace node-exporter and cAdvisor, but this guide keeps them as separate containers because they are simpler to troubleshoot while you learn.
Versions used
All images are pinned to versions current at the time of writing (December 2026). Pinning means docker compose pull never upgrades anything without you knowing. Update the tags deliberately, one component at a time, after reading its release notes.
| Component | Image |
|---|---|
| Prometheus | prom/prometheus:v3.13.5 (LTS) |
| Loki | grafana/loki:3.7.6 |
| Grafana | grafana/grafana:13.3.2 |
| Alloy | grafana/alloy:v1.22.0 |
| node-exporter | prom/node-exporter:v1.10.2 |
| cAdvisor | ghcr.io/google/cadvisor:0.55.1 |
Watch the tag formats: some images use a v prefix and some don't. cAdvisor moved from gcr.io to ghcr.io at v0.53.0, and its GHCR tags have no v.
Step 1: Prepare the host
Turn on Docker log rotation
Do this first, because Alloy will read these files. By default, Docker keeps every line a container writes in a JSON file that grows forever. On my own host, the largest of these files had reached 38 MB before I noticed. Add rotation in /etc/docker/daemon.json. If the file already exists, merge these keys into it instead of replacing it:
{
"log-driver": "json-file",
"log-opts": { "max-size": "10m", "max-file": "3" }
}
Validate the file, then restart Docker:
sudo python3 -m json.tool /etc/docker/daemon.json
sudo systemctl restart docker
Restarting Docker restarts every container on the host, so pick a quiet moment. The setting only applies to containers created afterwards. Recreate your existing stacks once with docker compose up -d --force-recreate to apply it.
Create the project folder
mkdir -p ~/observability/{prometheus,loki,alloy,secrets,grafana/provisioning/datasources}
cd ~/observability
By the end of this guide, the folder looks like this:
observability/
├── compose.yaml
├── .env
├── secrets/
│ └── grafana_admin_password.txt
├── prometheus/prometheus.yml
├── loki/loki-config.yaml
├── alloy/config.alloy
└── grafana/provisioning/datasources/datasources.yaml
Everything except secrets/ and .env belongs in Git. Keep those two out with a .gitignore:
.env
secrets/
Settings and the Grafana password
Create .env with the values that change from host to host:
# The name this host's logs are labelled with in Loki
HOST_LABEL=docker-host
# The port Grafana is published on, and the URL you browse to
GRAFANA_PORT=3000
GRAFANA_ROOT_URL=http://192.168.1.50:3000
Replace 192.168.1.50 with your host's address. If something already uses port 3000, change GRAFANA_PORT. In my lab, Dockhand already had 3000, so Grafana is on 3030.
Generate a strong admin password and store it as a file. Grafana runs as user ID 472 inside its container, so that user must be able to read the file:
openssl rand -base64 24 > secrets/grafana_admin_password.txt
sudo chown 472:472 secrets/grafana_admin_password.txt
sudo chmod 400 secrets/grafana_admin_password.txt
Save a copy of the password in your password manager now. You need it for the first login.
Container user IDs matter. Many images run as a fixed, non-root user, so a file or folder the container must write to needs the right owner on the host. Grafana is 472, Loki is 10001, and Prometheus is
nobody(65534). Named volumes usually get this right automatically, and bind mounts usually don't. If a container logspermission deniedon its data directory, check ownership first.
Step 2: The compose file
Create compose.yaml. It's the longest file in the project, and the notes below cover the choices that aren't obvious.
name: observability
services:
prometheus:
image: prom/prometheus:v3.13.5
container_name: prometheus
command:
- --config.file=/etc/prometheus/prometheus.yml
- --storage.tsdb.path=/prometheus
- --storage.tsdb.retention.time=30d
- --storage.tsdb.retention.size=20GB
- --web.enable-lifecycle
volumes:
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
ports:
- "127.0.0.1:9090:9090"
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:9090/-/ready"]
interval: 30s
timeout: 5s
retries: 3
start_period: 30s
restart: unless-stopped
loki:
image: grafana/loki:3.7.6
container_name: loki
command: ["-config.file=/etc/loki/loki-config.yaml"]
volumes:
- ./loki/loki-config.yaml:/etc/loki/loki-config.yaml:ro
- loki_data:/loki
ports:
# Published so Alloy on other hosts can push logs. On a single host,
# change this to "127.0.0.1:3100:3100".
- "3100:3100"
healthcheck:
# The Loki image has no shell, wget or curl. -health is a flag, not a subcommand.
test: ["CMD", "/usr/bin/loki", "-health"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
restart: unless-stopped
grafana:
image: grafana/grafana:13.3.2
container_name: grafana
environment:
GF_SECURITY_ADMIN_USER: admin
GF_SECURITY_ADMIN_PASSWORD__FILE: /run/secrets/grafana_admin_password
GF_USERS_ALLOW_SIGN_UP: "false"
GF_AUTH_ANONYMOUS_ENABLED: "false"
GF_ANALYTICS_REPORTING_ENABLED: "false"
GF_SERVER_ROOT_URL: ${GRAFANA_ROOT_URL:-http://localhost:3000}
secrets:
- grafana_admin_password
volumes:
- ./grafana/provisioning:/etc/grafana/provisioning:ro
- grafana_data:/var/lib/grafana
ports:
- "${GRAFANA_PORT:-3000}:3000"
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000/api/health"]
interval: 30s
timeout: 5s
retries: 3
start_period: 60s
restart: unless-stopped
alloy:
image: grafana/alloy:v1.22.0
container_name: alloy
command:
- run
- --server.http.listen-addr=0.0.0.0:12345
- --storage.path=/var/lib/alloy/data
- /etc/alloy/config.alloy
environment:
HOST_LABEL: ${HOST_LABEL:-docker-host}
volumes:
- ./alloy/config.alloy:/etc/alloy/config.alloy:ro
- alloy_data:/var/lib/alloy/data
# Read-only stops file writes, not API calls: Alloy can still control Docker.
- /var/run/docker.sock:/var/run/docker.sock:ro
- /var/log/journal:/var/log/journal:ro
- /etc/machine-id:/etc/machine-id:ro
restart: unless-stopped
node-exporter:
image: prom/node-exporter:v1.10.2
container_name: node-exporter
command: ["--path.rootfs=/host"]
pid: host
volumes:
- /:/host:ro,rslave
restart: unless-stopped
cadvisor:
image: ghcr.io/google/cadvisor:0.55.1
container_name: cadvisor
command:
- --docker_only=true
- --housekeeping_interval=30s
- --store_container_labels=false
- --whitelisted_container_labels=com.docker.compose.project,com.docker.compose.service
privileged: true
devices:
- /dev/kmsg
volumes:
- /:/rootfs:ro
- /var/run:/var/run:ro
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
- /dev/disk/:/dev/disk:ro
restart: unless-stopped
secrets:
grafana_admin_password:
file: ./secrets/grafana_admin_password.txt
volumes:
prometheus_data:
loki_data:
grafana_data:
alloy_data:
What to notice:
- Only Grafana and Loki are reachable from your network. Prometheus is bound to
127.0.0.1, so you can reach it over an SSH tunnel but nobody else can. Alloy and the exporters aren't published at all, because the containers reach each other by name on the project's network. Loki is published only so that Alloy on your other hosts can push to it. - Retention has two limits. Prometheus deletes data older than 30 days, or the oldest data once it reaches 20 GB, whichever comes first. The size limit is a safety net that stops a mistake from filling the disk.
- Health checks avoid tools the images don't have. The Loki image has no shell,
wgetorcurl, so its check calls the Loki binary with the-healthflag. The Alloy image has no HTTP client, so it has no health check. Prometheus scrapes Alloy instead, and the alert in Step 6 catches it if Alloy stops. - The Docker socket is powerful. Alloy needs it to discover containers and read their logs. Mounting it read-only stops Alloy writing files through it, but not making API calls: anything with access to the socket can control Docker. Only give it to images you trust.
- The node-exporter network graphs show its container, not the host. node-exporter runs on the project network for simplicity, so its network counters are the container's own. If you want host NIC statistics, run it with
network_mode: hostand scrape it on the host's address instead.
Step 3: Configure each component
Prometheus: what to scrape
Create prometheus/prometheus.yml:
global:
scrape_interval: 30s
evaluation_interval: 30s
scrape_configs:
# Prometheus, Loki, Grafana and Alloy all publish their own metrics.
- job_name: prometheus
static_configs:
- targets: ["localhost:9090"]
labels: { host: docker-host }
- job_name: loki
static_configs:
- targets: ["loki:3100"]
labels: { host: docker-host }
- job_name: grafana
static_configs:
- targets: ["grafana:3000"]
labels: { host: docker-host }
- job_name: alloy
static_configs:
- targets: ["alloy:12345"]
labels: { host: docker-host }
# Host metrics: CPU, memory, disk, filesystems.
- job_name: node
static_configs:
- targets: ["node-exporter:9100"]
labels: { host: docker-host }
# Container metrics. cAdvisor exposes far more series than a home lab needs,
# so keep only the ones the dashboards use.
- job_name: cadvisor
static_configs:
- targets: ["cadvisor:8080"]
labels: { host: docker-host }
metric_relabel_configs:
- source_labels: [__name__]
regex: "container_(cpu_usage_seconds_total|memory_working_set_bytes|network_(receive|transmit)_bytes_total|fs_(reads|writes)_bytes_total|last_seen|start_time_seconds|oom_events_total|spec_memory_limit_bytes)|machine_(cpu_cores|memory_bytes)"
action: keep
# Series with no container name are cgroups, not containers.
- source_labels: [name]
regex: ""
action: drop
Change docker-host to the same name you used for HOST_LABEL, so metrics and logs from this host share a label.
The metric_relabel_configs block on cAdvisor is the most useful lesson in this file. Every unique combination of metric name and label values is a separate series, and the number of series, called cardinality, drives Prometheus's memory and disk use. Out of the box, cAdvisor reports dozens of metrics for every container, many broken down per CPU core or per network interface. Keeping only the metrics you chart removes most of those series without losing anything you look at. For the same reason, the compose file tells cAdvisor to copy only the two Compose labels, project and service, instead of every Docker label.
The scrape interval is 30 seconds rather than the common 15. A home lab doesn't need finer detail, and halving the interval halves the samples stored.
Loki: log storage and retention
Create loki/loki-config.yaml:
auth_enabled: false
server:
http_listen_port: 3100
common:
instance_addr: 127.0.0.1
path_prefix: /loki
storage:
filesystem:
chunks_directory: /loki/chunks
rules_directory: /loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: 2024-01-01
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
limits_config:
retention_period: 720h # 30 days
reject_old_samples: true
reject_old_samples_max_age: 168h
compactor:
working_directory: /loki/compactor
retention_enabled: true
delete_request_store: filesystem
analytics:
reporting_enabled: false
This runs Loki as a single process that stores everything on the local disk, which suits one home lab. Retention needs two settings: retention_period says how long to keep logs, and the compactor with retention_enabled: true actually deletes them. Without the compactor, Loki keeps logs forever.
auth_enabled: false means anything that can reach port 3100 can push or read logs. That is normal for a single-tenant Loki on a private network, and it's why Step 7 limits who can reach that port.
Alloy: container and host logs
Alloy uses its own configuration language. Each block is a component, and components pass data to each other: forward_to says where data goes next. Create alloy/config.alloy:
// ---------------------------------------------------------------
// Logs: every container on this host
// ---------------------------------------------------------------
discovery.docker "containers" {
host = "unix:///var/run/docker.sock"
}
// Turn Docker metadata into a few useful, low-cardinality labels.
discovery.relabel "containers" {
targets = []
rule {
source_labels = ["__meta_docker_container_name"]
regex = "/(.*)"
target_label = "container"
}
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_project"]
target_label = "stack"
}
rule {
source_labels = ["__meta_docker_container_label_com_docker_compose_service"]
target_label = "service"
}
}
loki.source.docker "containers" {
host = "unix:///var/run/docker.sock"
targets = discovery.docker.containers.targets
relabel_rules = discovery.relabel.containers.rules
labels = { source = "docker" }
forward_to = [loki.process.drop_old.receiver]
}
// On first start Alloy reads each container's whole log history.
// Loki rejects lines older than 7 days, so drop them here instead.
loki.process "drop_old" {
stage.drop {
older_than = "156h"
drop_counter_reason = "too_old"
}
forward_to = [loki.write.default.receiver]
}
// ---------------------------------------------------------------
// Logs: the host's systemd journal (sshd, sudo, kernel, docker)
// ---------------------------------------------------------------
loki.relabel "journal" {
forward_to = []
rule {
source_labels = ["__journal__systemd_unit"]
target_label = "unit"
}
rule {
source_labels = ["__journal_priority_keyword"]
target_label = "level"
}
}
loki.source.journal "host" {
path = "/var/log/journal"
max_age = "12h"
relabel_rules = loki.relabel.journal.rules
labels = { source = "journal" }
forward_to = [loki.write.default.receiver]
}
loki.write "default" {
endpoint {
url = "http://loki:3100/loki/api/v1/push"
}
external_labels = { host = sys.env("HOST_LABEL") }
}
Read it top to bottom as two pipelines:
- Container logs. Alloy asks Docker for the list of containers, turns each container's name and Compose labels into Loki labels, reads its log, drops anything too old for Loki to accept, and sends the rest to Loki.
- Host logs. Alloy reads the systemd journal, which holds SSH logins,
sudouse, kernel messages and Docker's own logs. It labels each line with its systemd unit and priority.
The labels are deliberately few: host, stack, service, container, source, and unit and level for the journal. Loki indexes labels, not the text of each line, so every label value creates a separate stream. Labels with a small, stable set of values make Loki fast. Labels such as a request ID or user ID create a new stream for nearly every line and make it slow. Search for those values inside the log text instead.
If your host keeps the journal in memory only, you'll find it under /run/log/journal instead of /var/log/journal. Change the mount and the path to match.
Grafana: data sources
Create grafana/provisioning/datasources/datasources.yaml:
apiVersion: 1
datasources:
- name: Prometheus
uid: prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
isDefault: true
editable: false
- name: Loki
uid: loki
type: loki
access: proxy
url: http://loki:3100
editable: false
Provisioning means Grafana creates these data sources on every start, so you never click through the setup screens and a rebuilt Grafana comes back identical. The fixed uid values let dashboards and alert rules refer to a data source reliably.
Step 4: Start the stack
Pull the images, then start everything:
docker compose pull
docker compose up -d
Wait a minute, then check each container:
docker compose ps
You should see every service as running, with (healthy) beside Prometheus, Loki and Grafana. If a container is restarting, read its log, for example docker compose logs loki --tail 50, and check the gotchas section below.
Checkpoint: metrics
Prometheus is bound to localhost, so open an SSH tunnel from your own computer:
ssh -L 9090:localhost:9090 yourname@192.168.1.50
Browse to http://localhost:9090/targets. All six jobs should be UP. A target that is DOWN usually has the wrong container name or port in prometheus.yml.
Checkpoint: logs
Open Grafana at the URL you set in GRAFANA_ROOT_URL and sign in as admin with the password from your secret file. Go to Explore, choose Loki and run:
{stack="observability"}
You should see log lines from the stack's own containers. Try {source="journal", unit="ssh.service"} to see SSH logins on the host. On some distributions the unit is sshd.service.
Step 5: Dashboards worth importing
You don't need to build dashboards from scratch. In Grafana, go to Dashboards, then New, then Import, and enter a dashboard ID from grafana.com/grafana/dashboards:
- 1860, Node Exporter Full: everything about the host, from CPU and memory to disk space and filesystems.
- A cAdvisor dashboard for per-container CPU and memory. Pick one that uses
container_cpu_usage_seconds_totalandcontainer_memory_working_set_bytes, because those are among the metrics the relabel rules keep.
Then build one small dashboard of your own with a Logs panel showing {host="docker-host"} |= "error". A list of recent errors across every container is often the most useful screen in the whole stack.
Treat dashboards as places to investigate, not things to watch. Nobody should be looking at Grafana to find out that something is broken. That is the alert's job.
Step 6: One alert worth receiving
The alert fatigue article makes the case for alerting on symptoms, the things a user notices, rather than causes such as high CPU. In a home lab, the users are your household, and the symptom they notice is "it's not working". High CPU on its own isn't worth a notification. A service that has been unreachable for five minutes is.
Create the alert in Grafana:
-
Go to Alerting, then Contact points, and add somewhere to send alerts. Grafana has built-in integrations for email, Telegram, Discord, Slack, Pushover and generic webhooks. I use a webhook to a Home Assistant automation that sends the alert to the companion app on my phone.
-
Go to Alerting, then Alert rules, and create a new rule named Service down.
-
Choose Prometheus as the data source and enter this query:
min by (job, host) (up) -
Set the condition to fire when the value is below 1.
-
Put it in a folder called Homelab with an evaluation group that runs every 1 minute, and set the pending period to 5 minutes. The pending period stops a container restart from waking you up.
-
Select your contact point and save.
Prometheus records up as 1 when a scrape succeeds and 0 when it fails, so this rule fires when any scraped service stops answering. That includes Alloy, which has no Docker health check. Grafana also fires an alert if the query itself fails, which covers Prometheus going down.
Test it. Run docker stop alloy, wait about six minutes, and you should receive a "Service down" notification for job=alloy. Run docker start alloy, and the resolved notification follows. An alert you haven't tested is an alert you can't trust.
Put it under version control. Once it works, open the rule's More menu and choose Export, then save the YAML into grafana/provisioning/alerting/. Grafana then recreates the rule on every start, and the file sits in Git with the rest of the stack. Provisioned rules are read-only in the Grafana UI, so from then on, edit the file and restart Grafana.
Resist adding ten more rules on day one. Add a rule when something breaks and you realise an alert would have told you sooner, and remove any rule that fires without you needing to act.
Step 7: Secure Grafana and the stack
Grafana can show every log line on your network, and log lines contain more than you'd expect: internal hostnames, email addresses, and sometimes tokens that a badly behaved app logged by mistake. Treat it like any other admin interface.
- Keep the admin password out of the compose file. It's in a Docker secret file, readable only by Grafana's user, and excluded from Git.
- Self sign-up and anonymous access are off. Create named accounts for anyone else in the household under Administration, then Users and access, with the Viewer role unless they need more.
- Don't forward Grafana's port on your router. If you want access from outside, use a VPN such as WireGuard or Tailscale. If you do publish it, put it behind a reverse proxy with single sign-on, such as Traefik with Authentik, and set
GRAFANA_ROOT_URLto the public address. - Limit who can reach Loki. Loki has authentication turned off, so port 3100 should only accept traffic from your Docker hosts. A host firewall rule or a VLAN rule on your router does this. If this is your only host, bind Loki to
127.0.0.1as the comment in the compose file says. - Keep Prometheus on localhost. Its API and web UI have no login, and
--web.enable-lifecyclelets anyone who can reach it shut it down. Use the SSH tunnel. - Remember what the Docker socket gives Alloy. Pin its image version, update it deliberately, and don't add other containers that mount the socket without a good reason.
Storage, retention and cardinality
You'll want to know how much disk this needs before it fills one. The Prometheus storage documentation gives the formula:
disk needed = retention in seconds × samples per second × bytes per sample
Prometheus compresses each sample to about 1 to 2 bytes. Samples per second is the number of active series divided by the scrape interval. To find your series count, query prometheus_tsdb_head_series in Prometheus or Grafana.
A worked example. A single host running this stack plus a dozen other containers has roughly 20,000 series. With a 30-second interval, that's about 670 samples per second. Over 30 days (2,592,000 seconds) at 2 bytes per sample, that's about 3.5 GB. The 20 GB size cap leaves plenty of headroom for a second or third host.
Loki depends on how much your containers log, which varies far more. A quiet home lab might write a few hundred megabytes a day, and Loki's compression typically shrinks that to a fraction on disk. Measure rather than guess: after a few days, check the volume sizes and project forward.
docker system df -v | grep -E "VOLUME NAME|observability_"
When disk use grows faster than expected, cardinality is the usual cause, not retention. Check these first:
- New series in Prometheus. In Prometheus, open Status, then TSDB Status, to see which metrics and labels have the most series. One exporter with a label that changes on every scrape, such as a timestamp, a container ID or a URL path, can add thousands of series a day.
- New streams in Loki. Avoid labels whose values keep changing. Containers recreated with random names, such as one-off
docker runjobs, each create new streams. Thecontainerlabel is fine for long-running Compose services but adds up if you run many short-lived containers. - Chatty containers. A single container logging every health check can dominate Loki's disk use. Turn its log level down, or drop the lines in Alloy with a
stage.dropthat matches them.
The same trade-offs, cardinality, sampling and retention, decide what observability costs at work. Here, they decide whether a 256 GB SSD is enough.
Backups
The Docker storage guide covers volume backups in detail. For this stack, decide what is worth restoring:
| What | Where | Back it up? |
|---|---|---|
Config files and compose.yaml | The project folder | Yes, in Git. This is the stack. |
.env and secrets/ | The project folder | Yes, in your password manager or an encrypted backup, not in Git. |
| Grafana's database | grafana_data volume | Yes, if you've built dashboards or users in the UI. |
| Prometheus and Loki data | Their volumes | Optional. It's history, not configuration, and it ages out anyway. |
The Grafana database is a single SQLite file and is small. Stop Grafana briefly for a consistent copy:
docker compose stop grafana
docker run --rm -v observability_grafana_data:/data -v "$PWD":/backup alpine \
tar czf /backup/grafana-$(date +%F).tar.gz -C /data .
docker compose start grafana
If every dashboard and alert rule is provisioned from files, which is a good goal, Git alone is enough to rebuild Grafana. Then the database backup only protects users and preferences.
Test a restore. Run the stack on a second machine or a VM from Git, restore the Grafana backup into a new volume, and check that your dashboards and alert rule appear. It takes twenty minutes, and it's the only way to know the backup works.
Problems you might hit
These all happened while I built this stack. Most of them are harmless, but they look alarming the first time.
A flood of "timestamp too old" errors when Alloy starts. On its first run, Alloy reads each container's entire log history, and Loki rejects anything older than seven days. The drop_old stage in the Alloy config prevents this. If you remove that stage, the errors still stop once Alloy catches up.
"entry too far behind" after a Docker restart. Alloy re-reads recent logs, but Loki only accepts out-of-order lines within about an hour of each stream's newest entry. Those lines are already stored, and the errors stop by themselves.
"empty ring" in Loki's log just after it starts. This is a normal startup message. Ignore it unless it continues for more than a minute or two.
Loki shows unhealthy for the first minute. loki -health returns an error with status 503 while Loki is still starting. The 60-second start_period covers this. If Loki stays unhealthy, read its log.
cAdvisor targets are up but container names are missing. cAdvisor needs the /var/lib/docker and /var/run mounts to match containers to names. If you use rootless Docker or a non-default data directory, adjust those paths.
loki health instead of loki -health. Without the dash, Loki treats health as an argument and tries to start a second Loki, which fails on its config. The health check must use the flag.
Adding more hosts
The stack you built is the central part. Each additional Docker host only needs collectors:
- Copy
alloy/config.alloyto the new host and change theloki.writeURL fromhttp://loki:3100/...to the central host's address, for examplehttp://192.168.1.50:3100/loki/api/v1/push. - Run Alloy, node-exporter and cAdvisor there, using the same service definitions from the compose file with a different
HOST_LABEL. - Publish node-exporter and cAdvisor on the new host's LAN address, firewalled to the central host, and add them as targets in
prometheus.ymlwith the newhostlabel. - Reload Prometheus without a restart:
curl -X POST http://localhost:9090/-/reloadon the central host.
The direction of each connection matters if your network is segmented. Prometheus pulls metrics from the other hosts, and each host's Alloy pushes logs to Loki. A host in a DMZ therefore needs only one outbound rule, to Loki on port 3100, and nothing can reach your Grafana from there.
Where to go next
You now have metrics and logs in one place, an alert that tells you when something is down, and storage that won't surprise you. From here:
- Define what "working" means for the services your household relies on. SLIs, SLOs and error budgets shows how, and Prometheus can calculate them.
- Add metrics from your apps. Many self-hosted apps, including Traefik, CrowdSec, Authentik and Home Assistant, can expose Prometheus metrics. Add them as scrape targets.
- Add traces. Alloy already speaks OpenTelemetry, so adding Tempo is a new container, a new data source and a few lines of Alloy config. The OpenTelemetry article explains the pipeline you'll be building, and a follow-up article will add it to this stack.
The Observability Deep Dive covers the thinking behind each of these steps, from logs, metrics and traces to alerting and cost.

