![]() To get monitoring set up, you’ll need to install the CloudWatch Agent on your EC2s in order to get the memory and disk usage of your instance. I’ll briefly cover this a bit, just to make this guide a little more complete. This will be what I’ll be focusing on in this guide. ![]() So, the solution is to create these alarms automatically when an instance is started, and delete these alarms when an instance is terminated. You could get around this by dropping the instance ID from the metric, but then you wouldn’t know which instance the alarm is ringing for. This means that a manually created alarm is going to become irrelevant once the EC2 is terminated, and new instances will not have any alarms. If your EC2s are controlled by auto scaling groups, then your instance IDs are always changing. But since your metrics should be well organized, you would want to put these metrics inside namespaces, which are further defined with things like the instance ID, the name of the disk, and the actual memory/disk usage itself. You see, AWS alarms require that the source of the metrics be fully defined. Usually, this is a simple affair, assuming the source of the metrics never change. So, creating alarms was the natural next step. No one is going to stare at the graphs 24/7. However, having metrics without alarms was kind of useless. A quick Google search, first result, and there’s documentation on AWS giving a detailed step by step guide on how to do this. However, there are still some very important metrics that are missing: memory utilization and disk usage.įinding out how to set up the collection of these metrics was easy enough. AWS automatically sets you up with some metrics, such as CPU Utilization, network in/out, and status checks. Add period in seconds for after how much time you want datapoints.If you’ve ever managed servers, you should know that there are some metrics that you should keep an eye on.Please put arn of your sns(simple notofication service) to which you want to send email when alarm triggers.so that when value goes beyond to threshold it will trigger the alarm I have used GreaterThanOrEqualToThreshold. you can have different comparison_operator.Dimension for mem_used_percent would be only InstanceId and for disk_used_percent i have provided in github main.tf.In metric name write disk_used_percent and mem_used_percent respectively for both alarms.We have aws_cloudwatch_metric_alarm resource in terraform to deal with aws alarms.This is my github repo link for disk usage only. After sometime the metric will be visible in cloudwatch metric under CWAgent Creating Cloudwatch Alarms using terraform sudo systemctl restart amazon-cloudwatch-agent. sudo nano /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.jsonĤ. First assign a role to your ec2, giving it full cloudwatch accessĢ.īefore going to create alarm we first need to configure cloudwatch agent for our metrics. This will sudo rpm -U amazon-cloudwatch-agent.rpm.Let us say we have already one ec2 instance running. Here i will be downloading cloudwatch agent on Amazon Linux Machine(Red hat based). Downloading and Installing Cloudwatch Agent cloudwatch agent will be sending the variety of metrics from our ec2 to cloudwatch. Some metrics are directly going from ec2 and we can use them in our alarm but metrics like disk usage and memory usage we need to install cloudwatch agent in our ec2. ![]() Using alarm we can keep an eye on whether our usage has gone beyond the threshold value, if gone beyond then we can use sns(simple notification service) to send a mail to the user informing/alerting about the same.īefore going further in the alarm let us know one thing that there are namespaces. IntroductionĪlarm:- In AWS we have concept of cloudwatch alarms from where we can track various metric on our ec2. Hi all, in this post we will be going to learn about what are cloudwatch alarms, how to create cloudwatch alarms using terraform as in many use cases we need to provision infrastructure using IAAC(Infrastructure as a code), here terraform.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |