使用 Boto3 的 EMR 集群的运行状况

Health & Status of EMR Cluster using Boto3

我想使用boto3获取EMR集群的健康状态。 如果它是健康的,那么我应该能够 运行 我的 jobs.How 知道集群是否健康? 我 运行 下面的代码,它返回了一个字典。

import boto3

emr_client = boto3.client('emr')
clusters = emr_client.list_clusters(ClusterStates=['STARTING', 'BOOTSTRAPPING', 'RUNNING', 'WAITING'])
for cluster in clusters['Clusters']:  
  cluster_id = cluster['Id']
  response = emr_client.list_instances(ClusterId=cluster_id)
  print(response)

输出:

{'Instances': [{'Id': 'ci-xxxx', 'Ec2InstanceId': 'i-xxxx', 'PublicDnsName': '', 'PrivateDnsName': 'ip-xxxx.ec2.internal', 'PrivateIpAddress': 'xxxx', 'Status': {'State': 'BOOTSTRAPPING', 'StateChangeReason': {}, 'Timeline': {'CreationDateTime': datetime.datetime(2021, 12, 27, 13, 8, 28, 758000, tzinfo=tzlocal())}}, 'InstanceGroupId': 'ig-xxxx', 'Market': 'ON_DEMAND', 'InstanceType': 'm5.xlarge', 'EbsVolumes': [{'Device': 'xxx', 'VolumeId': 'vol-xxx'}, {'Device': 'xxx', 'VolumeId': 'vol-xxxx'}]}, {'Id': 'ci-xxxx', 'Ec2InstanceId': 'i-xxxx', 'PublicDnsName': '', 'PrivateDnsName': 'ip-xxxx.ec2.internal', 'PrivateIpAddress': 'xxxx', 'Status': {'State': 'BOOTSTRAPPING', 'StateChangeReason': {}, 'Timeline': {'CreationDateTime': datetime.datetime(2021, 12, 27, 13, 8, 28, 758000, tzinfo=tzlocal())}}, 'InstanceGroupId': 'ig-xxxx', 'Market': 'ON_DEMAND', 'InstanceType': 'm5.xlarge', 'EbsVolumes': [{'Device': 'xxx', 'VolumeId': 'vol-xxxx'}, {'Device': 'xxx', 'VolumeId': 'vol-xxxx'}]}], 'ResponseMetadata': {'RequestId': 'xxxx', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'xxxx', 'content-type': 'application/x-amz-json-1.1', 'content-length': '989', 'date': 'Mon, 27 Dec 2021 19:08:55 GMT'}, 'RetryAttempts': 0}}

我们如何从中获取实例状态? list_instances 是寻找 EMR 集群健康状况的正确方法吗?

谢谢。

我猜你想要的是集群中实例的健康状况。如果是这样,您必须 list_instances, and there you can find their Status. You can also iterate over the instance ids from the previous command and use describe_instance_status 了解更多详情。