Configuring Prometheus, Node-exporter and Grafana in a EC2 instance

Configuring Prometheus, Node-exporter and Grafana in a EC2 instance

Creation of EC2 instance

  1. Go to AWS console and create an EC2 instance with ubuntu OS.

  2. Open all the below inbound ports to run specific services

    • Port: 9090 - Prometheus

    • Port: 9100 - Node-Exporter

    • Port: 3000 - Grafana

    • Port: 22 - SSH

  3. After connecting to the instance, run the below command to check all entries of the “apt” packages list to see if any update is available for any package from all of the sources

     sudo apt-get update
    

Installing and running prometheus

Prometheus Monitoring is a powerful tool for monitoring computer systems and applications. It continuously collects data about system performance and stores it in a time-series database that enables you to identify and diagnose problems, set up alerts, and optimize your systems for maximum efficiency.

  1. Go to https://prometheus.io/download/

  2. Under the Prometheus section copy the compressed file link for Linux OS LTS version.

  3. Come to the terminal and download the file.

     wget <URL of the Copied .tar.gz File>
    
  4. Now extract the prometheus compressed file

     tar -xvfz <Promethus .tar.gz filename>
    
  5. Change the directory after extracting Prometheus and you'll find these files

  6. Now by shell following below command start the prometheus server

     ./prometheus
    

  7. Now Prometheus server is running in the EC2 public IP with port 9090

    http://<EC2 Public IP>:9090/

Installing and Running Node Exporter

The Node Exporter is an agent that gathers system metrics and exposes them in a format which can be ingested by Prometheus. The Node Exporter is a project that is maintained through the Prometheus project.

  1. Go to https://prometheus.io/download/

  2. Under the node_exporter section copy the compressed file link for Linux OS.

  3. Come to the duplicate tab terminal and download the file.

     wget <URL of the Copied .tar.gz File>
    
  4. Now extract the node-exporter compressed file

     tar -xvfz <node-exporter .tar.gz filename>
    
  5. Change the directory after extracting node-exporter and you'll find these files

  6. Now by shell following below command start the node-exporter server

     ./node_exporter
    

  7. Now Node-Exporter server is running in the EC2 public IP with port 9090

    http://<EC2 Public IP>:9100/

Adding node exporter scrap_configs to prometheus as YAML format

  1. In other Tab, Go to Prometheus folder and create a file named exported.yml using below command.

     touch exporter.yml
    

    Note: File name can be anything

  2. Insert the below scrap configuration in exporter.yml and save it.

     global:
        scrape_interval: 15s
    
     scrape_configs:
        - job_name: node-exporter
          static_configs:
             - targets: ['localhost:9100']
    

    Note: Since my node exporter IP is same as Promethus server IP (as both are installed in one VM or EC2), I'm using localhost:9100 as 9100 is node-exporter port. We can add any number of node exporter in the following format,

    static_configs:

    - targets: ['localhost:9100', '172.163.0.0:9100', '19.168.0.54:9100']

  3. Now run the prometheus server using the below command.

     ./prometheus --config-file=exporter.yml
     (or)
     ./promethus --config-file=<your_filename>.yml
    
  4. Open the promethus server and Go to targets.

  5. Refresh and you'll see node-exporter is UP.

Installing and Running Grafana

Grafana is a multi-platform open source analytics and interactive visualization web application. It provides charts, graphs, and alerts for the web when connected to supported data sources.

  1. Update the package info

     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 -
    
  2. Add stable repository of Grafana

     echo "deb https://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 Grafana server and enable it to run at boot time

     sudo systemctl daemon-reload
     sudo systemctl start grafana-server
     sudo systemctl status grafana-server
     sudo systemctl enable grafana-server.service
    
  5. Access grafana server in URL with port 3000

    http://<EC2 Public IP>:3000/

  6. Login with Username: admin and Password: admin

  7. Go to add your first data source

  8. Search and select prometheus

  9. Add URL under the connection

    Note: As Grafana and Prometheus are installed in same VM or EC2, i have given localhost:9090 as 9090 port is where prometheus running in our EC2.

  10. And click Save and Test

  11. Go back to Grafana home page and select Create your first Dashboard.

  12. Click on Import a Dashboard

  13. Search for node-exporter id for grafana or go to the link and search the node exporter dashboard and copy the ID https://grafana.com/grafana/dashboards/

  14. Paste the ID and Click on Load

  15. Choose prometheus source and Import

  16. Now finally this is the Dashboard we see