def sort_by_system_instance_health(instances):
    return sorted(
        instances,
        key=lambda i: (
            i.instance_status["SystemStatus"]["Status"] != "ok"
            or i.instance_status["InstanceStatus"]["Status"] != "ok"
        ),
    )