Graylog is powerful, but it is also heavy. Three services, a search index, and a chunk of RAM is a lot to ask of a small server that also runs a website. Loki takes the opposite approach: it stores logs cheaply, indexes only their labels, and leans on Grafana for the interface you already use for metrics. This guide covers loki promtail grafana log aggregation as a lightweight stack that fits comfortably on a small server.
The stack has three parts. Loki stores the logs and answers queries. Promtail reads log files from your servers and ships them to Loki. Grafana provides the interface, where you search logs next to the metrics dashboards you may already have. All three run as small containers or binaries, and the whole stack uses a fraction of the memory a full search index needs.
Loki Promtail Grafana Log Aggregation: Why It Stays Light
Loki’s trick is that it does not index the text of every log line. It indexes only labels, which are small key-value pairs such as the hostname, the service name, and the log level. The log text itself is stored compressed and scanned at query time. That makes storage cheap and ingestion fast, and it makes Loki a good fit for a small server where disk and memory are limited. The trade-off is that a search across a huge time range without good labels is slower than in a full-text index, so choosing labels well matters.
Promtail is the shipper. It tails log files on each server, attaches labels, and pushes the lines to Loki. It runs as a tiny agent with almost no memory use, and it remembers where it stopped reading, so a restart does not resend the whole file or skip lines. Grafana is the front end: its Explore view lets you write LogQL queries, filter by labels, and jump from a metrics spike on a dashboard straight to the logs from the same minute. If you already run Grafana for metrics, adding Loki costs you one more container, not a new platform.
Installing Loki, Promtail, and Grafana
Docker Compose is the simplest way to run all three. One Compose file defines Loki, Promtail, and Grafana, with a volume for Loki’s data and a volume for Grafana’s dashboards. Grafana needs a port you can reach, Loki needs a port Promtail can reach, and Promtail needs read access to the log files on the host. Keep the ports private: bind Grafana to localhost and reach it through an SSH tunnel or a reverse proxy with authentication, because an open Grafana with default credentials is a quick win for scanners.
A loki promtail setup starts with Loki’s configuration, which is a short YAML file. Set the storage path, the retention period, and the chunk settings, and leave the rest at defaults. Retention is the important choice: thirty days is a reasonable default for a small server, and Loki deletes older chunks automatically. Without retention, the disk fills up quietly over a few months, which is the same failure every log system has when nobody configures cleanup.
Start Loki first and confirm it answers on its readiness endpoint. Then start Promtail and watch its log for errors about files it cannot read. Permission problems are the most common first-run failure: Promtail runs as a container user that may not be able to read /var/log on the host. Mount the log directory read-only and make sure the files are readable by the container’s user, or run Promtail as a system service instead of a container. Start Grafana last, add Loki as a data source with the Loki URL, and open the Explore view to confirm logs are arriving.
Configuring Promtail to Ship the Right Logs
Promtail’s configuration lists the files to tail and the labels to attach. Start with the system log and the Nginx access and error logs, each with labels for the job and the host. A label set like job=”nginx” and host=”web-01″ is enough to filter quickly later. Avoid labels with many unique values, such as a request path or a user ID, because every unique label combination creates a new stream, and too many streams hurt Loki’s performance. Labels should describe the source, not the content of each line.
Nginx logs need care because their format varies. If you use the default combined format, Promtail ships each line as text and Grafana parses it at query time. That works fine for a small setup. If you want structured fields, switch Nginx to JSON logging and let Promtail parse the JSON into labels and fields. JSON logs are slightly larger on disk, but they make queries like “show me all 500 errors from the API” trivial instead of a text search.
Ship application logs the same way. PHP errors, database slow-query logs, and your app’s own log file each get a job label and a file path. The goal is one pipeline for every log on the server, so a problem that spans the web server and the application shows up in one search. The guide to Nginx access and error logs explains what the lines mean, which helps you decide which ones are worth alerting on.
Searching Logs with LogQL in Grafana
LogQL is Loki’s query language, and it reads like a filter pipeline. A query starts with a label selector, such as {job=”nginx”}, and then adds filters, such as |= “500” to keep lines containing 500, or != “healthcheck” to drop the noise. That combination, a label selector plus a text filter, covers most everyday searches. Add a time range and Grafana shows the matching lines with a histogram above them, so you can see when the errors spiked, not just that they happened. This lightweight log aggregation approach keeps queries fast for the volumes a small server produces.
Learn three query patterns and you can handle most incidents. First, errors in the last hour: {job=”nginx”} |= “error”. Second, a specific status code: {job=”nginx”} | json | status=”500″. Third, a rate of errors over time, which turns the log search into a graph you can alert on. Save the queries you use more than once as Grafana panels or as links in your runbook, so the next incident starts with a search instead of a blank page.
Alerting on Log Patterns
Grafana can alert on Loki queries, and two alerts cover most small servers. Alert when the rate of 5xx responses in the Nginx logs crosses a threshold for five minutes, and alert when the word “error” appears in the application logs more than a handful of times in ten minutes. Both alerts need a notification channel, such as email or a webhook, and both need thresholds tuned after a week of normal data, so they fire on real problems and not on a busy afternoon.
Keep alerts rare. An alert that fires daily gets ignored, and an ignored alert is the same as no alert. Start with the two above, watch them for two weeks, and add a third only when you can name the specific failure it catches. The Uptime Kuma setup guide covers the outside-in half of monitoring, which pairs well with log alerts: one tells you the site is down, the other tells you why.
Retention, Disk, and Day-to-Day Care
Loki’s retention setting is the whole disk plan. Set it when you install, and confirm old chunks actually disappear by checking the data directory after the retention period passes. If the disk keeps growing past the retention window, the cause is usually a second Loki data path or a compactor that never runs. Check the Loki log for compactor errors before you add disk.
Promtail needs almost no care. It tails files, ships lines, and resumes after restarts. Check occasionally that it is still running and that its targets are all marked as ready in its own status page. Grafana needs the usual care: back up its database, keep it updated, and keep it behind authentication. The Prometheus and Grafana setup guide for a 2 GB VPS covers the metrics side in detail, and the comparison of Grafana Cloud and self-hosted Grafana helps you decide whether to keep Grafana on the VPS or move it to a hosted plan. Check official pricing before you decide, because hosted tiers change.
A grafana logs small server setup is done when three things are true: every log on the server arrives in Loki, you can find an error from last night in under a minute, and one alert fires when the error rate spikes. Set it up on a quiet afternoon, ship the Nginx logs first, and use it the next time something breaks. The first time a LogQL query finds the cause in seconds, the stack has paid for itself.