π 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:
- Login to Grafana
- Go to βοΈ Settings β Data Sources
- Click Add Data Source
- Select Prometheus
- In URL, enter:
http://13.232.111.4:9090
- 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! π