📊 Setup Prometheus — Self-Hosted Metrics Collection
Deploy Prometheus on Ubuntu to scrape and store time-series metrics from your servers, containers, and applications — the foundation of the Grafana monitoring stack.
📦 Resources & Setup Scripts
Grab the automated bash script from GitHub to follow along with the video.
Quick Install:
wget https://raw.githubusercontent.com/mhmdali94/Docker/main/monitoring/prometheus/prometheus-ubuntu.sh
chmod +x prometheus-ubuntu.sh
sudo bash prometheus-ubuntu.sh
Tutorial Steps
1 Download the Script
wget https://raw.githubusercontent.com/mhmdali94/Docker/main/monitoring/prometheus/prometheus-ubuntu.sh
2 Make it Executable
chmod +x prometheus-ubuntu.sh
3 Run the Installer
The script installs Docker if needed, then deploys Prometheus with a starter prometheus.yml scrape config.
sudo bash prometheus-ubuntu.sh
4 Access the Web UI
Open your browser and navigate to:
http://<your-server-ip>:9090
5 Connect to Grafana
In Grafana, go to Connections → Data Sources → Add Prometheus with URL http://prometheus:9090 to start building dashboards.
Ports Used
| Port | Purpose |
|---|---|
| 9090 | Prometheus Web UI & API |
Overview
Prometheus is the de facto standard for metrics collection in modern infrastructure. It uses a pull model: Prometheus scrapes HTTP endpoints (/metrics) on a defined schedule, stores time-series data in its built-in TSDB, and exposes it via PromQL for querying. As a CNCF graduated project, it is the backbone of the Grafana + Prometheus + Loki observability stack used by thousands of companies.
Why Use It
Prometheus is the answer to 'how do I know what's happening inside my servers and applications?' Every major open-source project exposes a Prometheus-compatible /metrics endpoint. Once Prometheus is running, you get CPU, RAM, disk, network, and application-specific metrics for free — just add a scrape target.
When You Need It
Who Should Use It
Real Use Cases
Main Features
How to Use After Installation
Security Best Practices
Ports and Firewall Notes
Prometheus listens on port 9090. This is an internal port — expose it only within your Docker network for Grafana to query. Do not open it externally. Node Exporter listens on 9100 and cAdvisor on 8080 — both internal only.
Backup and Maintenance
Common Mistakes
Troubleshooting
Alternatives
VictoriaMetrics (Prometheus-compatible, lower memory, better compression), InfluxDB (push-based, SQL-like query), Netdata (auto-discovery, no config needed), Datadog (managed, expensive). Prometheus is the industry standard and is the right choice for the Grafana stack.
When Not to Use It
If you need push-based metrics ingestion (your apps can't expose a /metrics endpoint), InfluxDB or OpenObserve is a better fit. If you want zero-configuration monitoring that auto-discovers everything, Netdata is faster to start with. Prometheus shines when you want full control over what you scrape and how.
PrismaTechWork Professional Help
PrismaTechWork provides end-to-end infrastructure services — from initial deployment and security hardening to ongoing monitoring, automated backups, and dedicated support. Whether you need a single-server setup or a multi-site network, our team ensures your infrastructure is built right, secured properly, and maintained reliably.
Frequently Asked Questions
What is the difference between Prometheus and Grafana?
Prometheus collects and stores metrics (the data layer). Grafana visualizes metrics (the presentation layer). They are complementary — Prometheus without Grafana gives you raw data; Grafana without Prometheus gives you a pretty UI with nothing to show. The standard practice is to run both together.
What is an exporter?
An exporter is a sidecar process that translates metrics from a system that doesn't natively speak Prometheus into the /metrics format. Node Exporter translates Linux kernel metrics. MySQL Exporter translates MySQL status variables. There are hundreds of community exporters for almost every software.
How long does Prometheus store data?
By default, 15 days. You can change this with the `--storage.tsdb.retention.time` flag. For longer-term storage, configure remote write to Thanos, Grafana Mimir, or VictoriaMetrics, which provide multi-year metric storage at low cost.
What is PromQL and is it hard to learn?
PromQL is Prometheus's query language for slicing, aggregating, and computing over time-series data. It has a learning curve, but most practical queries follow simple patterns: `rate(http_requests_total[5m])` gives you request rate; `avg by (instance)(cpu_usage)` gives per-host average. Grafana's dashboard explorer helps you learn by example.
Can Prometheus send alerts without Grafana?
Yes. Prometheus has a built-in Alertmanager integration. Define alert rules in a rules file, and Prometheus will fire them to Alertmanager, which routes notifications to Slack, PagerDuty, email, or webhook. Grafana adds a visual alerting layer on top, but is not required for basic alerting.
How do I monitor Docker containers with Prometheus?
Run cAdvisor (Container Advisor) alongside your Docker daemon. It exposes a /metrics endpoint with per-container CPU, memory, network, and I/O metrics. Add it as a Prometheus scrape target in prometheus.yml and import the cAdvisor Grafana dashboard (ID 14282).
What is the difference between Prometheus and InfluxDB?
Prometheus uses a pull model (it scrapes targets), while InfluxDB uses a push model (applications write to it). Prometheus is designed for operational metrics with PromQL; InfluxDB is more general-purpose with SQL-like Flux queries. For the Grafana stack, Prometheus is the native choice.
How do I update Prometheus?
Run `docker compose pull && docker compose up -d`. Prometheus TSDB data is stored in a named volume and is not affected by image updates. Check the Prometheus changelog for TSDB format changes before major version upgrades.
