Real-Time Server Monitoring with Grafana, Prometheus, and AWS: A Step-by-Step Guide
In modern DevOps, monitoring infrastructure health and performance is crucial. Real-time observability helps teams stay proactive, identify issues early, and ensure optimal performance. This guide will walk you through setting up real-time server monitoring using Grafana and Prometheus on AWS — a powerful stack that provides customizable, high-performance visualization and alerting.
Why Use Grafana and Prometheus?
Prometheus is a robust open-source time-series database designed for metrics collection and alerting.
Grafana offers rich data visualizations and dashboards for time-series data from various sources.
Combined with Amazon EC2, CloudWatch, or ECS, they offer a flexible monitoring stack for cloud-native environments.
Prerequisites
An active AWS account
One or more EC2 instances running Linux (Amazon Linux 2, Ubuntu, etc.)
Basic knowledge of SSH, Linux commands, and AWS security groups
Step 1: Launch EC2 Instances
Open AWS Console → EC2 → Launch Instance
Select a suitable AMI (Amazon Linux 2 or Ubuntu)
Choose instance type (e.g., t2.micro for testing)
Configure the security group to allow:
TCP 22 (SSH)
TCP 9090 (Prometheus)
TCP 3000 (Grafana)
Connect to the instance via SSH after launch.
Step 2: Install Prometheus on EC2
wget https://github.com/prometheus/prometheus/releases/download/v2.51.2/prometheus-2.51.2.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd prometheus-*
./prometheus --config.file=prometheus.yml
Update prometheus.yml to scrape metrics:
scrape_configs:
- job_name: 'ec2-metrics'
static_configs:
- targets: ['localhost:9100']
Install node_exporter for system metrics:
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.1/node_exporter-1.8.1.linux-amd64.tar.gz
tar xvfz node_exporter-*.tar.gz
cd node_exporter-*
./node_exporter &
Step 3: Install and Configure Grafana
sudo yum install -y https://dl.grafana.com/oss/release/grafana-10.4.2-1.x86_64.rpm
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
Visit http://<your-ec2-public-ip>:3000
Login (default: admin/admin)
Add Prometheus as a data source:
URL: http://localhost:9090
Import pre-built dashboards or create custom ones.
Step 4: Create Real-Time Dashboards and Alerts
Use metrics like:
node_cpu_seconds_total
node_memory_MemAvailable_bytes
node_network_receive_bytes_total
Set up alert rules in Prometheus or Grafana:
CPU > 90% for 5 minutes → trigger alert
Configure email/Slack/Webhook integrations for Grafana alerts
Optional: Monitoring Across Multiple AWS Regions
Use Prometheus federation or deploy agents in each region.
Use Amazon Managed Grafana and Amazon Managed Prometheus for scalability and lower ops overhead.
Secure endpoints using AWS IAM, TLS, or VPC Peering
Security Best Practices
Restrict Grafana/Prometheus ports using AWS Security Groups.
Use a reverse proxy with HTTPS (e.g., Nginx + Let's Encrypt)
Enable Grafana login hardening (OAuth, MFA)
Regularly update Grafana/Prometheus to patch vulnerabilities.

Comments
Post a Comment