任务元数据终端节点版本 4 - Amazon Elastic Container Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

任务元数据终端节点版本 4

重要

如果您使用的是托管在 Amazon Fargate 上的 Amazon ECS 任务,请参阅用于 Amazon Fargate 的 Amazon Elastic Container Service 用户指南中的任务元数据端点版本 4

Amazon ECS 容器代理会向每个容器注入一个环境变量,称为任务元数据端点,它提供了各种任务元数据和 Docker 统计信息添加到容器中。

任务元数据和联网速率统计数据将发送到 CloudWatch 容器洞察,并可在 Amazon Web Services Management Console 中查看。有关更多信息,请参阅Amazon ECS CloudWatch Container Insights

注意

Amazon ECS 提供较早版本的任务元数据端点。为避免将来需要创建新的任务元数据终端节点版本,可能会将其他元数据添加到版本 4 输出中。我们不会删除任何现有元数据或更改元数据字段名称。

启用任务元数据端点

原定设置情况下,环境变量会注入到运行至少版本的 Amazon EC2 Linux 实例上启动的 Amazon ECS 任务的容器中 1.39.0 的 Amazon ECS 容器代理。对于使用 awsvpc 网络模式的 Amazon EC2 Windows 实例,Amazon ECS 容器代理的版本必须至少为 1.54.0。有关更多信息,请参阅Amazon ECS Linux 容器代理版本

注意

通过将代理更新为最新版本,您可以使用较旧版本的 Amazon ECS 容器代理在 Amazon EC2 实例上添加对此功能的支持。有关更多信息,请参阅更新 Amazon ECS 容器代理

任务元数据端点版本 4 路径

以下任务元数据端点路径可用于容器:

${ECS_CONTAINER_METADATA_URI_V4}

此路径返回容器的元数据。

${ECS_CONTAINER_METADATA_URI_V4}/task

此路径返回任务的元数据,包括与任务相关的所有容器的 ID 和名称列表。有关此终端节点响应的更多信息,请参阅任务元数据 JSON 响应

${ECS_CONTAINER_METADATA_URI_V4}/taskWithTags

除了可以使用 ListTagsForResource API 检索的任务和容器实例标记外,此路径还返回 /task 端点中包含的任务的元数据。检索标记元数据时收到的任何错误都将包含在 Errors 字段中的值。

注意

Errors 字段仅位于运行至少一个版本 1.50.0 的容器代理的 Amazon EC2 Linux 实例上托管的任务的响应中。对于使用 awsvpc 网络模式的 Amazon EC2 Windows 实例,Amazon ECS 容器代理必须至少为版本 1.54.0

${ECS_CONTAINER_METADATA_URI_V4}/stats

此路径返回特定容器的 Docker 统计信息。有关每个返回的统计信息的更多信息,请参阅 Docker API 文档中的 ContainerStats

对于使用 awsvpcbridge 版本托管在运行至少版本 1.43.0 的容器代理的Amazon EC2 Linux 实例上的或网络模式的Amazon ECS任务,响应中将包含其他网络速率统计信息。对于所有其他任务,响应将仅包含累积网络统计信息。

${ECS_CONTAINER_METADATA_URI_V4}/task/stats

此路径返回与任务相关的所有容器的 Docker 统计数据 。附加容器可以使用此路径提取网络指标。有关每个返回的统计信息的更多信息,请参阅 Docker API 文档中的 ContainerStats

对于使用 awsvpcbridge 版本托管在运行至少版本 1.43.0 的容器代理的Amazon EC2 Linux 实例上的或网络模式的Amazon ECS任务,响应中将包含其他网络速率统计信息。对于所有其他任务,响应将仅包含累积网络统计信息。

任务元数据 JSON 响应

以下信息返回自任务元数据终端节点 (${ECS_CONTAINER_METADATA_URI_V4}/task) JSON 响应。除了任务中每个容器的元数据外,还包括与任务关联的元数据。

Cluster

