supeng 4 ماه پیش
والد
کامیت
77e7a9a363
2فایلهای تغییر یافته به همراه9 افزوده شده و 10 حذف شده
  1. 6 7
      longvideoapi/longvideoapi_reduce_with_count.py
  2. 3 3
      longvideoapi/utils.py

+ 6 - 7
longvideoapi/longvideoapi_reduce_with_count.py

@@ -40,12 +40,12 @@ def remove_instances(ecs_client, alb_client, instance_ids, port):
                                                server_group_id_list=longvideoapi_config.server_group_id_list,
                                                instance_ids=instance_ids, port=port)
         logging.info(
-            f"Successfully removed instance_ids:  {instance_ids} from server group {longvideoapi_config.server_group_id_list}.")
+            f"Successfully removed count:{len(instance_ids)} instance_ids:  {instance_ids} from server group {longvideoapi_config.server_group_id_list}.")
     except Exception as e:
         logging.error(
-            f"Failed to remove instance_ids: {instance_ids} from server group {longvideoapi_config.server_group_id_list}: {e}")
+            f"Failed to remove count:{len(instance_ids)} instance_ids: {instance_ids} from server group {longvideoapi_config.server_group_id_list}: {e}")
 
-    logging.info(f"Remove from ALB finished, instances: {instance_ids}")
+    logging.info(f"Remove from ALB finished, count:{len(instance_ids)} instances: {instance_ids}")
 
     # 3. 停止机器
     utils.stop_instances(ecs_client=ecs_client, instance_ids=instance_ids)
@@ -100,15 +100,14 @@ def main():
 
         # 获取指定释放的机器数量
         reduce_count = int(sys.argv[1])
-        logging.info(f"reduce instances count: {reduce_count}")
+        logging.info(f"reduce_count: {reduce_count}")
 
         # 获取 ALB 下所有机器
         online_instance_ids = utils.list_server_group_servers(alb_client=alb_client,
                                                               server_group_id=longvideoapi_config.server_group_id_list[
                                                                   0])
         online_instance_count = len(online_instance_ids)
-        logging.info(f"online instance count: {online_instance_count}.")
-        logging.info(f"online instance ids: {online_instance_ids}")
+        logging.info(f"online instance count: {online_instance_count} instance_ids: {online_instance_ids}")
 
         if online_instance_count - reduce_count < 10:
             logging.error("缩容后服务器数量不能小于10台")
@@ -116,7 +115,7 @@ def main():
 
         # 获取前 count 台机器进行释放
         reduce_instance_ids = online_instance_ids[:reduce_count]
-        logging.info(f"reduce instances: {reduce_instance_ids}")
+        logging.info(f"reduce instances count = {len(reduce_instance_ids)} instances: {reduce_instance_ids}")
 
         # 停止并释放机器
         remove_instances(ecs_client=ecs_client, alb_client=alb_client, instance_ids=reduce_instance_ids,

+ 3 - 3
longvideoapi/utils.py

@@ -253,7 +253,7 @@ def release_instances(ecs_client, instance_ids, force=False):
         response = send_request(ecs_client=ecs_client, request=request)
         # return response
         if response.get('Code') is None:
-            logging.info(f"Release instances finished, instances: {instance_id_sub_array}")
+            logging.info(f"Release instances finished, count = {len(instance_id_sub_array)} instances: {instance_id_sub_array}")
         else:
             logging.error(f"Release instances fail!!!")
             sys.exit()
@@ -281,7 +281,7 @@ def get_instances_status(ecs_client, instance_ids):
                 stopped_instances_sub = [instance.get('InstanceId') for instance in instances_list if
                                      instance.get('Status') == 'Stopped']
                 if len(stopped_instances_sub) == len(instance_id_sub_array):
-                    logging.info(f"Instances stopped status set success, instances: {stopped_instances_sub}")
+                    logging.info(f"Instances stopped status set success, count:{len(stopped_instances_sub)} instances: {stopped_instances_sub}")
                     stopped_instances.extend(stopped_instances_sub)
                     break
                 else:
@@ -309,7 +309,7 @@ def stop_instances(ecs_client, instance_ids, force_stop=False):
         response = send_request(ecs_client=ecs_client, request=request)
         # return response
         if response.get('Code') is None:
-            logging.info(f"Instances stop finished, instances: {instance_id_sub_array}")
+            logging.info(f"Instances stop finished, count:{len(instance_id_sub_array)} instances: {instance_id_sub_array}")
         else:
             logging.error(f"Failed to stop instances: {response}")
             sys.exit()