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.
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.
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 https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz sudo tar xf node_exporter-1.3.1.linux-amd64.tar.gz ./node_exporter
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
prometheus.sh script file into your instance it will download and start the Prometheus on your ec2.
sudo wget https://github.com/prometheus/prometheus/releases/download/v2.36.0-rc0/prometheus-2.36.0-rc0.linux-amd64.tar.gz 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
Also, you can refer to the official document of Prometheus to install it.
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 - https://packages.grafana.com/gpg.key | sudo apt-key add - echo "deb https://packages.grafana.com/oss/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.
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.