任务所属的 Amazon ECS 群集的 Amazon Resource Name (ARN) 或短名称。

ServiceName

任务所属服务的名称。如果任务与服务相关联,则 Amazon EC2 和 Amazon ECS Anywhere 容器实例将显示 ServiceName。

注意

仅在使用 Amazon ECS 容器代理版本 1.63.1 或更高版本时包含 ServiceName 元数据。

VPCID

Amazon EC2 容器实例的 VPC ID。此字段仅针对 Amazon EC2 实例显示。

注意

仅在使用 Amazon ECS 容器代理版本 1.63.1 或更高版本时包含 VPCID 元数据。

TaskARN

容器所属的任务的完整 Amazon Resource Name (ARN)。

Family

任务的 Amazon ECS 任务定义系列。

Revision

任务的 Amazon ECS 任务定义修订。

DesiredStatus

来自 Amazon ECS 的任务的所需状态。

KnownStatus

来自 Amazon ECS 的任务的已知状态。

Limits

在任务级别上指定的资源限制 (如 CPU 和内存)。如果未定义资源限制,则省略此参数。

PullStartedAt

开始提取第一个容器映像时的时间戳。

PullStoppedAt

完成提取最后一个容器映像时的时间戳。

AvailabilityZone

任务所在的可用区。

注意

可用区元数据仅适用于使用平台版本 1.4 或更高版本(Linux)或者 1.0.0(Windows)的 Fargate 任务。

LaunchType

任务使用的启动类型。使用集群容量提供程序时,这表明任务使用的是 Fargate 还是 EC2 基础设施。

注意

仅在使用 Amazon ECS Linux 容器代理版本 1.45.0 或更高版本(Linux)或者 1.0.0 或更高版本(Windows)时将该 LaunchType 元数据包含在内。

Containers

与任务关联的每个容器的容器元数据列表。

DockerId

容器的 Docker ID。

当您使用 Fargate 时,id 是一个 32 位十六进制,后面是 10 位数字。

Name

任务定义中所指定的容器的名称。

DockerName

提供给 Docker 的容器的名称。Amazon ECS 容器代理为容器生成一个唯一名称,以避免相同任务定义的多个副本在一个实例上运行时发生名称冲突。

Image

容器的映像。

ImageID

容器的 SHA-256 摘要。

Ports

对于容器公开的任何端口。如果没有公开的端口,则省略此参数。

Labels

应用到容器的任何标签。如果没有应用的标签,则省略此参数。

DesiredStatus

来自 Amazon ECS 的容器的所需状态。

KnownStatus

来自 Amazon ECS 的容器的已知状态。

ExitCode

容器的退出代码。如果没有容器退出,则省略此参数。

Limits

在容器级别上指定的资源限制 (如 CPU 和内存)。如果未定义资源限制,则省略此参数。

CreatedAt

创建容器时的时间戳。如果尚未创建容器,则省略此参数。

StartedAt

容器启动时的时间戳。如果尚未启动容器,则省略此参数。

FinishedAt

容器停止时的时间戳。如果尚未停止容器,则省略此参数。

Type

容器的类型。在您的任务定义中指定的容器属于 NORMAL 类型。您可以省略其他被 Amazon ECS 容器代理用来进行内部任务资源预配置的容器类型。

LogDriver

容器使用的日志驱动程序。

注意

LogDriver 元数据仅在使用Amazon ECS Linux 容器代理版本时包含 1.45.0 或更高版本.

LogOptions

为容器定义的日志驱动程序选项。

注意

LogOptions 元数据仅在使用Amazon ECS Linux 容器代理版本时包含 1.45.0 或更高版本.

ContainerARN

容器的完整 Amazon Resource Name (ARN)。

注意

ContainerARN 元数据仅在使用Amazon ECS Linux 容器代理版本时包含 1.45.0 或更高版本.

Networks

容器的网络信息,如网络模式和 IP 地址。如果未定义网络信息,则省略此参数。

ExecutionStoppedAt

