How To Monitor Linux Machines Using Prometheus and Grafana

Reading Time: 4 minutes

Hi, readers in this blog will see How To Monitor Linux Machines Using Prometheus and Grafana. I will create an ec2 instance and will monitor that instance using Prometheus and Grafana.


Prometheus is the central component that collects the metrics from multiple nodes. It uses the concept of scraping, where target systems’ metric endpoints are contacted to fetch data at regular intervals.

Node Exporter

So to monitor a Linux machine we need a Node Exporter that is used to pull Linux system metrics like CPU load and disk I/O. Node Exporter will expose these as Prometheus-style metrics.

So first I am going to launch two ec2 instances on AWS.on one ec2 instance we will install Prometheus and Grafana and on the other ec2 instance we will install node exporter.

Make sure to add these ports where Prometheus Server is installed.

And below ports on Linux-server where node exporter is installed.

Install NodeExporter

So First install the node exporter on the machine to which we will monitor. To install use the below command to install run:

sudo wget
sudo tar xf node_exporter-1.3.1.linux-amd64.tar.gz

Make sure port 9100 is open from your IP to access this URL. You should be able to access all the metrics which is coming from this server

Install Prometheus and Grafana

SSH into the ec2 and run the following script file into your instance it will download and start the Prometheus on your ec2.

sudo wget
sudo tar xf prometheus-2.36.0-rc0.linux-amd64.tar.gz 
cd prometheus-2.36.0-rc0.linux-amd64/
sudo ./prometheus

Before running the Prometheus Server first let’s do some changes to prometheus.yml file. Under the static_configs: specify the target that is the Private IP of your Monitoring instance.

Copy the public IP and hit into the browser, then go to Status->targets, you will see the endpoint with IP that you have specified under the prometheus.yml file

Also, you can refer to the official document of Prometheus to install it.

Install Grafana

Grafana is an open-source tool that is use to provide the visualization of your metrics. Grafana is a complete observability stack that allows you to monitor and analyze metrics, logs, and traces. It allows you to query, visualize, alert on, and know your data no matter where the data is. To install Grafana use the given command.

sudo apt-get install -y apt-transport-https
sudo apt-get install -y software-properties-common wget
wget -q -O - | sudo apt-key add -
echo "deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana

Also, you can refer official document of Grafana to install it.

Take the public_IP:3000 and hit into the browser to access the Grafana UI. Login to the Grafana using the initial username and password.After the create a data source. Add prometheus DataSource.Click on Setting ->datasources.

Here I am giving the URL using private_IP because Prometheus and Grafana are installing on the same Instance so they can easily communicate using private_IP.

Save the data source and now it’s time to create a dashboard.

Import The Dashboard Of Linux Machine

Click on + icon -> Import

You can use the JSON file or id for the dashboard here I am going to use the 10204 id for Node Exporter Dashboard. Click on load and after that choose the data source that you have created earlier and click on import.

This is how the dashboard will look like and provide all the metrics for your node.


Thank You for sticking to the last. We have successfully learned how to monitor the AWS EC2 instances using Prometheus and visualize the dashboard using Grafana. Please do let me know if you have any suggestions or improvements.


Written by 

Jubair Ahmad is a Software Consultant (DevOps)at Knoldus.Inc.He loves learning new technology and also have interest in playing cricket.