Skip to main content

Command Palette

Search for a command to run...

Day 74 - Connecting EC2 with Grafana (Feb 8, 2024)

Updated
2 min read
Day 74 - Connecting EC2 with Grafana  (Feb 8, 2024)

Introduction

Monitoring the performance of your server infrastructure is crucial for ensuring optimal operation and identifying potential issues. In this tutorial, we'll explore how to set up Grafana and Prometheus to monitor CPU usage on Ubuntu instances. Grafana provides a powerful visualization interface, while Prometheus collects and stores metrics.

Prerequisites

Before we begin, make sure you have:

  • Two Ubuntu instances running on your preferred cloud provider (e.g., AWS, Azure).

  • SSH access to both instances.

  • Basic knowledge of Ubuntu commands and Prometheus/Grafana.

Step 1: Install Grafana on Ubuntu

sudo apt-get update
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y grafana
sudo systemctl enable grafana-server
sudo systemctl start grafana-server

Access Grafana by navigating to http://<your-ubuntu-instance-ip>:3000 in your browser, using the default login credentials (admin/admin).

Step 2: Configure Prometheus Data Source in Grafana

  1. Log in to Grafana.

  2. Go to "Settings" > "Data Sources."

  3. Click "Add your first data source."

  4. Choose "Prometheus" and enter the IP address of the second Ubuntu instance where Prometheus will run.

Step 3: Install Prometheus on the Second Ubuntu Instance

SSH into the second Ubuntu instance:

sudo apt-get update
sudo apt-get install -y prometheus
sudo systemctl enable prometheus
sudo systemctl start prometheus

Step 4: Configure Prometheus as a Data Source in Grafana

  1. Log in to Grafana.

  2. Go to "Settings" > "Data Sources."

  3. Click "Add your first data source."

  4. Choose "Prometheus" and enter the IP address of the second Ubuntu instance.

Step 5: Create CPU Usage Dashboard in Grafana

  1. In Grafana, go to the "+" menu on the left sidebar and choose "Dashboard."

  2. Add a new panel.

  3. Select the Prometheus data source.

  4. Use the following query to monitor user CPU usage:

  1.   rate(node_cpu_seconds_total{mode="user"}[1m])
    
  2. Configure visualization settings and save the panel.

Step 6: Explore and Analyze Metrics

Explore the Grafana dashboard to visualize and analyze CPU usage metrics from both Ubuntu instances. Customize panels and queries based on your monitoring requirements.

More from this blog

DevOps Journey with M Hassan

174 posts

I am writing these blogs because I recently completed a comprehensive DevOps course where I gained in-depth knowledge of the topics mentioned. As I progressed through the course, I realized the importance of having a concise and accessible resource to revise and reinforce my understanding of each topic. Therefore, I decided to create cheat sheets in the form of blog posts. These cheat sheets will not only serve as a handy reference for myself but also benefit others who are also interested in mastering DevOps concepts. By documenting each topic and providing concise explanations, I aim to create a valuable resource that simplifies complex concepts and facilitates hands-on practice. This way, I can solidify my own understanding while helping others on their DevOps journey.

Day 74 - Connecting EC2 with Grafana (Feb 8, 2024)