
Install Grafana and Prometheus on Ubuntu 22.04
In this guide, we will walk you through how to install Grafana and Prometheus on an Ubuntu Instance for easy monitoring and visualization. Follow these simple steps!
Prerequisite:
Ubuntu 22.04
Prometheus: 2.31.2
Grafana: 11.0
Step-by-step instructions to install Grafana and Prometheus
Step 1: Update and upgrade the system:
To update and upgrade the package lists from the repositories, run the following command:
sudo apt-get update -y
sudo apt-get upgrade -y
Step 2: Install Grafana:
Add the Grafana repository to your system. Open a terminal and run the following commands:
sudo apt-get install -y software-properties-common

Add the Grafana package signing key and Install Grafana
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"

curl https://packages.grafana.com/gpg.key | sudo apt-key add -

After adding the keys, update the system and install Grafana
sudo apt-get update && sudo apt-get install -y grafana

Start the Grafana service and enable it to start automatically at system reboot using the following commands:
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
Step 3: Install Prometheus:
Install Prometheus using the following command:
sudo apt-get install prometheus -y

Start the Prometheus service and enable it to start automatically at system reboot using the following commands:
sudo systemctl start prometheus
sudo systemctl enable prometheus
Check the version of Grafana and Prometheus:
Checking the Grafana Version
To check the version of Grafana, run the curl command using the server IP and Grafana port number.
curl http://your_server_ip:3000/api/health

Check the version of Prometheus
To check the version of Prometheus, run these commands.
prometheus --version

Access Grafana via browser:
Access Grafana through a web browser: Open a web browser and go to http://Your_Server_IP:3000. Log in with the default username and password (admin/admin). Follow the on-screen instructions to set up Grafana. Once loaded, you should see the Grafana login page. The default credentials are:
username: admin
password: admin

You'll be prompted to create a new password. Input a secure password, confirm it, and click the "Submit" button.

Attaching Prometheus to Grafana following these steps
Add Prometheus as a data source
Click on the Grafana icon in the top left corner to show the main menu
Select Data Sources.

Click Add Data Source.
Choose Prometheus as the type.

Set the URL to http://localhost:9090 (or the appropriate URL if Prometheus is on a different server).
Now click on the Save & Test.

Now create a dashboard.

Click on the Import Dashboard.


Import the dashboard and save the dashboard back to the dashboard section click on the created dashboard and add visualization.



After selecting Prometheus now configure the dashboard.
Select the matrix, define the labels, select the value, and run the query.

Upon running the queries, the status is displayed, and if you wish to modify the GRAF, simply click on the right side of the time series.

Key Features of Prometheus:
Multi-dimensional Data Model: Uses key-value pairs for labels to identify metrics uniquely.
Powerful Query Language (PromQL): Allows flexible and high-dimensional data querying.
Pull-based Collection: Scrapes metrics from HTTP endpoints at the targets' intervals.
Alerting: Integrated alert manager that handles alerts based on PromQL expressions.
Compatibility: Works well with containerized environments like Kubernetes.\
Last updated