任务的 DesiredStatus 变为 STOPPED 时的时间戳。这将发生在关键容器变成 STOPPED 时。

示例

以下示例显示了每个任务元数据端点的输出示例。

容器元数据响应示例

查询 ${ECS_CONTAINER_METADATA_URI_V4} 终端节点时,仅返回有关容器本身的元数据。下面是一个示例输出。

{ "DockerId": "ea32192c8553fbff06c9340478a2ff089b2bb5646fb718b4ee206641c9086d66", "Name": "curl", "DockerName": "ecs-curltest-24-curl-cca48e8dcadd97805600", "Image": "111122223333.dkr.ecr.us-west-2.amazonaws.com/curltest:latest", "ImageID": "sha256:d691691e9652791a60114e67b365688d20d19940dde7c4736ea30e660d8d3553", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "curl", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/8f03e41243824aea923aca126495f665", "com.amazonaws.ecs.task-definition-family": "curltest", "com.amazonaws.ecs.task-definition-version": "24" }, "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "Limits": { "CPU": 10, "Memory": 128 }, "CreatedAt": "2020-10-02T00:15:07.620912337Z", "StartedAt": "2020-10-02T00:15:08.062559351Z", "Type": "NORMAL", "LogDriver": "awslogs", "LogOptions": { "awslogs-create-group": "true", "awslogs-group": "/ecs/metadata", "awslogs-region": "us-west-2", "awslogs-stream": "ecs/curl/8f03e41243824aea923aca126495f665" }, "ContainerARN": "arn:aws:ecs:us-west-2:111122223333:container/0206b271-b33f-47ab-86c6-a0ba208a70a9", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.100" ], "AttachmentIndex": 0, "MACAddress": "0e:9e:32:c7:48:85", "IPv4SubnetCIDRBlock": "10.0.2.0/24", "PrivateDNSName": "ip-10-0-2-100.us-west-2.compute.internal", "SubnetGatewayIpv4Address": "10.0.2.1/24" } ] }

任务元数据响应示例

查询 ${ECS_CONTAINER_METADATA_URI_V4}/task 端点时,除了任务中每个容器的元数据外,还会返回有关该容器的任务元数据。下面是一个示例输出。

{ "Cluster": "default", "TaskARN": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "Family": "curltest", "ServiceName": "MyService", "Revision": "26", "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "PullStartedAt": "2020-10-02T00:43:06.202617438Z", "PullStoppedAt": "2020-10-02T00:43:06.31288465Z", "AvailabilityZone": "us-west-2d", "VPCID": "vpc-1234567890abcdef0", "LaunchType": "EC2", "Containers": [ { "DockerId": "598cba581fe3f939459eaba1e071d5c93bb2c49b7d1ba7db6bb19deeb70d8e38", "Name": "~internal~ecs~pause", "DockerName": "ecs-curltest-26-internalecspause-e292d586b6f9dade4a00", "Image": "amazon/amazon-ecs-pause:0.1.0", "ImageID": "", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "~internal~ecs~pause", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "com.amazonaws.ecs.task-definition-family": "curltest", "com.amazonaws.ecs.task-definition-version": "26" }, "DesiredStatus": "RESOURCES_PROVISIONED", "KnownStatus": "RESOURCES_PROVISIONED", "Limits": { "CPU": 0, "Memory": 0 }, "CreatedAt": "2020-10-02T00:43:05.602352471Z", "StartedAt": "2020-10-02T00:43:06.076707576Z", "Type": "CNI_PAUSE", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.61" ], "AttachmentIndex": 0, "MACAddress": "0e:10:e2:01:bd:91", "IPv4SubnetCIDRBlock": "10.0.2.0/24", "PrivateDNSName": "ip-10-0-2-61.us-west-2.compute.internal", "SubnetGatewayIpv4Address": "10.0.2.1/24" } ] }, { "DockerId": "ee08638adaaf009d78c248913f629e38299471d45fe7dc944d1039077e3424ca", "Name": "curl", "DockerName": "ecs-curltest-26-curl-a0e7dba5aca6d8cb2e00", "Image": "111122223333.dkr.ecr.us-west-2.amazonaws.com/curltest:latest", "ImageID": "sha256:d691691e9652791a60114e67b365688d20d19940dde7c4736ea30e660d8d3553", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "curl", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "com.amazonaws.ecs.task-definition-family": "curltest", "com.amazonaws.ecs.task-definition-version": "26" }, "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "Limits": { "CPU": 10, "Memory": 128 }, "CreatedAt": "2020-10-02T00:43:06.326590752Z", "StartedAt": "2020-10-02T00:43:06.767535449Z", "Type": "NORMAL", "LogDriver": "awslogs", "LogOptions": { "awslogs-create-group": "true", "awslogs-group": "/ecs/metadata", "awslogs-region": "us-west-2", "awslogs-stream": "ecs/curl/158d1c8083dd49d6b527399fd6414f5c" }, "ContainerARN": "arn:aws:ecs:us-west-2:111122223333:container/abb51bdd-11b4-467f-8f6c-adcfe1fe059d", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.61" ], "AttachmentIndex": 0, "MACAddress": "0e:10:e2:01:bd:91", "IPv4SubnetCIDRBlock": "10.0.2.0/24", "PrivateDNSName": "ip-10-0-2-61.us-west-2.compute.internal", "SubnetGatewayIpv4Address": "10.0.2.1/24" } ] } ] }

