简体   繁体   English

通过php以编程方式获取AWS Elastic Beanstalk运行状况代码

[英]Getting AWS Elastic Beanstalk health code programatically via php

I have an AWS Elastic Beanstalk instance on which I have some crons running. 我有一个AWS Elastic Beanstalk实例,我在其上运行了一些crons。 I occasionally have issues 我偶尔会有问题

Environment health has transitioned from Ok to Severe. 4.5 % of the requests to the ELB are failing with HTTP 5xx (2 minutes ago)

I have alarms set to let me know about this, and that part is working correctly. 我有警报设置让我知道这一点,那部分工作正常。 But I want to stop the crons from executing if the environment health status is not "OK" or "Warning". 但是如果环境健康状态不是“OK”或“Warning”,我想阻止crons执行。 Is there a way to programatically get the health status code (shown in image below, circled in red) from a php script running on the same instance? 有没有办法以编程方式从同一实例上运行的php脚本获取健康状态代码(如下图所示,红色圈出)?

AWS Elastic Beanstalk运行状况代码

I would use CloudWatch alarm to trigger sending a notification email in such event. 在这种情况下,我会使用CloudWatch警报触发发送通知电子邮件。

The first thing to understand is that Elastic Beanstalk to a convenient tool to bootstrap the infrastructure on AWS. 首先要了解的是Elastic Beanstalk是一个方便的工具,用于在AWS上引导基础架构。 Anything you setup with Elastic Beanstalk, either via its cli or console, you can pretty much do the same on the EC2 page. 使用Elastic Beanstalk设置的任何东西,无论是通过它的cli还是控制台,你都可以在EC2页面上做同样的事情。

  1. On AWS console, go to EC2 在AWS控制台上,转至EC2
  2. Go to Load Balancing/Target Groups 转到负载平衡/目标组
  3. Find the right Target Group that is attached to the Load Balancer created by Elastic Beanstalk 找到附加到Elastic Beanstalk创建的Load Balancer的正确目标组
  4. Check the "Monitoring" tab, you should see "CloudWatch alarms: no alarm configured" 选中“监控”选项卡,您会看到“CloudWatch警报:未配置警报”
  5. Click "Create Alarm" and finish off the rest, you may need to create a topic, set email address, and define the alarm triggering criteria. 单击“创建警报”并完成其余操作,您可能需要创建主题,设置电子邮件地址并定义警报触发条件。

Assuming you have a health script within your application that beanstalk pings periodically, you should be able to determine if your app is healthy or not within your application. 假设您的应用程序中有一个health脚本定期查找bean,您应该能够确定您的应用程序在您的应用程序中是否健康。 You should not rely on having to programically get the status from Benstalk. 您不应该依赖于以编程方式从Benstalk获取状态。

For example, within your health script you can set a flag if your application is healthy or not. 例如,如果您的应用程序运行正常,您可以在health脚本中设置标志。 Such flag can be in the form of a touched file in the filesystem. 这种标志可以是文件系统中被触摸的文件的形式。 Or a flag somewhere in a cache if you use one. 或者如果您使用缓存,则在缓存中的某个位置标记。 Ex: Memcache. 例如:Memcache。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM