问题原文
原帖链接 · Neal · CC BY-SA 4.0
Say nginx on an EC2 instance crashes. The instance is healthy and CloudWatch Metrics are great, but all the domains hosted on the server are now "Connection refused".
This seems like a very basic function - monitoring to ensure a website is returning a 200. Is this somewhere in CloudWatch? I would think something could just curl -s -o /dev/null -w "%{http_code}" http://www.example.org/ and if it doesn't receive a return code of 200, say 5 times in a row, it will trigger an instance restart and SNS notification.
Perhaps there is something I should be running on the EC2 instance that would restart nginx if something is unreachable? Either way, I'd love to know how to do this with an AWS resource, so I could even monitor any site and kick off an SNS.
Sorry if I'm missing something easy here. It just seems this would something easily searched, but I have spent hours across months trying to figure this out.
已采纳解答
原帖链接 · MLu · CC BY-SA 4.0
This is typically the job for a load balancer (ALB or ELB) that can detect whether the web server on the instance is running or not and if not you can trigger some action through CloudWatch. Again, typically, an instance replacement through Auto Scaling Group.
It’s perfectly normal to use ASG and ALB even if you need only a single instance.
Alternatively you can create Custom CloudWatch metrics using the CW agent installed on the instance. Then you can report anything you want.
Hope that helps :)
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
