Setting Up Prometheus and Grafana
First, download the latest Prometheus version from the official website. You can do this via wget or curl. After downloading, unpack the tarball.
# Download and Unpack Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-2.30.3.linux-amd64.tar.gzFor easier access, you can move the Prometheus and Promtool binaries to /usr/local/bin/.
sudo mv prometheus-2.30.3.linux-amd64/prometheus /usr/local/bin/
sudo mv prometheus-2.30.3.linux-amd64/promtool /usr/local/bin/Create a prometheus.yml file. You can place this in a directory of your choice; for this example, let's use /etc/prometheus/
sudo mkdir /etc/prometheus
sudo nano /etc/prometheus/prometheus.ymlAdd the following content to prometheus.yml. This is a simple configuration to scrape metrics from itself:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']In summary, this configuration tells Prometheus to scrape metrics from itself every 15 seconds. This is often useful for getting started and testing, but in a production environment, you’d replace or augment this with configurations that scrape your actual services and applications.
Save the file and exit the text editor. You can now run Prometheus with the following command:
prometheus --config.file=/etc/prometheus/prometheus.yml
You should be able to access the Prometheus UI by navigating to http://localhost:9090.

Install Grafana
Add APT Repository and Install Grafana
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install grafanaEnable and Start Grafana Service
sudo systemctl enable grafana-server
sudo systemctl start grafana-serverNow Grafana should be running, and you can access the UI by navigating to http://localhost:3000. The default login is admin for the username and admin for the password.
Configure Grafana to Use Prometheus
Add Data Source
- Log in to Grafana (
http://localhost:3000). - Go to
Settings -> Data Sources -> Add data source. - Choose
Prometheus. - Set the URL to
http://localhost:9090. - Click
Save & Test.
You now have Prometheus and Grafana installed and configured. Prometheus is scraping metrics, and Grafana is ready to visualize them. You can start creating dashboards in Grafana to visualize your Prometheus metrics.
Subscribe to my newsletter to get access to all the content I’ll be publishing in the future.
