How to Monitor Server Performance with Prometheus and Grafana

Keeping an eye on your server’s performance, resource usage, and health is crucial for preventing downtime and optimizing efficiency. In this guide, we’ll walk through setting up Prometheus and Grafana—two powerful tools for real-time monitoring and visualization of server metrics.

By the end, you’ll have a fully functional monitoring dashboard tracking CPU, RAM, disk usage, and more!


📌 What is Prometheus?

Prometheus is an open-source monitoring system designed for collecting and storing time-series data. It scrapes metrics from various sources and stores them in a time-series database.

Key Features:
✅ Time-series database for storing metrics
✅ Powerful query language (PromQL)
✅ Supports alerts and notifications
✅ Integrates with Grafana for visualization


📊 What is Grafana?

Grafana is an open-source tool for visualizing monitoring data from sources like Prometheus, InfluxDB, and Loki. It provides beautiful, customizable dashboards for tracking server performance.

Key Features:
✅ Real-time metric visualization
✅ Custom dashboards with alerts
✅ Supports multiple data sources (Prometheus, MySQL, Elasticsearch, etc.)


🔧 Step 1: Install Prometheus on Your Server

1️⃣ Update Your System

sudo apt update && sudo apt upgrade -y

2️⃣ Download & Install Prometheus

cd /tmp
curl -LO https://github.com/prometheus/prometheus/releases/latest/download/prometheus-linux-amd64.tar.gz
tar -xvf prometheus-linux-amd64.tar.gz
sudo mv prometheus-linux-amd64 /usr/local/bin/prometheus

3️⃣ Create a Prometheus Configuration File

sudo nano /etc/prometheus.yml

Add the following content:

global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

4️⃣ Start Prometheus

prometheus --config.file=/etc/prometheus.yml &

Prometheus is now running on http://localhost:9090 🎉


📊 Step 2: Install Grafana on Your Server

1️⃣ Install Grafana

sudo apt install -y grafana

2️⃣ Start and Enable Grafana

sudo systemctl start grafana-server
sudo systemctl enable grafana-server

Grafana will now be accessible at http://localhost:3000.


⚙️ Step 3: Connect Prometheus to Grafana

1️⃣ Log into Grafana (Default username: admin, Password: admin)
2️⃣ Go to Configuration → Data Sources
3️⃣ Click Add Data Source → Select Prometheus
4️⃣ Enter the Prometheus URL:

http://localhost:9090

5️⃣ Click Save & Test

🎉 Grafana is now connected to Prometheus!


📈 Step 4: Create a Monitoring Dashboard

1️⃣ In Grafana, go to Create → Dashboard
2️⃣ Click Add a New Panel
3️⃣ Use the query:

node_cpu_seconds_total

4️⃣ Click Apply
5️⃣ Customize the dashboard to show CPU, RAM, Disk Usage, Network Traffic, etc.

✅ You now have a real-time server monitoring dashboard!


🚨 Step 5: Set Up Alerts for Critical Issues

Grafana can send alerts via email, Slack, or Telegram when resource usage gets too high.

1️⃣ Go to Alerting → Notification Channels
2️⃣ Click New Channel and choose Email/Slack/Discord
3️⃣ Set the condition:

avg_over_time(node_cpu_seconds_total[5m]) > 90

4️⃣ Save and enable alerts

🚀 Now you’ll get notifications when CPU usage exceeds 90% for 5 minutes!


☁️ Want to Monitor Cloud Servers Instead?

You can set up Prometheus + Grafana on a Cloud VM to monitor multiple remote servers.

👉 Deploy on Vultr


🎯 Conclusion: Keep Your Server Healthy

With Prometheus + Grafana, you can:
Monitor CPU, RAM, Disk, Network Traffic
Visualize data with real-time dashboards
Set alerts to prevent downtime

💻 Need a powerful mini PC for self-hosting?
👉 Best AMD Mini PCs

📖 Want to Learn More About Linux Server Management?
👉 Best Linux OS Books

🔹 Have questions? Drop them in the comments below! 🚀

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *