Logo

dev-resources.site

for different kinds of informations.

Monitor Your Static App memory usage EC2 Instances with Prometheus and Grafana

Published at
1/12/2025
Categories
aws
prometheus
monitoring
grafana
Author
yashvikothari
Categories
4 categories in total
aws
open
prometheus
open
monitoring
open
grafana
open
Author
13 person written this
yashvikothari
open
Monitor Your Static App memory usage EC2 Instances with Prometheus and Grafana

This blog post will guide you through setting up Prometheus and Grafana on a launched Ubuntu EC2 instance to monitor CPU and memory utilization metrics, and then visualize them in Grafana dashboards for effective resource allocation / optimization.

Prerequisites:

1.An AWS account with an EC2 instance launched and running Ubuntu.
2.SSH access to your EC2 instance with a PEM key file.

Image description

🔍 Objective:

1.Configure Prometheus to scrape metrics from EC2 instances

2.Set up Grafana to visualize CPU and memory utilization metrics

3.Create dashboards in Grafana for monitoring and analysis

4.Optimize resource allocation based on monitoring data

Step 1: Launch an Ubuntu EC2 Instance

Log in to your AWS Management Console and navigate to the EC2 service.
Click on "Launch Instance".
Choose an Ubuntu AMI (Amazon Machine Image).
Select an appropriate instance type based on your requirements.
Configure instance details like storage, security group, and networking.
Launch the instance.

Image description

Step 2: Install and Configure Prometheus

Connect to your EC2 instance using SSH with your PEM key file.

`


ssh -i "yashvikotharivm1_pem_key.pem" ubuntu@<your_public_ip_address.awsamazon.com>

`

Update the package lists:

sudo apt update

Install Prometheus:

sudo apt install prometheus

Edit the Prometheus configuration file (/etc/prometheus/prometheus.yml):

sudo nano /etc/prometheus/prometheus.yml

Add the following configuration snippet to scrape metrics from NodeExporter (a Prometheus exporter that collects system metrics):

YAML

scrape_configs:
  - job_name: node_exporter
    static_configs:
      - targets: ["localhost:9101"]
Enter fullscreen mode Exit fullscreen mode

Note: The default port for Prometheus scraping targets is 9090, but NodeExporter uses a different port (9101) to avoid conflicts.

Save the changes and restart Prometheus:
sudo systemctl restart prometheus
Step 3: Install and Configure Grafana`

Install Grafana:

sudo apt install grafana
Configure security groups to allow inbound traffic on port 3000 (Grafana's default web interface port).

Image description

Restart Grafana:
sudo systemctl restart grafana
Access the Grafana web interface:
http://:3000

Step 4: Add Prometheus as a Data Source in Grafana

Log in to Grafana using the default credentials (username: admin, password: admin).
Navigate to "Configuration" > "Data Sources".
Click "Add data source".
Select "Prometheus" as the type.
Enter the URL of your Prometheus instance (http://localhost:9090) in the "URL" field.
Click "Save & Test" to establish the connection.
Step 5: Create a Dashboard in Grafana

Image description

Click on "Dashboards" and then "New dashboard".
Give your dashboard a name (e.g., "EC2 Instance Monitoring").
Click "Add panel" and select "Graph" as the panel type.
In the "Title" field, enter "CPU Usage".
In the "Metrics" tab, select "Prometheus" as the data source.
In the "Query" box, paste the following query to visualize CPU usage:
rate(node_exporter_cpu_usage{job="node_exporter"}[1m])
Click "Save" to save the panel.

Image description

Repeat steps 5-7 to create additional panels for memory utilization or other metrics you want to monitor.

Image description

You can customize the panels with different visualizations (e.g., line graphs, heatmaps) and adjust the time range to view

Image description

Image description

Image description

Image description

More details available as below in github
(Complete Live project notes will be provided soon):-

Image description

monitoring Article's
30 articles in total
Favicon
Why Successful Companies Don't Have DBAs
Favicon
Monitor Your Static App memory usage EC2 Instances with Prometheus and Grafana
Favicon
From Overspending to Savings: 5 Ways to Tame Your AWS Bill
Favicon
How to Integrate and Configure Zabbix for Monitoring IT Infrastructure
Favicon
CodeIgniter Monitoring Library – Born from Understanding Real Developer Needs
Favicon
Observability 2.0 - The Best Thing Since Sliced Bread
Favicon
Understanding CPU Performance: A Detailed Guide to Comparing Processors for Optimal Computing
Favicon
Scraping Custom Django Metrics with Prometheus
Favicon
Optimize and Monitor Power Apps Like a Pro with Application Insights
Favicon
Top 10 Tips for Optimizing Software Performance
Favicon
GPS Monitoring function on SVMS Pro video management software has been released .
Favicon
OpenSearch metrics challenge: can you spot the performance flaw?
Favicon
Netdata Memory Alert on Minisforum MS-01: My Experience and Thoughts
Favicon
BEST PRACTICES FOR DEFINING METRICS
Favicon
How And Why The Developer-First Approach Is Changing The Observability Landscape
Favicon
Prometheus
Favicon
Motion Detection Software Development
Favicon
Metrics Mayhem
Favicon
Configure monit service in AL2023
Favicon
Best Computer Tracking Software to Monitor Productivity and Security
Favicon
Understanding Observability: Benefits for Your Organization and Key Differences from Monitoring
Favicon
Module 10: Automatic Scaling and Monitoring in AWS
Favicon
3 Things You Need To Take Control Of Your Database
Favicon
How to Connect a Gaming PC to a Monitor
Favicon
What are the best logging and monitoring tools for .NET apps
Favicon
prometheus
Favicon
They Stopped Using Load Tests - And Here Is Why
Favicon
Unable to access the Documenso Server
Favicon
OpenTelemetry Collector Implementation Guide: Unified Observability for Modern Systems
Favicon
Monitoring and Observability Tools: A Comprehensive Guide Including Network Packets and Logging Tools

Featured ones: