in netbench-cdk/netbench-monitor/handler.py [0:0]
def process_describe_instances(response: dict) -> dict:
# Walk the running instance list checking the age of the disk mount
# against MAX_LIFETIME
instance_above_max: dict[str, int] = {}
instance_below_max: dict[str, int] = {}
alarm: bool = False
for group in response['Reservations']:
instance = group['Instances'][0]
# If this is missing, skip this instance
# this should never happen in the running state.
if 'BlockDeviceMappings' not in instance:
raise ValueError("Missing expected field BlockDeviceMapping; "
+ "running instances should have at least one "
+ "block device attached.")
if len(instance['BlockDeviceMappings']) > 0:
age = get_ebs_age(instance['BlockDeviceMappings'][0]['Ebs']['AttachTime'])
if age > MAX_LIFETIME:
alarm = True
instance_above_max[instance['InstanceId']] = age
else:
instance_below_max[instance['InstanceId']] = age
else:
continue
return {"alarm_threshold": MAX_LIFETIME,
"overall_alarm": alarm,
"instances_below_max": instance_below_max,
"instances_above_max": instance_above_max }