StackPilot

Self Hosted Log Aggregation on a Single Server That Fits

By The StackPilot Team 7 min read

Some links on this page are affiliate links. If you sign up through them we may earn a commission at no extra cost to you. We only link to services we have actually used, and commission never decides what we recommend.

You installed the stack, pointed an agent at /var/log, and it worked — for about four days. Then the disk hit 100%, or the container got OOM-killed, or every query came back with a cardinality error you did not understand.

This is the procedure for the second attempt, written on the assumption that you already know why you want the logs and just need the thing to stay up.

Quick verdict

For one server, run Grafana Loki in single-binary mode with filesystem storage, ship with Grafana Alloy, and set retention explicitly on day one. It is the only option in this weight class that does not put a JVM on a box you are also trying to keep responsive.

The tradeoff you accept is query power: LogQL is fast on labels and slow on regex-heavy full-text scans, and you have to keep label cardinality low or the index becomes the problem. If the logs you need are the ones from the machine that just died, self-hosting on that same machine is the wrong shape entirely — that is the case for Better Stack, and I say so below.

What you are actually choosing between

OptionCost shape and ops burdenCeiling and lock-in
Loki + Grafana, single binaryCheapest tier. One process, filesystem storage, no heap to tune. Burden is label discipline and retention config.Comfortable to a few GB/day on one box. LogQL is Loki-specific, but chunks are plain compressed files you can walk away from.
GraylogMid. Three moving parts on one host: Graylog, MongoDB, and OpenSearch.Good UI and alerting out of the box. You are running a small cluster on one machine. Config is Graylog-shaped.
OpenSearch or Elasticsearch, single nodePremium in RAM. A JVM heap you must size by hand plus disk watermarks that flip indices read-only.Best full-text search of the group. Also the heaviest ops burden per log line.
Agent only (Vector or Fluent Bit) to filesCheapest. No server at all.No cross-service search. You are back to grep and jq, which is fine more often than people admit.
Better Stack (hosted)Per-volume SaaS pricing, no server to run.Ceiling is your budget. Logs leave the box, so no air-gap or data-residency story.

Step by step

1. Cap the log sources before you install anything. The wall most people hit is not the aggregator — it is Docker's default json-file driver, which grows without limit. Do this first or the aggregator just gets blamed for a problem it did not cause.

{
  "log-driver": "json-file",
  "log-opts": { "max-size": "50m", "max-file": "3" }
}

Put that in /etc/docker/daemon.json and restart the daemon. Do the same for journald in /etc/systemd/journald.conf with SystemMaxUse=1G. Now the floor is stable.

2. Put the log data on its own filesystem or volume. A separate partition, an attached block device, or at minimum a dedicated directory with a quota. When retention misbehaves, you want it to fill a volume, not your root filesystem. This single decision is the difference between a warning and an outage.

3. Install Loki as one process. Single-binary mode is a supported deployment for exactly this scale. You want filesystem storage, the TSDB index, and replication factor 1. A minimal config that actually enforces retention:

auth_enabled: false
server:
  http_listen_port: 3100

common:
  path_prefix: /var/lib/loki
  storage:
    filesystem:
      chunks_directory: /var/lib/loki/chunks
  replication_factor: 1
  ring:
    kvstore: { store: inmemory }

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

limits_config:
  retention_period: 336h
  reject_old_samples: true
  reject_old_samples_max_age: 168h

compactor:
  working_directory: /var/lib/loki/compactor
  retention_enabled: true
  delete_request_store: filesystem

The compactor block is the part people omit. Without retention_enabled: true and a delete_request_store, Loki accepts your retention_period and quietly never deletes anything. That is the failure waiting for you two weeks after a successful install.

4. Ship logs with Grafana Alloy. Promtail still works, but Grafana's own documentation now steers new installs to Alloy, and Alloy handles metrics and traces from the same config if you add them later. Point it at the journal and at your container log directory, not at a hand-maintained list of files.

