本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用 EB CLI 监控环境的运行状况
Elastic Beanstalk 命令行界面 (EB CLI) 是用于管理 AWS Elastic Beanstalk 环境的命令行工具。您也可以使用 EB CLI 实时监控您的环境的运行状况,这比当前在 Elastic Beanstalk 控制台中提供的监控效果更精细。
在安装并配置 EB CLI 后,您可以使用 eb create 命令启动新环境并将您的代码部署到该环境。如果您已具有在 Elastic Beanstalk 控制台中创建的环境,则可以在项目文件夹中运行 eb init 并按提示操作来将 EB CLI 附加到该环境(项目文件夹可能是空的)。
重要
通过运行带 pip
install
选项的 --upgrade
来确保您使用的是 EB CLI 的最新版本:
$ sudo pip install --upgrade awsebcli
有关完整的 EB CLI 安装说明,请参阅安装 Elastic Beanstalk 命令行界面。
要使用 EB CLI 监控您的环境的运行状况,您必须首先通过运行 eb init 并按照提示操作来配置本地项目文件夹。有关完整说明,请参阅配置 EB CLI。
如果您已有一个在 Elastic Beanstalk 中运行的环境并且想使用 EB CLI 监控其运行状况,请执行这些步骤以将其附加到现有环境。
将 EB CLI 附加到现有环境
-
打开命令行终端并导航至您的用户文件夹。
-
为您的环境创建一个新的文件夹并打开该文件夹。
-
运行 eb init 命令,然后选择要监控其运行状况的应用程序和环境。如果您只有一个运行您选择的应用程序的环境,EB CLI 将自动选择它,您无需选择环境,如以下示例所示。
~/project$
eb init
Select an application to use 1) elastic-beanstalk-example 2) [ Create new Application ] (default is 2):1
Select the default environment. You can change this later by typing "eb use [environment_name]". 1) elasticBeanstalkEx2-env 2) elasticBeanstalkExa-env (default is 1):1
使用 EB CLI 监控运行状况
-
打开命令行并导航到项目文件夹。
-
运行 eb health 命令以显示您的环境中的实例的运行状况。在此示例中,有五个实例在 Linux 环境中运行。
~/project $
eb health
elasticBeanstalkExa-env Ok 2015-07-08 23:13:20 WebServer Ruby 2.1 (Puma) total ok warning degraded severe info pending unknown 5 5 0 0 0 0 0 0 instance-id status cause health Overall Ok i-d581497d Ok i-d481497c Ok i-136e00c0 Ok i-126e00c1 Ok i-8b2cf575 Ok instance-id r/sec %2xx %3xx %4xx %5xx p99 p90 p75 p50 p10 requests Overall 671.8 100.0 0.0 0.0 0.0 0.003 0.002 0.001 0.001 0.000 i-d581497d 143.0 1430 0 0 0 0.003 0.002 0.001 0.001 0.000 i-d481497c 128.8 1288 0 0 0 0.003 0.002 0.001 0.001 0.000 i-136e00c0 125.4 1254 0 0 0 0.004 0.002 0.001 0.001 0.000 i-126e00c1 133.4 1334 0 0 0 0.003 0.002 0.001 0.001 0.000 i-8b2cf575 141.2 1412 0 0 0 0.003 0.002 0.001 0.001 0.000 instance-id type az running load 1 load 5 user% nice% system% idle% iowait% cpu i-d581497d t2.micro 1a 12 mins 0.0 0.04 6.2 0.0 1.0 92.5 0.1 i-d481497c t2.micro 1a 12 mins 0.01 0.09 5.9 0.0 1.6 92.4 0.1 i-136e00c0 t2.micro 1b 12 mins 0.15 0.07 5.5 0.0 0.9 93.2 0.0 i-126e00c1 t2.micro 1b 12 mins 0.17 0.14 5.7 0.0 1.4 92.7 0.1 i-8b2cf575 t2.micro 1c 1 hour 0.19 0.08 6.5 0.0 1.2 92.1 0.1 instance-id status id version ago deployments i-d581497d Deployed 1 Sample Application 12 mins i-d481497c Deployed 1 Sample Application 12 mins i-136e00c0 Deployed 1 Sample Application 12 mins i-126e00c1 Deployed 1 Sample Application 12 mins i-8b2cf575 Deployed 1 Sample Application 1 hour在此示例中,有一个实例在 Windows 环境中运行。
~/project $
eb health
WindowsSampleApp-env Ok 2018-05-22 17:33:19 WebServer IIS 10.0 running on 64bit Windows Server 2016/2.2.0 total ok warning degraded severe info pending unknown 1 1 0 0 0 0 0 0 instance-id status cause health Overall Ok i-065716fba0e08a351 Ok instance-id r/sec %2xx %3xx %4xx %5xx p99 p90 p75 p50 p10 requests Overall 13.7 100.0 0.0 0.0 0.0 1.403 0.970 0.710 0.413 0.079 i-065716fba0e08a351 2.4 100.0 0.0 0.0 0.0 1.102* 0.865 0.601 0.413 0.091 instance-id type az running % user time % privileged time % idle time cpu i-065716fba0e08a351 t2.large 1b 4 hours 0.2 0.1 99.7 instance-id status id version ago deployments i-065716fba0e08a351 Deployed 2 Sample Application 4 hours
读取输出
输出将在屏幕顶部显示环境的名称、环境的总体运行状况和当前日期。
elasticBeanstalkExa-env Ok 2015-07-08 23:13:20
接下来三行将显示环境类型(本例中为“WebServer”)、配置 (Ruby 2.1 with Puma) 以及每种状态(共七种状态)的实例数量的明细。
WebServer Ruby 2.1 (Puma)
total ok warning degraded severe info pending unknown
5 5 0 0 0 0 0 0
输出的其余部分分为四个部分。第一个部分依次显示了环境总体和每个实例的状态 和状态原因。以下示例显示了环境中两个状态为 Info
的实例以及一个表示部署已开始的原因。
instance-id status cause health
Overall Ok
i-d581497d Info Performing application deployment (running for 3 seconds)
i-d481497c Info Performing application deployment (running for 3 seconds)
i-136e00c0 Ok
i-126e00c1 Ok
i-8b2cf575 Ok
有关运行状况的状态和颜色的信息,请参阅运行状况颜色和状态。
requests 部分显示了 Web 服务器日志中有关每个实例的信息。在此示例中,每个实例正常接收请求且没有错误。
instance-id r/sec %2xx %3xx %4xx %5xx p99 p90 p75 p50 p10 requests
Overall 13.7 100.0 0.0 0.0 0.0 1.403 0.970 0.710 0.413 0.079
i-d581497d 2.4 100.0 0.0 0.0 0.0 1.102* 0.865 0.601 0.413 0.091
i-d481497c 2.7 100.0 0.0 0.0 0.0 0.842* 0.788 0.480 0.305 0.062
i-136e00c0 4.1 100.0 0.0 0.0 0.0 1.520* 1.088 0.883 0.524 0.104
i-126e00c1 2.2 100.0 0.0 0.0 0.0 1.334* 0.791 0.760 0.344 0.197
i-8b2cf575 2.3 100.0 0.0 0.0 0.0 1.162* 0.867 0.698 0.477 0.076
cpu 部分显示了每个实例的操作系统指标。输出因操作系统而异。以下是 Linux 环境的输出。
instance-id type az running load 1 load 5 user% nice% system% idle% iowait% cpu
i-d581497d t2.micro 1a 12 mins 0.0 0.03 0.2 0.0 0.0 99.7 0.1
i-d481497c t2.micro 1a 12 mins 0.0 0.03 0.3 0.0 0.0 99.7 0.0
i-136e00c0 t2.micro 1b 12 mins 0.0 0.04 0.1 0.0 0.0 99.9 0.0
i-126e00c1 t2.micro 1b 12 mins 0.01 0.04 0.2 0.0 0.0 99.7 0.1
i-8b2cf575 t2.micro 1c 1 hour 0.0 0.01 0.2 0.0 0.1 99.6 0.1
以下是 Windows 环境的输出。
instance-id type az running % user time % privileged time % idle time
i-065716fba0e08a351 t2.large 1b 4 hours 0.2 0.0 99.8
有关显示的服务器和操作系统指标的信息,请参阅实例指标。
最后的 deployments 部分显示了每个实例的部署状态。如果滚动部署失败,您可以使用显示的部署 ID、状态和版本标签来确定环境中正在运行错误版本的实例。
instance-id status id version ago deployments
i-d581497d Deployed 1 Sample Application 12 mins
i-d481497c Deployed 1 Sample Application 12 mins
i-136e00c0 Deployed 1 Sample Application 12 mins
i-126e00c1 Deployed 1 Sample Application 12 mins
i-8b2cf575 Deployed 1 Sample Application 1 hour
交互式运行状况视图
eb health 命令将显示环境运行状况的快照。要每 10 秒将显示的信息刷新一次,请使用 --refresh
选项。
$ eb health --refresh
elasticBeanstalkExa-env Ok 2015-07-09 22:10:04 (1 secs)
WebServer Ruby 2.1 (Puma)
total ok warning degraded severe info pending unknown
5 5 0 0 0 0 0 0
instance-id status cause health
Overall Ok
i-bb65c145 Ok Application deployment completed 35 seconds ago and took 26 seconds
i-ba65c144 Ok Application deployment completed 17 seconds ago and took 25 seconds
i-f6a2d525 Ok Application deployment completed 53 seconds ago and took 26 seconds
i-e8a2d53b Ok Application deployment completed 32 seconds ago and took 31 seconds
i-e81cca40 Ok
instance-id r/sec %2xx %3xx %4xx %5xx p99 p90 p75 p50 p10 requests
Overall 671.8 100.0 0.0 0.0 0.0 0.003 0.002 0.001 0.001 0.000
i-bb65c145 143.0 1430 0 0 0 0.003 0.002 0.001 0.001 0.000
i-ba65c144 128.8 1288 0 0 0 0.003 0.002 0.001 0.001 0.000
i-f6a2d525 125.4 1254 0 0 0 0.004 0.002 0.001 0.001 0.000
i-e8a2d53b 133.4 1334 0 0 0 0.003 0.002 0.001 0.001 0.000
i-e81cca40 141.2 1412 0 0 0 0.003 0.002 0.001 0.001 0.000
instance-id type az running load 1 load 5 user% nice% system% idle% iowait% cpu
i-bb65c145 t2.micro 1a 12 mins 0.0 0.03 0.2 0.0 0.0 99.7 0.1
i-ba65c144 t2.micro 1a 12 mins 0.0 0.03 0.3 0.0 0.0 99.7 0.0
i-f6a2d525 t2.micro 1b 12 mins 0.0 0.04 0.1 0.0 0.0 99.9 0.0
i-e8a2d53b t2.micro 1b 12 mins 0.01 0.04 0.2 0.0 0.0 99.7 0.1
i-e81cca40 t2.micro 1c 1 hour 0.0 0.01 0.2 0.0 0.1 99.6 0.1
instance-id status id version ago deployments
i-bb65c145 Deployed 1 Sample Application 12 mins
i-ba65c144 Deployed 1 Sample Application 12 mins
i-f6a2d525 Deployed 1 Sample Application 12 mins
i-e8a2d53b Deployed 1 Sample Application 12 mins
i-e81cca40 Deployed 1 Sample Application 1 hour
(Commands: Help,Quit, ▼ ▲ ◄ ►)
此示例显示了一个最近从一个实例扩展到五个实例的环境。扩展操作成功完成,现在,所有实例正在通过运行状况检查并已准备好接收请求。在交互式模式中,运行状况的状态每 10 秒更新一次。在右上角,计时器为下一次更新进行倒计时。
在左下角,报告显示了一个选项列表。要退出交互模式,请按 Q。要滚动,请按箭头键。要查看其他命令的列表,请按 H。
交互运行状况视图选项
在以交互方式查看环境运行状况时,您可以使用键盘键调整视图并告知 Elastic Beanstalk 替换或重新启动各个实例。要在以交互模式查看运行状况报告时查看可用命令的列表,请按 H。
up,down,home,end Scroll vertically
left,right Scroll horizontally
F Freeze/unfreeze data
X Replace instance
B Reboot instance
<,> Move sort column left/right
-,+ Sort order descending/ascending
P Save health snapshot data file
Z Toggle color/mono mode
Q Quit this program
Views
1 All tables/split view
2 Status Table
3 Request Summary Table
4 CPU%/Load Table
H This help menu
(press Q or ESC to return)