带标签元数据响应的示例任务

查询 ${ECS_CONTAINER_METADATA_URI_V4}/taskWithTags 端点时,将返回有关任务的元数据,包括任务和容器实例标记。下面是一个示例输出。

{ "Cluster": "default", "TaskARN": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "Family": "curltest", "ServiceName": "MyService", "Revision": "26", "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "PullStartedAt": "2020-10-02T00:43:06.202617438Z", "PullStoppedAt": "2020-10-02T00:43:06.31288465Z", "AvailabilityZone": "us-west-2d", "VPCID": "vpc-1234567890abcdef0", "TaskTags": { "tag-use": "task-metadata-endpoint-test" }, "ContainerInstanceTags":{ "tag_key":"tag_value" }, "LaunchType": "EC2", "Containers": [ { "DockerId": "598cba581fe3f939459eaba1e071d5c93bb2c49b7d1ba7db6bb19deeb70d8e38", "Name": "~internal~ecs~pause", "DockerName": "ecs-curltest-26-internalecspause-e292d586b6f9dade4a00", "Image": "amazon/amazon-ecs-pause:0.1.0", "ImageID": "", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "~internal~ecs~pause", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "com.amazonaws.ecs.task-definition-family": "curltest", "com.amazonaws.ecs.task-definition-version": "26" }, "DesiredStatus": "RESOURCES_PROVISIONED", "KnownStatus": "RESOURCES_PROVISIONED", "Limits": { "CPU": 0, "Memory": 0 }, "CreatedAt": "2020-10-02T00:43:05.602352471Z", "StartedAt": "2020-10-02T00:43:06.076707576Z", "Type": "CNI_PAUSE", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.61" ], "AttachmentIndex": 0, "MACAddress": "0e:10:e2:01:bd:91", "IPv4SubnetCIDRBlock": "10.0.2.0/24", "PrivateDNSName": "ip-10-0-2-61.us-west-2.compute.internal", "SubnetGatewayIpv4Address": "10.0.2.1/24" } ] }, { "DockerId": "ee08638adaaf009d78c248913f629e38299471d45fe7dc944d1039077e3424ca", "Name": "curl", "DockerName": "ecs-curltest-26-curl-a0e7dba5aca6d8cb2e00", "Image": "111122223333.dkr.ecr.us-west-2.amazonaws.com/curltest:latest", "ImageID": "sha256:d691691e9652791a60114e67b365688d20d19940dde7c4736ea30e660d8d3553", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "curl", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "com.amazonaws.ecs.task-definition-family": "curltest", "com.amazonaws.ecs.task-definition-version": "26" }, "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "Limits": { "CPU": 10, "Memory": 128 }, "CreatedAt": "2020-10-02T00:43:06.326590752Z", "StartedAt": "2020-10-02T00:43:06.767535449Z", "Type": "NORMAL", "LogDriver": "awslogs", "LogOptions": { "awslogs-create-group": "true", "awslogs-group": "/ecs/metadata", "awslogs-region": "us-west-2", "awslogs-stream": "ecs/curl/158d1c8083dd49d6b527399fd6414f5c" }, "ContainerARN": "arn:aws:ecs:us-west-2:111122223333:container/abb51bdd-11b4-467f-8f6c-adcfe1fe059d", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.61" ], "AttachmentIndex": 0, "MACAddress": "0e:10:e2:01:bd:91", "IPv4SubnetCIDRBlock": "10.0.2.0/24", "PrivateDNSName": "ip-10-0-2-61.us-west-2.compute.internal", "SubnetGatewayIpv4Address": "10.0.2.1/24" } ] } ] }