5. Keep labels boring. This is the next wall. Labels are indexed; everything else is chunk content scanned at query time. Put job, host, unit, and level in labels. Never put request IDs, user IDs, trace IDs, timestamps, or raw URLs in labels — each unique combination is a new stream, and a few hundred thousand streams will make ingestion stall and queries time out. If you need to filter on a high-cardinality field, use a LogQL filter expression instead.

6. Set a volume alert before you need it. Alert on log bytes ingested per hour, not just on disk percentage. A crash loop produces a log flood, and the flood is what fills the disk. A disk alert fires after the damage; an ingest-rate alert fires before it.

7. Verify retention actually runs. Query something older than your retention window and confirm it is gone. Do this on day two, not day thirty.

8. Where Better Stack fits in this procedure. If steps 1–7 sound like a weekend you would rather spend elsewhere, Better Stack is the hosted equivalent: you install a collector, point it at the same sources, and get log search plus uptime checks and alerting in one place. The reason it earns a mention here is not that it is cleverer than Loki — it is that it lives off the box. When the server wedges, your logs are still readable from somewhere else, which is the one thing a single-server self-hosted stack fundamentally cannot give you.

Where this falls short

Single-node Loki has no replication. Lose the volume and you lose the logs, and you lose them precisely during the incident that made you want logs. Accept that and back up the config, not the chunks.

Query performance degrades faster than people expect on regex-heavy scans over long ranges. If your actual use case is "search every log line for a substring across 30 days, interactively", Loki will frustrate you and OpenSearch is the honest answer — with the RAM bill that implies.

The structural problem is co-tenancy. Your aggregator competes for RAM, disk IO, and CPU with the workload it monitors. Under memory pressure the kernel picks a victim, and it does not care that the victim was going to tell you what happened. If you run anything with a real uptime commitment on that box, this is the argument for shipping logs off-host, whether to Better Stack or to a second cheap VPS running the same Loki config.

Better Stack's own drawbacks, stated plainly: it is SaaS, so your logs leave your infrastructure, which rules it out for regulated data or anything air-gapped. Ingest pricing scales with volume, and debug-level logging on a chatty service is exactly the pattern that makes per-GB bills uncomfortable — you will want to drop debug logs at the collector rather than ship them and filter later. It is also not a substitute for local retention if you have a compliance requirement to keep raw logs on your own storage.

If you have one server, no compliance constraint, and a tolerance for a couple of hours of setup, self-host Loki. If you have one server and no tolerance for the pager going off because the logging stack ate the RAM, pay someone else.

FAQ

How much RAM does self hosted log aggregation need for a single server?

Loki's single binary idles in the low hundreds of megabytes and grows with query load. OpenSearch and Elasticsearch need a JVM heap you size explicitly, and on a 2 GB VPS that heap is most of your memory — which is why the ELK stack on a small box so often ends in an OOM kill.

Why does my log aggregator keep filling the disk?

Almost always one of three things: retention is configured but the compactor is not enabled, Docker's json-file driver is still unbounded, or a crash loop is producing a flood. Check ingest rate first, then confirm the compactor is deleting.

Is Loki or Elasticsearch better for a single server?

Loki, for the common case. It uses less memory, has no JVM to tune, and its storage is just compressed files. Pick Elasticsearch or OpenSearch only if interactive full-text search across long time ranges is the primary thing you do with logs.

Do I need a log aggregator at all for one server?

Often not. journalctl -u service --since plus rotated files covers a surprising amount. Add an aggregator when you need to correlate across several services, keep history longer than a day, or alert on log content — not before.

Related reading: Server keeps running out of memory? What to check next, How to Monitor a VPS Without Spending Money: 4 Free Paths

Bottom line

Self-host Loki on the box, cap your log sources first, put the data on its own volume, and enable the compactor so retention is real rather than aspirational. That combination survives contact with a single production VPS. If the logs matter more than the setup time, or the box is one you cannot afford to have go dark, ship them off-host instead.

Today: write the Docker log-opts block and the journald SystemMaxUse line, restart both daemons, and check df -h before and after. That is thirty minutes and it removes the most common cause of the outage you are about to have.

Try Better Stack
Uptime + log monitoring.

Check current pricing