Setup Prometheus, Node Exporter and Grafana

Setup Prometheus, Node Exporter and Grafana

In this blog post, we are going to talk about two popular open-source tools Prometheus and Grafana. This blog post is aimed at anyone who is trying to learn Prometheus and Grafana or has some experience with these tools.

This is going to be a very beginners guide where we will start from -

What is Prometheus? - It is an open-source tool for scrapping the performance metrics of any given hardware resource (CPU, VM, Cloud Virtual Machine, Router, etc.). Prometheus scraps the data with the timestamp which can be stored on a server and accessed using the PromQL. Prometheus has superb support API which makes Prometheus integration with any resource present in the Datacenter. Prometheus architecture is really scalable and 3rd party libraries and makes it more powerful.

What is Grafana? - Grafana is an open-source analytics and visualization tool. Grafana does not store any data, but instead, it relies on Prometheus to send the data so that dashboard can be prepared. Also, Grafana is used for sending notifications and mail alerts based on various thresholds. One of the cool features of the Grafana is Grafana Labs where you can go and download the dashboard prepared by other developers so that you do not have to re-invent the wheel.

Installation of Prometheus:-

  1. Go to the download page of Prometheus and and select the Linux file for download. We are using Linux OS so copy Linux Prometheus file.

  2. Now I am creating one Prometheus folder and there I will paste the link using wget command.

  3. Extract the download binary file.

    "tar -xvzf prometheus-2.50.0-rc.0.linux-amd64.tar.gz"

  4. Go into the extracted directory "cd prometheus-2.50.0-rc.0.linux-amd64"

  5. Start the prometheus server with the command "./prometheus"

  6. Prometheus is by default running on port no 9090. So open the same port no into security group of your Linux machine.

  7. Copy the public ip with port no 9090 and you will able to access Prometheus page. (https://43.204.215.172:9090/)

    Installation of Node Exporter

    Node exporter is responsible for fetching the statistics from various hardware and virtual resources in the format which Prometheus can understand and with the help of the Prometheus server those statistics can be exposed on port 9100.

    There are many third-party Node exporters which can be used by SREs as well as DevOps based on their application needs. But primarily we look for the following metrics -

    1. CPU usage

    2. Memory usage

    3. Disk usage

    4. Network usage

1. Download the binary of Node Exporter based on the operating system. Create one folder and paste the node exporter link with wget command

2. Extract the download node exporter binary file.

3. Go into the extracted directory

4. Start the node exported with the command

5. Open the port no 9100 in the security group then you are able to access node exporter page

Metrics also coming from node exporter

Installation of Grafana

After installing the Prometheus server and node exporter let's install the Grafana for setting up visualization using Grafana dashboard. Choose the correct Grafana binary based on your operating system. Here I am using ubuntu Linux binary.

Steps for Installing Grafana-

In this installation, we are going to install the latest enterprise edition Grafana.

  1. Update the package information
    "sudo apt-get install -y apt-transport-https 3sudo apt-get install -y" "software-properties-common wget 4wget -q -O -" "packages.grafana.com/gpg.key | sudo apt-key add -"

  2. Add stable repository of Grafana

    "echo "deb packages.grafana.com/enterprise/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list"

  3. Update repository and Install Grafana

    "sudo apt-get update"
    "sudo apt-get install grafana-enterprise"

  4. Start the Grafana Server -

    "sudo systemctl daemon-reload"
    "sudo systemctl start grafana-server"
    "sudo systemctl status grafana-server"

  5. Open the port no 3000 in security group and access the Grafana Page "http://43.204.215.172:3000/login"

    The default login Username: Password for accessing the Grafana dashboard is admin: admin

    Grafana is an analytics and visualization dashboard, Grafana does not store data, but instead it relies on Datasource connection towards the Prometheus server because Prometheus server is responsible for scraping and storing the data.

Let's create a Prometheus Datasource inside Grafana Dashboard

  1. Goto your Grafana Dashboard and click on Connection --> Data Sources --> Add data source

Now let's create the Dashboard. Here I am going to import the dashboard which is already created by someone.

Conclusion:

Grafana and Prometheus are a really popular frameworks for monitoring, alerting, and data visualization. Hope You all are getting this. If you stuck anywhere please reach out to me. Thank You.