Skip to main content

πŸš€ Install and Configure Grafana with Prometheus πŸ“Š

Step 1: Update System & Install Dependencies βš™οΈβ€‹

Before installing Grafana, ensure your system is updated and required dependencies are installed.

sudo apt update
sudo apt install -y software-properties-common

Step 2: Add Grafana Repository πŸ—οΈβ€‹

Grafana is not included in the default Ubuntu repository, so we need to add the official Grafana repository.

wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee /etc/apt/sources.list.d/grafana.list

Step 3: Install Grafana πŸ–₯️​

After adding the repository, install Grafana using the following command:

sudo apt update && sudo apt install -y grafana

Step 4: Configure Grafana πŸ”§β€‹

To modify Grafana settings, open the configuration file:

sudo nano /etc/grafana/grafana.ini

Modify the following lines to allow external access:

[server]
protocol = http
http_addr = 0.0.0.0 # Allows access from any device
http_port = 3000
domain = 13.232.111.4 # Set your public IP if accessing Grafana externally

This configuration ensures Grafana is accessible from anywhere.

Step 5: Start and Enable Grafana Service πŸš€β€‹

Now, reload the system daemon and enable Grafana to start on boot.

sudo systemctl daemon-reload
sudo systemctl enable --now grafana-server
sudo systemctl status grafana-server

This ensures Grafana runs automatically after every system reboot.

Step 6: Access Grafana πŸŒβ€‹

Open your browser and navigate to:

http://13.232.111.4:3000/login

The default username and password are:

  • Username: admin
  • Password: admin (you will be prompted to change it on first login)

Step 7: Add Prometheus as a Data Source πŸ”—β€‹

To connect Grafana with Prometheus, follow these steps:

  1. Login to Grafana
  2. Go to βš™οΈ Settings β†’ Data Sources
  3. Click Add Data Source
  4. Select Prometheus
  5. In URL, enter:
http://13.232.111.4:9090
  1. Click Save & Test to confirm connectivity.

Step 8: Build Dashboard πŸ“Šβ€‹

  • Navigate to Dashboards β†’ New Dashboard β†’ Add a New Panel.
  • Use Node Exporter to visualize system metrics like CPU, Memory, Disk, and Network.
  • Save the dashboard for real-time monitoring.

🌍 Running Grafana on a Domain 🏠

Step 1: Modify Grafana Configuration πŸ“β€‹

If you want to access Grafana via a custom domain, modify the configuration:

sudo nano /etc/grafana/grafana.ini

Add the following line:

root_url = %(protocol)s://grafana.asifahmadkhan.com/

This sets up Grafana to be accessible using the custom domain.

Step 2: Install & Configure Nginx πŸŒβ€‹

Nginx will act as a reverse proxy to forward requests to Grafana.

sudo apt update && sudo apt install -y nginx
sudo systemctl status nginx

Create an Nginx configuration file:

sudo nano /etc/nginx/sites-available/grafana.asifahmadkhan.com.conf

Add the following content:

server {
listen 80;
server_name grafana.asifahmadkhan.com;

location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

This configuration ensures all requests to grafana.asifahmadkhan.com are forwarded to the local Grafana service running on port 3000.

Step 3: Point Your Domain to the Server πŸ—οΈβ€‹

Log in to your domain registrar and update the A record to point to your server’s IP.

Step 4: Secure with SSL πŸ”’β€‹

Use Let's Encrypt to secure Grafana with HTTPS:

certbot --nginx -d grafana.asifahmadkhan.com

This command will obtain an SSL certificate and automatically configure Nginx for HTTPS.


πŸŽ‰ Congratulations! Grafana is now accessible at:

https://grafana.asifahmadkhan.com

πŸš€ Happy Monitoring! πŸ“ˆ