Cloudwatch Integration in Prometheus
Integrating Amazon CloudWatch with Prometheus provides a powerful monitoring solution. By configuring the Prometheus CloudWatch Exporter, you can collect CloudWatch metrics and expose them to Prometheus. This integration allows you to leverage Prometheus's querying and visualization capabilities while monitoring AWS resources and custom metrics. With consolidated data and proactive alerting, you gain deep visibility into your infrastructure for optimized performance and reliability.
Set up a Prometheus server: Install and configure Prometheus on your preferred server or container environment.
In this Blog, I have already downloaded Prometheus in EC2 instance.
Download the Cloudwatch jar file in the EC2 instance.
wget -O cloudwatch_exporter.jar http://search.maven.org/remotecontent?filepath=io/prometheus/cloudwatch/cloudwatch_exporter/0.8.0/cloudwatch_exporter-0.8.0-jar-with-dependencies.jar
Install Java in EC2 Instance
sudo apt-get install -y openjdk-11-jre-headless
The commands are used in the context of setting up AWS CLI (Command Line Interface) credentials on a Unix/Linux-based system.
mkdir -p ~/.aws/
vim ~/.aws/credentials
Add credentials in this file
[default]
aws_access_key_id=YOUR_ACCESS_KEY
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
Create file cloudwatchexporter.yaml and paste
region: us-east-1
metrics:
- aws_namespace: AWS/EC2
aws_metric_name: CPUUtilization
aws_dimensions: [InstanceId]
aws_statistics: [Average]
Add jobs in prometheus.yaml file
- job_name: cloudwatch
static_configs:
- targets: ['localhost:9106']
Add Iam role for user
create new user
Give name of the user
Give inline policy to user
Add this policy
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowListMetrics", "Effect": "Allow", "Action": [ "cloudwatch:ListMetrics", "cloudwatch:GetMetricStatistics" ], "Resource": "*" } ] }
Next click Review policy
Create policy
Take aws security credential
Run this command
/usr/bin/java -jar cloudwatch_exporter.jar 9106 cloudwatchexporter.yml
./prometheus
Run prometheus server
EC2 server matrics are shown in the Prometheus dashboard now you can integrate with grafana.