[ACCEPTED]-How do I set up CloudWatch to detect when an EC2 instance goes down?-amazon-cloudwatch
Amazon's Route 53 Health Check is the right 7 tool for the job.
Route 53 can monitor the 6 health and performance of your application 5 as well as your web servers and other resources.
You 4 can set up HTTP resource checks in Route 3 53 that will trigger an e-mail notification 2 if the server is down or responding with 1 an error.
To monitor an event in CloudWatch you create 15 an Alarm, which monitors a metric against a given 14 threshold.
When creating an alarm you can 13 add an "action" for sending a 12 notification. AWS handles notifications 11 through SNS (Simple Notification Service). You 10 can subscribe to a notification topic and 9 then you'll receive an email for you alarm.
For 8 EC2 metrics like CPU or disk utilization 7 this is the guide from the AWS docs: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/US_AlarmAtThresholdEC2.html
As 6 answered already, use an ELB to monitor 5 HTTP.
This is the list of available metrics 4 for ELB: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/US_MonitoringLoadBalancerWithCW.html#available_metrics
To answer your specific question, for 3 monitoring X seconds for the http response, you 2 would set up an alarm to monitor the ELB 1 "Latency".
CloudWatch monitoring is just like you have 30 discovered. You will be able to infer that 29 one of your instances is frozen by taking 28 a look at the metrics, but CloudWatch won't 27 e.g. send you an email when your app is 26 down or too slow, for example.
If you are 25 looking for some sort of notification when 24 your app or instance is down, I suggest 23 you to use a monitoring service. Pingdom is a good 22 option. You can also set up a new instance 21 on AWS and install a monitoring tool, like 20 Nagios, which would be my preferred option.
Good 19 practices that are always worth, in the 18 long road: using load balancing (Amazon ELB), more 17 than one instance running your app, Autoscaling 16 (when an instance is down, Amazon will automatically 15 start a new one and maintain your SLA), and 14 custom monitoring.
My team has used a custom 13 monitoring script for a long time, and we 12 always knew of failures as soon as they 11 occurred. Basically, if we had two nodes 10 running our app, node 1 sent HTTP requests 9 to node 2 and node 2 to 1. If any request 8 took more than expected, or returned an 7 unexpected HTTP status or response body, the 6 script sent an email to the system admins. Nowadays, we 5 rely on more robust approaches, like Nagios, which 4 can even monitor operating system stuff 3 (threads, etc), application servers (connection 2 pools health, etc) and so on. It's worth 1 every cent invested in setting it up.
CloudWatch recently added "status check" metrics 5 that will answer one of your questions on 4 whether an instance is down or not. It will 3 not do a request to your Web server but 2 rather a system check. As previous answer 1 suggest, use ELB for HTTP health checks.
You could always have another instance for 6 tools/testing, that instance would try the 5 http request based on a schedule and measure 4 the response time, then you could publish 3 that response time with CloudWatch and set 2 an alarm when it goes over a certain threshold.
You 1 could even do that from the instance itself.
As Kurst Ursan mentioned above, using "Status 12 Check" metrics is the way to go. In some 11 cases you won't be able to browse that metrics 10 (i.e if you;re using AWS OpsWorks), so you're 9 going to have to report that custom metric 8 on your own. However, you can set up an 7 alarm built on a metric that always matches 6 (in an OK sate) and have the alarm trigger 5 when the state changes to "INSUFFICIENT 4 DATA" state, this technically means CloudWatch 3 can't tell whether the state is OK or ALARM 2 because it can't reach your instance, AKA 1 your instance is offline.
There are a bunch of ways to get instance 20 health info. Here are a couple.
Watch for 19 instance status checks and EC2 events (planned 18 downtime) in the EC2 API. You can poll those 17 and send to Cloudwatch to create an alarm.
Create 16 a simple daemon on the server which writes 15 to DynamoDB every second (has better granularity 14 than Cloudwatch). Have a second process 13 query the heartbeats and alert when missing.
Put 12 all instances in a load balancer with a 11 dummy port open that that gives a TCP response. Setup 10 TCP health checks on the ELB, and alert 9 on unhealthy instances.
Unless you use a 8 product like Blue Matador (automatically 7 notifies you of production issues), it's 6 actually quite heinous to set something 5 like this up - let alone maintain it. That 4 said, if you're going down the road, and 3 want some help getting started using Cloudwatch 2 (terminology, alerts, logs, etc), start 1 with this blog: How to Monitor Amazon EC2 with CloudWatch
You can use CloudWatch Event Rule to Monitor 12 whenever any EC2 instance goes down. You 11 can create an Event rule from CloudWatch 10 console as following :
In the CLoudWatch 9 Console choose Events -> rule
For Event 8 Pattern, In service Name Choose EC2 For 7 Event Type, Choose EC2 Instance State-change 6 Notification For Specific States, Choose 5 Stopped
In targets Choose any previously 4 created SNS topic for sending a notification!
This is not exactly a 2 CloudWatch alarm, however this serves the 1 purpose of monitoring/notification.
More Related questions