Fargate 上任务的 Amazon ECS 任务元数据 v4 示例
以下示例显示了在上 AWS Fargate 运行的 Amazon ECS 任务的任务元数据端点的输出示例。
通过容器,您可以在任务元数据端点后面使用 curl 来查询端点,例如 curl ${ECS_CONTAINER_METADATA_URI_V4}/task
。
容器元数据响应示例
查询 ${ECS_CONTAINER_METADATA_URI_V4}
终端节点时,仅返回有关容器本身的元数据。下面是一个示例输出。
{
"DockerId": "cd189a933e5849daa93386466019ab50-2495160603",
"Name": "curl",
"DockerName": "curl",
"Image": "111122223333.dkr.ecr.us-west-2.amazonaws.com/curltest:latest",
"ImageID": "sha256:25f3695bedfb454a50f12d127839a68ad3caf91e451c1da073db34c542c4d2cb",
"Labels": {
"com.amazonaws.ecs.cluster": "arn:aws:ecs:us-west-2:111122223333:cluster/default",
"com.amazonaws.ecs.container-name": "curl",
"com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:111122223333:task/default/cd189a933e5849daa93386466019ab50",
"com.amazonaws.ecs.task-definition-family": "curltest",
"com.amazonaws.ecs.task-definition-version": "2"
},
"DesiredStatus": "RUNNING",
"KnownStatus": "RUNNING",
"Limits": {
"CPU": 10,
"Memory": 128
},
"CreatedAt": "2020-10-08T20:09:11.44527186Z",
"StartedAt": "2020-10-08T20:09:11.44527186Z",
"Type": "NORMAL",
"Networks": [
{
"NetworkMode": "awsvpc",
"IPv4Addresses": [
"192.0.2.3"
],
"AttachmentIndex": 0,
"MACAddress": "0a:de:f6:10:51:e5",
"IPv4SubnetCIDRBlock": "192.0.2.0/24",
"DomainNameServers": [
"192.0.2.2"
],
"DomainNameSearchList": [
"us-west-2.compute.internal"
],
"PrivateDNSName": "ip-10-0-0-222.us-west-2.compute.internal",
"SubnetGatewayIpv4Address": "192.0.2.0/24"
}
],
"ContainerARN": "arn:aws:ecs:us-west-2:111122223333:container/05966557-f16c-49cb-9352-24b3a0dcd0e1",
"LogOptions": {
"awslogs-create-group": "true",
"awslogs-group": "/ecs/containerlogs",
"awslogs-region": "us-west-2",
"awslogs-stream": "ecs/curl/cd189a933e5849daa93386466019ab50"
},
"LogDriver": "awslogs",
"Snapshotter": "overlayfs"
}
Fargate 上任务的 Amazon ECS 任务元数据 v4 示例
查询 ${ECS_CONTAINER_METADATA_URI_V4}/task
终端节点时,将返回有关容器所属的任务的元数据。下面是一个示例输出。
{
"Cluster": "arn:aws:ecs:us-east-1:123456789012:cluster/clusterName",
"TaskARN": "arn:aws:ecs:us-east-1:123456789012:task/MyEmptyCluster/bfa2636268144d039771334145e490c5",
"Family": "sample-fargate",
"Revision": "5",
"DesiredStatus": "RUNNING",
"KnownStatus": "RUNNING",
"Limits": {
"CPU": 0.25,
"Memory": 512
},
"PullStartedAt": "2023-07-21T15:45:33.532811081Z",
"PullStoppedAt": "2023-07-21T15:45:38.541068435Z",
"AvailabilityZone": "us-east-1d",
"Containers": [
{
"DockerId": "bfa2636268144d039771334145e490c5-1117626119",
"Name": "curl-image",
"DockerName": "curl-image",
"Image": "curlimages/curl",
"ImageID": "sha256:daf3f46a2639c1613b25e85c9ee4193af8a1d538f92483d67f9a3d7f21721827",
"Labels": {
"com.amazonaws.ecs.cluster": "arn:aws:ecs:us-east-1:123456789012:cluster/MyEmptyCluster",
"com.amazonaws.ecs.container-name": "curl-image",
"com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-east-1:123456789012:task/MyEmptyCluster/bfa2636268144d039771334145e490c5",
"com.amazonaws.ecs.task-definition-family": "sample-fargate",
"com.amazonaws.ecs.task-definition-version": "5"
},
"DesiredStatus": "RUNNING",
"KnownStatus": "RUNNING",
"Limits": { "CPU": 128 },
"CreatedAt": "2023-07-21T15:45:44.91368314Z",
"StartedAt": "2023-07-21T15:45:44.91368314Z",
"Type": "NORMAL",
"Networks": [
{
"NetworkMode": "awsvpc",
"IPv4Addresses": ["172.31.42.189"],
"AttachmentIndex": 0,
"MACAddress": "0e:98:9f:33:76:d3",
"IPv4SubnetCIDRBlock": "172.31.32.0/20",
"DomainNameServers": ["172.31.0.2"],
"DomainNameSearchList": ["ec2.internal"],
"PrivateDNSName": "ip-172-31-42-189.ec2.internal",
"SubnetGatewayIpv4Address": "172.31.32.1/20"
}
],
"ContainerARN": "arn:aws:ecs:us-east-1:123456789012:container/MyEmptyCluster/bfa2636268144d039771334145e490c5/da6cccf7-1178-400c-afdf-7536173ee209",
"Snapshotter": "overlayfs"
},
{
"DockerId": "bfa2636268144d039771334145e490c5-3681984407",
"Name": "fargate-app",
"DockerName": "fargate-app",
"Image": "public.ecr.aws/docker/library/httpd:latest",
"ImageID": "sha256:8059bdd0058510c03ae4c808de8c4fd2c1f3c1b6d9ea75487f1e5caa5ececa02",
"Labels": {
"com.amazonaws.ecs.cluster": "arn:aws:ecs:us-east-1:123456789012:cluster/MyEmptyCluster",
"com.amazonaws.ecs.container-name": "fargate-app",
"com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-east-1:123456789012:task/MyEmptyCluster/bfa2636268144d039771334145e490c5",
"com.amazonaws.ecs.task-definition-family": "sample-fargate",
"com.amazonaws.ecs.task-definition-version": "5"
},
"DesiredStatus": "RUNNING",
"KnownStatus": "RUNNING",
"Limits": { "CPU": 2 },
"CreatedAt": "2023-07-21T15:45:44.954460255Z",
"StartedAt": "2023-07-21T15:45:44.954460255Z",
"Type": "NORMAL",
"Networks": [
{
"NetworkMode": "awsvpc",
"IPv4Addresses": ["172.31.42.189"],
"AttachmentIndex": 0,
"MACAddress": "0e:98:9f:33:76:d3",
"IPv4SubnetCIDRBlock": "172.31.32.0/20",
"DomainNameServers": ["172.31.0.2"],
"DomainNameSearchList": ["ec2.internal"],
"PrivateDNSName": "ip-172-31-42-189.ec2.internal",
"SubnetGatewayIpv4Address": "172.31.32.1/20"
}
],
"ContainerARN": "arn:aws:ecs:us-east-1:123456789012:container/MyEmptyCluster/bfa2636268144d039771334145e490c5/f65b461d-aa09-4acb-a579-9785c0530cbc",
"Snapshotter": "overlayfs"
}
],
"LaunchType": "FARGATE",
"ClockDrift": {
"ClockErrorBound": 0.446931,
"ReferenceTimestamp": "2023-07-21T16:09:17Z",
"ClockSynchronizationStatus": "SYNCHRONIZED"
},
"EphemeralStorageMetrics": {
"Utilized": 261,
"Reserved": 20496
}
}
示例任务统计信息响应
查询 ${ECS_CONTAINER_METADATA_URI_V4}/task/stats
终端节点时,将返回有关容器所属的任务的网络指标。下面是一个示例输出。
{
"3d1f891cded94dc795608466cce8ddcf-464223573": {
"read": "2020-10-08T21:24:44.938937019Z",
"preread": "2020-10-08T21:24:34.938633969Z",
"pids_stats": {},
"blkio_stats": {
"io_service_bytes_recursive": [
{
"major": 202,
"minor": 26368,
"op": "Read",
"value": 638976
},
{
"major": 202,
"minor": 26368,
"op": "Write",
"value": 0
},
{
"major": 202,
"minor": 26368,
"op": "Sync",
"value": 638976
},
{
"major": 202,
"minor": 26368,
"op": "Async",
"value": 0
},
{
"major": 202,
"minor": 26368,
"op": "Total",
"value": 638976
}
],
"io_serviced_recursive": [
{
"major": 202,
"minor": 26368,
"op": "Read",
"value": 12
},
{
"major": 202,
"minor": 26368,
"op": "Write",
"value": 0
},
{
"major": 202,
"minor": 26368,
"op": "Sync",
"value": 12
},
{
"major": 202,
"minor": 26368,
"op": "Async",
"value": 0
},
{
"major": 202,
"minor": 26368,
"op": "Total",
"value": 12
}
],
"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": 1137691504,
"percpu_usage": [
696479228,
441212276,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"usage_in_kernelmode": 80000000,
"usage_in_usermode": 810000000
},
"system_cpu_usage": 9393210000000,
"online_cpus": 2,
"throttling_data": {
"periods": 0,
"throttled_periods": 0,
"throttled_time": 0
}
},
"precpu_stats": {
"cpu_usage": {
"total_usage": 1136624601,
"percpu_usage": [
695639662,
440984939,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
],
"usage_in_kernelmode": 80000000,
"usage_in_usermode": 810000000
},
"system_cpu_usage": 9373330000000,
"online_cpus": 2,
"throttling_data": {
"periods": 0,
"throttled_periods": 0,
"throttled_time": 0
}
},
"memory_stats": {
"usage": 6504448,
"max_usage": 8458240,
"stats": {
"active_anon": 1675264,
"active_file": 557056,
"cache": 651264,
"dirty": 0,
"hierarchical_memory_limit": 536870912,
"hierarchical_memsw_limit": 9223372036854772000,
"inactive_anon": 0,
"inactive_file": 3088384,
"mapped_file": 430080,
"pgfault": 11034,
"pgmajfault": 5,
"pgpgin": 8436,
"pgpgout": 7137,
"rss": 4669440,
"rss_huge": 0,
"total_active_anon": 1675264,
"total_active_file": 557056,
"total_cache": 651264,
"total_dirty": 0,
"total_inactive_anon": 0,
"total_inactive_file": 3088384,
"total_mapped_file": 430080,
"total_pgfault": 11034,
"total_pgmajfault": 5,
"total_pgpgin": 8436,
"total_pgpgout": 7137,
"total_rss": 4669440,
"total_rss_huge": 0,
"total_unevictable": 0,
"total_writeback": 0,
"unevictable": 0,
"writeback": 0
},
"limit": 9223372036854772000
},
"name": "curltest",
"id": "3d1f891cded94dc795608466cce8ddcf-464223573",
"networks": {
"eth1": {
"rx_bytes": 2398415937,
"rx_packets": 1898631,
"rx_errors": 0,
"rx_dropped": 0,
"tx_bytes": 1259037719,
"tx_packets": 428002,
"tx_errors": 0,
"tx_dropped": 0
}
},
"network_rate_stats": {
"rx_bytes_per_sec": 43.298687872232854,
"tx_bytes_per_sec": 215.39347269466413
}
}
}