带有错误元数据响应标签的示例任务

查询 ${ECS_CONTAINER_METADATA_URI_V4}/taskWithTags 端点时,将返回有关任务的元数据,包括任务和容器实例标记。如果检索标记数据时出错,则响应中返回错误。以下是与容器实例关联的IAM角色没有允许的 ecs:ListTagsForResource 权限时的输出示例。

{ "Cluster": "default", "TaskARN": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "Family": "curltest", "ServiceName": "MyService", "Revision": "26", "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "PullStartedAt": "2020-10-02T00:43:06.202617438Z", "PullStoppedAt": "2020-10-02T00:43:06.31288465Z", "AvailabilityZone": "us-west-2d", "VPCID": "vpc-1234567890abcdef0", "Errors": [ { "ErrorField": "ContainerInstanceTags", "ErrorCode": "AccessDeniedException", "ErrorMessage": "User: arn:aws:sts::111122223333:assumed-role/ecsInstanceRole/i-0744a608689EXAMPLE is not authorized to perform: ecs:ListTagsForResource on resource: arn:aws:ecs:us-west-2:111122223333:container-instance/default/2dd1b186f39845a584488d2ef155c131", "StatusCode": 400, "RequestId": "cd597ef0-272b-4643-9bd2-1de469870fa6", "ResourceARN": "arn:aws:ecs:us-west-2:111122223333:container-instance/default/2dd1b186f39845a584488d2ef155c131" }, { "ErrorField": "TaskTags", "ErrorCode": "AccessDeniedException", "ErrorMessage": "User: arn:aws:sts::111122223333:assumed-role/ecsInstanceRole/i-0744a608689EXAMPLE is not authorized to perform: ecs:ListTagsForResource on resource: arn:aws:ecs:us-west-2:111122223333:task/default/9ef30e4b7aa44d0db562749cff4983f3", "StatusCode": 400, "RequestId": "862c5986-6cd2-4aa6-87cc-70be395531e1", "ResourceARN": "arn:aws:ecs:us-west-2:111122223333:task/default/9ef30e4b7aa44d0db562749cff4983f3" } ], "LaunchType": "EC2", "Containers": [ { "DockerId": "598cba581fe3f939459eaba1e071d5c93bb2c49b7d1ba7db6bb19deeb70d8e38", "Name": "~internal~ecs~pause", "DockerName": "ecs-curltest-26-internalecspause-e292d586b6f9dade4a00", "Image": "amazon/amazon-ecs-pause:0.1.0", "ImageID": "", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "~internal~ecs~pause", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "com.amazonaws.ecs.task-definition-family": "curltest", "com.amazonaws.ecs.task-definition-version": "26" }, "DesiredStatus": "RESOURCES_PROVISIONED", "KnownStatus": "RESOURCES_PROVISIONED", "Limits": { "CPU": 0, "Memory": 0 }, "CreatedAt": "2020-10-02T00:43:05.602352471Z", "StartedAt": "2020-10-02T00:43:06.076707576Z", "Type": "CNI_PAUSE", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.61" ], "AttachmentIndex": 0, "MACAddress": "0e:10:e2:01:bd:91", "IPv4SubnetCIDRBlock": "10.0.2.0/24", "PrivateDNSName": "ip-10-0-2-61.us-west-2.compute.internal", "SubnetGatewayIpv4Address": "10.0.2.1/24" } ] }, { "DockerId": "ee08638adaaf009d78c248913f629e38299471d45fe7dc944d1039077e3424ca", "Name": "curl", "DockerName": "ecs-curltest-26-curl-a0e7dba5aca6d8cb2e00", "Image": "111122223333.dkr.ecr.us-west-2.amazonaws.com/curltest:latest", "ImageID": "sha256:d691691e9652791a60114e67b365688d20d19940dde7c4736ea30e660d8d3553", "Labels": { "com.amazonaws.ecs.cluster": "default", "com.amazonaws.ecs.container-name": "curl", "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/158d1c8083dd49d6b527399fd6414f5c", "com.amazonaws.ecs.task-definition-family": "curltest", "com.amazonaws.ecs.task-definition-version": "26" }, "DesiredStatus": "RUNNING", "KnownStatus": "RUNNING", "Limits": { "CPU": 10, "Memory": 128 }, "CreatedAt": "2020-10-02T00:43:06.326590752Z", "StartedAt": "2020-10-02T00:43:06.767535449Z", "Type": "NORMAL", "LogDriver": "awslogs", "LogOptions": { "awslogs-create-group": "true", "awslogs-group": "/ecs/metadata", "awslogs-region": "us-west-2", "awslogs-stream": "ecs/curl/158d1c8083dd49d6b527399fd6414f5c" }, "ContainerARN": "arn:aws:ecs:us-west-2:111122223333:container/abb51bdd-11b4-467f-8f6c-adcfe1fe059d", "Networks": [ { "NetworkMode": "awsvpc", "IPv4Addresses": [ "10.0.2.61" ], "AttachmentIndex": 0, "MACAddress": "0e:10:e2:01:bd:91", "IPv4SubnetCIDRBlock": "10.0.2.0/24", "PrivateDNSName": "ip-10-0-2-61.us-west-2.compute.internal", "SubnetGatewayIpv4Address": "10.0.2.1/24" } ] } ] }

