Deploy Grafana + Loki + Prometheus | (Just Updated) Logs and Metrics That Scrape Your Apps
Grafana + Loki + Prometheus that scrape your apps and expire old data
Just deployed
/var/lib/grafana
Just deployed
/loki
prometheus
Just deployed
/prometheus
Deploy and Host Grafana, Loki and Prometheus on Railway
Grafana is the open-source dashboard and exploration UI, Loki is Grafana Labs' log aggregation system, and Prometheus is the de-facto open-source metrics database. Together they are the standard self-hosted alternative to Datadog, New Relic and Grafana Cloud: metrics scraped from your services, logs shipped from them, and one UI over both.
This template runs all three as a single Railway deploy — Grafana on your public domain, Loki and Prometheus on the private network, each with its own volume — with both data sources already wired up and Prometheus already scraping targets you name in a variable.
About Hosting Grafana, Loki and Prometheus
Each component is a single Go binary with a configuration file, which makes the stack easy to run and easy to run badly. Three details decide whether the deploy is useful: Prometheus only scrapes what its configuration file lists, so a stack shipped with the stock file collects nothing but its own metrics; Loki deletes nothing unless a compactor is running in retention mode, so its volume grows until writes fail; and Railway mounts volumes owned by root while the upstream Grafana image runs as an unprivileged user, so a naive deploy either crash-loops or has to run the whole dashboard as root.
This template handles all three. Prometheus reads its scrape targets from an environment variable and writes its configuration at boot, Loki ships a compactor with retention enabled and a configurable retention period, and Grafana repairs the ownership of its data directory as root and then drops to its own uid before starting.
Why Deploy Grafana, Loki and Prometheus on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying this stack on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
Observability belongs next to the services it observes. Deployed into the same Railway project as your apps, Prometheus scrapes them over the private network with no egress and no public exposure, and Grafana is the only service with a domain.
Common Use Cases
- Metrics and dashboards for services already running in the same Railway project, scraped over private networking.
- Central log store for those services, shipped with Promtail, Alloy, Vector, Fluent Bit or any Loki-compatible client.
- A self-hosted replacement for Datadog or Grafana Cloud for a small team.
- Alerting on both logs and metrics from one Grafana instance.
Dependencies for Grafana, Loki and Prometheus
- Grafana OSS 13.0.2, Loki 3.7.7 and Prometheus v3.14.0, each as a prebuilt pinned image.
- One Railway volume per service: Grafana's database, Loki's chunks and index, and Prometheus's TSDB.
Deployment Dependencies
- Grafana: https://github.com/grafana/grafana (AGPL-3.0)
- Loki: https://github.com/grafana/loki (AGPL-3.0)
- Prometheus: https://github.com/prometheus/prometheus (Apache-2.0)
Implementation Details
Every variable carries a working default, so the deploy form asks for nothing:
GF_SECURITY_ADMIN_PASSWORD— generated per deploy. Log in at your public URL asadminwith this password. Grafana refuses to boot if it is emptied.PROMETHEUS_SCRAPE_TARGETS— comma-separatedjob=host:port/metrics_pathentries. Loki is pre-registered; add your own services by their private domains, for exampleapi=api.railway.internal:8080/metrics. Prometheus always scrapes itself as well.PROMETHEUS_RETENTION_TIME— how long metrics are kept (default31d).LOKI_RETENTION_PERIOD— how long logs are kept (default744h, i.e. 31 days). The compactor enforces it; without one Loki keeps every log line forever.LOKI_URL/PROMETHEUS_URL— the private addresses Grafana's provisioned data sources point at. Both data sources are read-only and appear the moment the stack is up.
Ship logs to Loki at http://loki.railway.internal:3100/loki/api/v1/push from inside the
project. Loki and Prometheus have no public domain by design.
Template Content
LOKI_RETENTION_PERIOD
PROMETHEUS_RETENTION_TIME
