Monitoring EC2 with custom metric
Host level metrics consists of:
- CPU
- Network
- Disk
- Status Check
Ram Utilization - is a custom metric
Custom Metrics - minimum granularity is 1 minute
Select IAM - Create a role - choose Ec2 as service - Select CloudWatchFullAccess policy - Give name for the role
Create an Ec2 instance - configure instance and add the created role and bootstrap script in Advanced Details shown below.
#!/bin/bash
yum update -y
sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64
cd /home/ec2-user/
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O
unzip CloudWatchMonitoringScripts-1.2.2.zip
rm -rf CloudWatchMonitoringScripts-1.2.2.zip
# Use the commands below for the lab.
# /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --verify --verbose
# /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail
# */1 * * * * root /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail
Create new security group - Allow SSH and HTTP - create new key - Launch
Give permission for new key and login
chmod 400 newkey.pem
ssh ec2-user@ip-address -i newkey.pem
sudo su
cd aws-scripts-mon
Verify
/home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --verify --verbose
To monitor memory-utilization,memory-used,memory-available
/home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail
Now in cloudwatch you can see above parameters
To monitor data every minute add below code in crontab
cd nano /etc/crontab
*/1 * * * * root /home/ec2-user/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail
- Monitoring EBS
Initailize Amazon EBS volumes
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-initialize.html
Monitor the status of your volumes
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-volume-status.html
- Monitoring ELB
Go to EC2 instance - Load Balancers - create Load Balancer - classic Load Balancer - add security groups - configure security settings - configure health check - add EC2 instance - add tag -create
Add Access logs
Go to EC2 instance - Load Balancers - select created load balancer - Enable Access log - add interval,location...
Monitoring Elasticcache
Metrics From Multiple Regions & Custom Dashboards
Go to cloudwatch - create Dashboards - add a line - Linux system - instanceid - select metric like ultilization,available,use - Add widget - save dashboard
- Create a billing alarm
Go to cloudwatch - Billing - create alarm - select usd,period,static,greater than condition and value of usd - create topic - add email - confirm or subscribe the email - add description
- AWS organization
1.Create an organisation - start now - Enable all feaures - Add
account - Invite account - Organize accounts
2.Create organizational unit - Move each Invite account to
corresponding necessary organizational unit.
3.Create policies - Deny/Allow the selected services - Add
statement
4.Go to Organize accounts - Enable service control policies -
Select organizational unit attach the policies.
- AWS Resource Groups and Tagging
Go to EC2 instance - choose AMI and instance type - configure instance(no.of instance 4) - Add storage - skip tags - configure security group - Launch
Go to Resource Groups - Tag Editor - add Region,Resource Types(AWS::EC2:Instance) - Search Resources - select the instances - Manage tags of selected resources - Add tag - Tag key,Tag value - Apply changes to all selected
Go to EC2 instance - select instance - Add/Edit Tags(Tag key is case sensitive)
Go to Resource Groups - create group - Tag based - All supported resource type - Add Tag key,Tag value - View group resources - Add Group name - create group
so we need to create Groups and tagging in other locations also, afterthat go to management and governance - system manager - Resource Groups(Left-side) - select resource group - view details - Execute Automation (eg.Terminate EC2 instance) - select execution(eg.simple,manual etc ..)
- Cost Explorer and Cost Allocation Tags
click on username(Right-top-corner) - My Billing Dashboard - cost allocation tags - select tags - Activate
Go to Cost Explorer - Launch cost explorer - cost explorer - select the required options
EC2 pricing models
AWS config
https://aws.amazon.com/config/faq/
Go to Management Tools - config - Get started - Enable All resources - Amazon S3 bucket - create a bucket - Enable create AWS config service linked-role - Next - AWS config rules - type "ssh" - Next - continue
Go to Management Tools - config - Resources - select Resource Type(like Instance,SecurityGroups) - Look up
Top comments (0)