容器统计响应示例

查询 ${ECS_CONTAINER_METADATA_URI_V4}/stats 端点时,将返回容器的网络指标。对于使用 awsvpcbridge 版本托管在运行至少版本 1.43.0 的容器代理的Amazon EC2实例上的或网络模式的Amazon ECS任务,响应中将包含其他网络速率统计信息。对于所有其他任务,响应将仅包含累积网络统计信息。

以下是 Amazon EC2 上使用 bridge 网络模式的 Amazon ECS 任务的输出示例。

{ "read": "2020-10-02T00:51:13.410254284Z", "preread": "2020-10-02T00:51:12.406202398Z", "pids_stats": { "current": 3 }, "blkio_stats": { "io_service_bytes_recursive": [ ], "io_serviced_recursive": [ ], "io_queue_recursive": [ ], "io_service_time_recursive": [ ], "io_wait_time_recursive": [ ], "io_merged_recursive": [ ], "io_time_recursive": [ ], "sectors_recursive": [ ] }, "num_procs": 0, "storage_stats": { }, "cpu_stats": { "cpu_usage": { "total_usage": 360968065, "percpu_usage": [ 182359190, 178608875 ], "usage_in_kernelmode": 40000000, "usage_in_usermode": 290000000 }, "system_cpu_usage": 13939680000000, "online_cpus": 2, "throttling_data": { "periods": 0, "throttled_periods": 0, "throttled_time": 0 } }, "precpu_stats": { "cpu_usage": { "total_usage": 360968065, "percpu_usage": [ 182359190, 178608875 ], "usage_in_kernelmode": 40000000, "usage_in_usermode": 290000000 }, "system_cpu_usage": 13937670000000, "online_cpus": 2, "throttling_data": { "periods": 0, "throttled_periods": 0, "throttled_time": 0 } }, "memory_stats": { "usage": 1806336, "max_usage": 6299648, "stats": { "active_anon": 606208, "active_file": 0, "cache": 0, "dirty": 0, "hierarchical_memory_limit": 134217728, "hierarchical_memsw_limit": 268435456, "inactive_anon": 0, "inactive_file": 0, "mapped_file": 0, "pgfault": 4185, "pgmajfault": 0, "pgpgin": 2926, "pgpgout": 2778, "rss": 606208, "rss_huge": 0, "total_active_anon": 606208, "total_active_file": 0, "total_cache": 0, "total_dirty": 0, "total_inactive_anon": 0, "total_inactive_file": 0, "total_mapped_file": 0, "total_pgfault": 4185, "total_pgmajfault": 0, "total_pgpgin": 2926, "total_pgpgout": 2778, "total_rss": 606208, "total_rss_huge": 0, "total_unevictable": 0, "total_writeback": 0, "unevictable": 0, "writeback": 0 }, "limit": 134217728 }, "name": "/ecs-curltest-26-curl-c2e5f6e0cf91b0bead01", "id": "5fc21e5b015f899d22618f8aede80b6d70d71b2a75465ea49d9462c8f3d2d3af", "networks": { "eth0": { "rx_bytes": 84, "rx_packets": 2, "rx_errors": 0, "rx_dropped": 0, "tx_bytes": 84, "tx_packets": 2, "tx_errors": 0, "tx_dropped": 0 } }, "network_rate_stats": { "rx_bytes_per_sec": 0, "tx_bytes_per_sec": 0 } }

