
Deploy Prometheus | (Just Updated) Metrics Behind A Login, Retention Capped To The Volume
Prometheus behind a login. Retention capped to your volume, targets via env
prometheus
Just deployed
/prometheus
Deploy and Host Prometheus on Railway
Prometheus is the standard open-source monitoring system and time-series database: it scrapes metrics from your services over HTTP, stores them, and answers PromQL queries for dashboards and alerts. Grafana, Alertmanager and most of the cloud-native ecosystem speak to it.
This template runs Prometheus 3.15 from a thin wrapper around the official image: the Prometheus web UI and API on a Railway public domain, a Railway volume holding the time-series database, and a generated password in front of all of it.
About Hosting Prometheus
- It is behind a login from the first request. Prometheus has no authentication of its own, so
the stock image on a public Railway domain hands the query API, the loaded config and every
scrape target to anyone with the URL. Here a password is generated per deploy
(
PROMETHEUS_PASSWORD), turned into a bcrypt web config at boot, and every route, including the API, answers401without it. The container refuses to start if the password is missing. - Retention cannot fill your volume. The stock image keeps 15 days with no size limit, and a
busy target can fill the disk before the time limit arrives. The entrypoint reads the volume's
real size at boot and sets
--storage.tsdb.retention.sizeto 80% of it. - Scrape targets come from variables. Set
SCRAPE_TARGETSto a comma-separated list such asapi.railway.internal:3000,worker.railway.internal:9100and redeploy; no config file to edit. For anything more elaborate, put a fullprometheus.ymlinPROMETHEUS_CONFIG. - Data survives redeploys. The volume at
/prometheusis chowned at boot and the database runs as the unprivilegednobodyuser; samples written before a redeploy were read back after it. - Remote write is on.
/api/v1/writeaccepts pushes from Grafana Alloy, Agent or another Prometheus, behind the same password.
Common Use Cases
- Metrics for the other services in your Railway project, scraped over the private network
- A data source for Grafana dashboards (use
PROMETHEUS_PRIVATE_URLwith basic auth) - Alerting rules and long-lived service-level numbers for an app or a fleet of apps
- A remote-write target for agents that push metrics from outside Railway
Dependencies for Prometheus Hosting
- One Railway volume for the time-series database (created by the template)
Deployment Dependencies
- Prometheus documentation: https://prometheus.io/docs
- Basic auth in Prometheus: https://prometheus.io/docs/guides/basic-auth/
- Official image: https://hub.docker.com/r/prom/prometheus
- Wrapper source: https://github.com/bon5co/prometheus-railway
Implementation Details
| Variable | Purpose |
|---|---|
PROMETHEUS_PASSWORD | Password for the web UI, API and remote write, generated per deploy. The user name is admin (override with PROMETHEUS_USER). |
PROMETHEUS_PRIVATE_URL | URL on the private network, for Grafana or other services in the project. |
SCRAPE_TARGETS | Optional. Comma-separated host:port list to scrape. |
METRICS_PATH | Optional. Path on those targets, default /metrics. |
RETENTION_TIME | Optional. Default 15d. |
RETENTION_SIZE | Optional. Default 80% of the volume, for example 3GB. |
PROMETHEUS_CONFIG | Optional. A complete prometheus.yml, replaces the generated one. |
The healthcheck is off because every route needs the password; the service restarts on failure.
Why Deploy 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 Prometheus 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.
Template Content
prometheus
ghcr.io/bon5co/prometheus-railway:3.15.0
