Monitoring your infrastructure is essential for performance, reliability, and capacity planning.
In this guide, we’ll set up Prometheus (for metrics collection) and Grafana (for visualization) on Ubuntu 20.04, then connect Rocky Linux 8 and Ubuntu clients using Node Exporter.
🧩 What is Prometheus?
Prometheus is an open-source monitoring tool developed by SoundCloud, now part of the CNCF (Cloud Native Computing Foundation).
It collects metrics from systems and applications and stores them in a time-series database, allowing you to create alerts and analyze performance.
📊 What is Grafana?
Grafana is an open-source data visualization platform.
It connects to Prometheus (and many other sources) to visualize data in interactive dashboards and graphs.
⚙️ Step 1: Update Ubuntu 20.04 Server
# apt update && apt upgrade -y
🧠 Step 2: Install Prometheus on Ubuntu 20.04
1️⃣ Create Prometheus user and directories
# useradd --no-create-home --shell /bin/false prometheus
# mkdir /etc/prometheus /var/lib/prometheus
2️⃣ Download Prometheus
# cd /tmp
# wget https://github.com/prometheus/prometheus/releases/download/v2.53.0/prometheus-2.53.0.linux-amd64.tar.gz
# tar xvf prometheus-2.53.0.linux-amd64.tar.gz
# cd prometheus-2.53.0.linux-amd64
3️⃣ Move binaries and set permissions
# mv prometheus /usr/local/bin/
# mv promtool /usr/local/bin/
# mv consoles /etc/prometheus/
# mv console_libraries /etc/prometheus/
# mv prometheus.yml /etc/prometheus/
# chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus
# chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool
🧾 Step 3: Create Prometheus Systemd Service
# tee /etc/systemd/system/prometheus.service > /dev/null <<EOF
[Unit]
Description=Prometheus Monitoring
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
EOF
Then enable and start Prometheus:
# systemctl daemon-reload
# systemctl enable prometheus
# systemctl start prometheus
# systemctl status prometheus
Access it in your browser:
👉 http://gra01.darole.org:9090/
📈 Step 4: Install Grafana on Ubuntu 20.04
1️⃣ Add Grafana APT repository
# apt install -y apt-transport-https software-properties-common curl gpg
# mkdir -p /usr/share/keyrings/
# curl -fsSL https://packages.grafana.com/gpg.key | sudo gpg --dearmor -o /usr/share/keyrings/grafana.gpg
# echo "deb [signed-by=/usr/share/keyrings/grafana.gpg] https://packages.grafana.com/oss/deb stable main" |
sudo tee /etc/apt/sources.list.d/grafana.list
2️⃣ Install Grafana
# apt update
# apt install grafana -y
3️⃣ Enable and Start Grafana
# systemctl enable grafana-server
# systemctl start grafana-server
Open Grafana in a browser:
👉 http://gra01.darole.org:3000/
(Default credentials: admin / admin)
🔗 Step 5: Connect Grafana to Prometheus
-
Login to Grafana →
http://gra01.darole.org:3000 -
Go to Connections → Data Sources → Add Data Source
-
Choose Prometheus
-
In URL →
http://gra01.darole.org:9090 -
Click Save & Test
🖥️ Step 6: Install Node Exporter on Clients
➤ On Rocky Linux 8 & Ubuntu Clients
Run these commands on each client system (both Rocky 8 and Ubuntu):
Download Node Exporter
# cd /tmp
# wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz
# tar xvf node_exporter-1.8.2.linux-amd64.tar.gz
# sudo mv node_exporter-1.8.2.linux-amd64/node_exporter /usr/local/bin/
Create a user
# sudo useradd --no-create-home --shell /bin/false node_exporter
Create systemd service
# sudo tee /etc/systemd/system/node_exporter.service > /dev/null <<EOF
[Unit]
Description=Prometheus Node Exporter
After=network.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
[Install]
WantedBy=multi-user.target
EOF
# sudo systemctl daemon-reload
# sudo systemctl enable node_exporter
# sudo systemctl start node_exporter
Default metrics endpoint →
👉 http://lamp01.darole.org:9100/metrics
🔧 Step 7: Add Clients to Prometheus Server
Edit Prometheus config on your main Ubuntu 20.04 server:
root@gra01:~# sudo vi /etc/prometheus/prometheus.yml
Add client targets at the bottom:
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "node_exporter"
static_configs:
- targets:
- "kub01.darole.org:9100"
- "kub02.darole.org:9100"
- "kub03.darole.org:9100"
- "dock01.darole.org:9100"
- "lamp01.darole.org:9100"
- "zap01.darole.org:9100"
- "pup01.darole.org:9100"
- "web01.darole.org:9100"
- "db01.darole.org:9100"
- "ans01.darole.org:9100"
- "tomd01.darole.org:9100"
- "tomp01.darole.org:9100"
- "jen01.darole.org:9100"
- "son01.darole.org:9100"
Replace the IPs with your Rocky 8 and Ubuntu client IPs.
Then restart Prometheus:
# promtool check config /etc/prometheus/prometheus.yml
# sudo systemctl restart prometheus
✅ Step 8: Verify Monitoring Setup
-
Prometheus Targets:
👉http://gra01.darole.org:9090/targets
-
Grafana Dashboards:
👉http://gra01.darole.org:3000
You should now see metrics from all your Ubuntu and Rocky Linux clients visualized beautifully in Grafana.
🎯 Summary
| Component | Description | Default Port |
|---|---|---|
| Prometheus | Metrics collection & storage | 9090 |
| Grafana | Data visualization | 3000 |
| Node Exporter | System metrics on clients | 9100 |
🧠 Use: Prebuilt Dashboards
In Grafana:
- Go to Google and search for "grafana dashboard"
- Select the dashboard required and default values exported by Prometheus node exporter graphed
- Go to Create → Import Dashboard and Paste Copy ID 1860
Monitoring Docker containers with Prometheus + Grafana
Architecture
Step 1: Run cAdvisor
$ docker run -d \ --name=cadvisor \ --restart=unless-stopped \ -p 8080:8080 \ -v /:/rootfs:ro \ -v /var/run:/var/run:ro \ -v /sys:/sys:ro \ -v /var/lib/docker/:/var/lib/docker:ro \ -v /dev/disk/:/dev/disk:ro \ --privileged \ gcr.io/cadvisor/cadvisor:v0.49.1
$ curl http://localhost:8080/metrics
Step 2: Configure Prometheus
Edit:
sudo vi /etc/prometheus/prometheus.yml
global:
scrape_interval: 15s scrape_configs: - job_name: 'prometheus' static_configs: - targets: - localhost:9090 - job_name: 'cadvisor' static_configs: - targets: - dock01:8080Reload Prometheus
$ sudo systemctl restart prometheusStep 3: Verify Target
http://gra01.darole.org:9090/targets
You should see
Below is Grafana Dashboard for Docker
🏁 Conclusion
You’ve successfully:
-
Installed Prometheus and Grafana on Ubuntu 20.04
-
Added Rocky 8 and Ubuntu client nodes
-
Configured Node Exporter for monitoring
-
Set up Grafana dashboards
Your monitoring stack is now production-ready! 🎉
Would you like me to format this blog with Markdown headings + code syntax highlighting (ready for Medium or GitHub Pages publishing)?
No comments:
Post a Comment