示例任务统计信息响应

查询 ${ECS_CONTAINER_METADATA_URI_V4}/task/stats 终端节点时,将返回有关容器所属的任务的网络指标。下面是一个示例输出。

{ "01999f2e5c6cf4df3873f28950e6278813408f281c54778efec860d0caad4854": { "read": "2020-10-02T00:51:32.51467703Z", "preread": "2020-10-02T00:51:31.50860463Z", "pids_stats": { "current": 1 }, "blkio_stats": { "io_service_bytes_recursive": [ ], "io_serviced_recursive": [ ], "io_queue_recursive": [ ], "io_service_time_recursive": [ ], "io_wait_time_recursive": [ ], "io_merged_recursive": [ ], "io_time_recursive": [ ], "sectors_recursive": [ ] }, "num_procs": 0, "storage_stats": { }, "cpu_stats": { "cpu_usage": { "total_usage": 177232665, "percpu_usage": [ 13376224, 163856441 ], "usage_in_kernelmode": 0, "usage_in_usermode": 160000000 }, "system_cpu_usage": 13977820000000, "online_cpus": 2, "throttling_data": { "periods": 0, "throttled_periods": 0, "throttled_time": 0 } }, "precpu_stats": { "cpu_usage": { "total_usage": 177232665, "percpu_usage": [ 13376224, 163856441 ], "usage_in_kernelmode": 0, "usage_in_usermode": 160000000 }, "system_cpu_usage": 13975800000000, "online_cpus": 2, "throttling_data": { "periods": 0, "throttled_periods": 0, "throttled_time": 0 } }, "memory_stats": { "usage": 532480, "max_usage": 6279168, "stats": { "active_anon": 40960, "active_file": 0, "cache": 0, "dirty": 0, "hierarchical_memory_limit": 9223372036854771712, "hierarchical_memsw_limit": 9223372036854771712, "inactive_anon": 0, "inactive_file": 0, "mapped_file": 0, "pgfault": 2033, "pgmajfault": 0, "pgpgin": 1734, "pgpgout": 1724, "rss": 40960, "rss_huge": 0, "total_active_anon": 40960, "total_active_file": 0, "total_cache": 0, "total_dirty": 0, "total_inactive_anon": 0, "total_inactive_file": 0, "total_mapped_file": 0, "total_pgfault": 2033, "total_pgmajfault": 0, "total_pgpgin": 1734, "total_pgpgout": 1724, "total_rss": 40960, "total_rss_huge": 0, "total_unevictable": 0, "total_writeback": 0, "unevictable": 0, "writeback": 0 }, "limit": 4073377792 }, "name": "/ecs-curltest-26-internalecspause-a6bcc3dbadfacfe85300", "id": "01999f2e5c6cf4df3873f28950e6278813408f281c54778efec860d0caad4854", "networks": { "eth0": { "rx_bytes": 84, "rx_packets": 2, "rx_errors": 0, "rx_dropped": 0, "tx_bytes": 84, "tx_packets": 2, "tx_errors": 0, "tx_dropped": 0 } }, "network_rate_stats": { "rx_bytes_per_sec": 0, "tx_bytes_per_sec": 0 } }, "5fc21e5b015f899d22618f8aede80b6d70d71b2a75465ea49d9462c8f3d2d3af": { "read": "2020-10-02T00:51:32.512771349Z", "preread": "2020-10-02T00:51:31.510597736Z", "pids_stats": { "current": 3 }, "blkio_stats": { "io_service_bytes_recursive": [ ], "io_serviced_recursive": [ ], "io_queue_recursive": [ ], "io_service_time_recursive": [ ], "io_wait_time_recursive": [ ], "io_merged_recursive": [ ], "io_time_recursive": [ ], "sectors_recursive": [ ] }, "num_procs": 0, "storage_stats": { }, "cpu_stats": { "cpu_usage": { "total_usage": 379075681, "percpu_usage": [ 191355275, 187720406 ], "usage_in_kernelmode": 60000000, "usage_in_usermode": 310000000 }, "system_cpu_usage": 13977800000000, "online_cpus": 2, "throttling_data": { "periods": 0, "throttled_periods": 0, "throttled_time": 0 } }, "precpu_stats": { "cpu_usage": { "total_usage": 378825197, "percpu_usage": [ 191104791, 187720406 ], "usage_in_kernelmode": 60000000, "usage_in_usermode": 310000000 }, "system_cpu_usage": 13975800000000, "online_cpus": 2, "throttling_data": { "periods": 0, "throttled_periods": 0, "throttled_time": 0 } }, "memory_stats": { "usage": 1814528, "max_usage": 6299648, "stats": { "active_anon": 606208, "active_file": 0, "cache": 0, "dirty": 0, "hierarchical_memory_limit": 134217728, "hierarchical_memsw_limit": 268435456, "inactive_anon": 0, "inactive_file": 0, "mapped_file": 0, "pgfault": 5377, "pgmajfault": 0, "pgpgin": 3613, "pgpgout": 3465, "rss": 606208, "rss_huge": 0, "total_active_anon": 606208, "total_active_file": 0, "total_cache": 0, "total_dirty": 0, "total_inactive_anon": 0, "total_inactive_file": 0, "total_mapped_file": 0, "total_pgfault": 5377, "total_pgmajfault": 0, "total_pgpgin": 3613, "total_pgpgout": 3465, "total_rss": 606208, "total_rss_huge": 0, "total_unevictable": 0, "total_writeback": 0, "unevictable": 0, "writeback": 0 }, "limit": 134217728 }, "name": "/ecs-curltest-26-curl-c2e5f6e0cf91b0bead01", "id": "5fc21e5b015f899d22618f8aede80b6d70d71b2a75465ea49d9462c8f3d2d3af", "networks": { "eth0": { "rx_bytes": 84, "rx_packets": 2, "rx_errors": 0, "rx_dropped": 0, "tx_bytes": 84, "tx_packets": 2, "tx_errors": 0, "tx_dropped": 0 } }, "network_rate_stats": { "rx_bytes_per_sec": 0, "tx_bytes_per_sec": 0 } } }