0% found this document useful (0 votes)
34 views

Monitoring Ec2 Instance

Uploaded by

Kshitij Aggarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Monitoring Ec2 Instance

Uploaded by

Kshitij Aggarwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Monitoring EC2 Instance using Prometheus and

Grafana
How Grafana and Prometheus work together
Grafana and Prometheus are probably the most prominent
tools in the application monitoring and analytics
space. Prometheus is an open-source monitoring and alerting
platform that collects and stores metrics as time-series data
Grafana is an open-source analytics and interactive
visualization web application. It allows you to ingest data
from a huge number of data sources, query this data, and
display it on beautiful customizable charts for easy analysis. It
is also possible to, set alerts so you can quickly and easily be
notified of abnormal behavior and lots more.

Agenda:
1. Install Prometheus and configure Prometheus to monitor
itself
2. Install Node Exporter on the other EC2 Instances
3. Configure Prometheus for the EC2 Instance
4. Install Grafana
Requirement:
Launching 3 Amazon linux instances

Pawar Divya
Solution :
• Step 1: Security groups configures on EC2 Instances
Prometheus security group port number 9090 enabled

Grafana security group port number 3000 enabled

Prometheus node exporter security group port number 9100


enabled

1. Installing Prometheus
Launch one instance.
$ sudo yum install git

$ git clone https://github.com/Phanindra-Sangers/prometheus-monitoring.git

$ cd prometheus-monitoring

$ ./install-prometheus.sh

Pawar Divya
This script will install everything and configured it.
• Creates a new user and add new directories
sudo useradd --no-create-home prometheus
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus

Downloads the Prometheus, extract it and put it


in /usr/local/bin folder and finally delete the software
wget
https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-
2.23.0.linux-amd64.tar.gz

sudo cp -r prometheus-2.23.0.linux-amd64/console_libraries /etc/prometheus

tar -xvf prometheus-2.23.0.linux-amd64.tar.gz


sudo cp prometheus-2.23.0.linux-amd64/prometheus /usr/local/bin
sudo cp prometheus-2.23.0.linux-amd64/promtool /usr/local/bin
sudo
sudocpcp-rprometheus-2.23.0.linux-amd64/promtool
prometheus-2.23.0.linux-amd64/consoles/usr/local/bin/
/etc/prometheus/

rm -rf prometheus-2.23.0.linux-amd64.tar.gz prometheus-2.19.0.linux-amd64

2. Now we will configure Prometheus to monitor itself


using yaml file.

Create a prometheus.yml file at


/etc/prometheus/prometheus.yml with the below content.
$ cd /etc/prometheus
$ vi prometheus.yml

Pawar Divya
• copy the following content in yml file.

Now we want to run the Prometheus as a Service so that in


case of server restart service will come automatically
• Create a file at

$ cd /etc/systemd/system/
$ vi prometheus.service

• copy the below content in the service file

Pawar Divya
• Save and exit.
Change the ownership of all folders and files which we have
created to the user which we have created in the first step
sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
sudo chown -R prometheus:prometheus /var/lib/prometheus

Now we will configure the service and start it


sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl start prometheus
sudo systemctl status prometheus

now you can access the prometheus dashboard


http://<prometheus-public-ip>:9090

➢ Step 2 : Install Node Exporter


Launch one more instance i.e Node exporter
$ sudo yum install -y git
$ git clone
Pawar https://github.com/Phanindra-Sangers/prometheus-monitoring.git
Divya
1. Now to monitor your servers you need to install the
node exporter on all your target machine which is like
a monitoring agent on all the servers.
cd prometheus-monitoring/
./install-node-exportr.sh

This script will do the below steps:

sudo useradd --no-create-home node_exporter


wget
https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporte
r-1.0.1.linux-amd64.tar.gz
tar xzf node_exporter-1.0.1.linux-amd64.tar.gz
sudo cp node_exporter-1.0.1.linux-amd64/node_exporter /usr/local/bin/node_exporter
rm -rf node_exporter-1.0.1.linux-amd64.tar.gz node_exporter-1.0.1.linux-amd64
sudo cp node-exporter.service /etc/systemd/system/node-exporter.service
sudo systemctl daemon-reload
sudo systemctl enable node-exporter
sudoIt systemctl
will create
start a new user , download the software
node-exporter
sudousing wget
systemctl andnode-exporter
status then run the node-exporter as a service

Access the Node Exporter using

http:<node-exporter-public-ip>:9100

Pawar Divya
➢ Step 3: Configure Prometheus for the Nodes
Now we will configure the Prometheus for our EC2 instance
where we have installed the node-exporter.
Login to the Prometheus server and edit the file file at
location in Prometheus instance

/etc/prometheus/prometheus.yml

Restart the Prometheus service

sudo systemctl restart prometheus


sudo systemctl status prometheus

Now you can open the Prometheus using below url and can
see the new targets added

http://<prometheus-public-ip>:9090/targets

Pawar Divya
➢ Step 4: Install Grafana
Once Prometheus is installed successfully then we can install
the Grafana and configure Prometheus as a datasource.
Grafana is an opensource tool which is used to provide the
visualization of your metrics.
1. Steps to Install:
2. Run the below file for apt-get pckg manager

3. Untar the downloaded file.

Pawar Divya
4. Start the service and check the status

5. Now open it on the browser using below url:


*Make sure that port 3000 is open for this instance.
http://<grafana-public-ip>:3000

Login with username: admin and password admin

Pawar Divya
Add Prometheus DataSource
Click on setting > Data sources

Click on Add data source

Pawar Divya
Click on Prometheus

Mention your Prometheus IP

Pawar Divya
Scroll down click save and test.

Click on Explore > select Prometheus as a datasource

Now click on metrics > Select Up > Run query

Pawar Divya
You will get dashboards

Grafana provides lot of dashboards which we can directly


import in our Grafana instance and use it.
Import the dashboard
Click on Dashboards > click on Import

Pawar Divya
Click on Load

Select the node to configure [Prometheus] > select Import

Pawar Divya
Conclusion :
We have come to know how to install Prometheus and
grafana to monitor Ec2 instances

Pawar Divya

You might also like