mps_monitor.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. from datetime import datetime, time, timedelta
  2. import pytz
  3. from alibabacloud_mts20140618.client import Client as MTSClient
  4. from alibabacloud_mts20140618.models import ListJobRequest
  5. from alibabacloud_tea_openapi import models
  6. from resource.monitor.basic_monitor import BasicMonitor
  7. def write_file(content: str, dt: str):
  8. print(content)
  9. with open(f"/Users/zhao/Desktop/tzld/文档/MPS/mps_monitor_{dt}.txt", "a+") as f:
  10. f.write(content)
  11. f.write("\n")
  12. class MPSMonitor(BasicMonitor):
  13. def __init__(self):
  14. super().__init__()
  15. @classmethod
  16. def download_date(cls, dt: datetime, client: MTSClient):
  17. dt_str = dt.strftime("%Y%m%d")
  18. write_file("任务ID,任务创建时间,任务结束时间,任务状态,时长,模板ID,管道ID,输入文件,输出文件", dt_str)
  19. next_page_token = ""
  20. start_time = datetime.combine(dt, time.min)
  21. end_time = datetime.combine(dt + timedelta(days=1), time.min)
  22. while True:
  23. request = ListJobRequest(
  24. maximum_page_size=100,
  25. start_of_job_created_time_range=start_time.astimezone(pytz.UTC).strftime('%Y-%m-%dT%H:%M:%SZ'),
  26. end_of_job_created_time_range=end_time.astimezone(pytz.UTC).strftime('%Y-%m-%dT%H:%M:%SZ'),
  27. next_page_token=next_page_token
  28. )
  29. response = client.list_job(request)
  30. body = response.body
  31. jobs = body.job_list.job
  32. for job in jobs:
  33. creation_time = job.creation_time
  34. finish_time = job.finish_time
  35. state = job.state
  36. job_id = job.job_id
  37. output = job.output
  38. duration = output.properties.duration
  39. output_file_info = output.output_file
  40. output_file = f"{output_file_info.bucket}:{output_file_info.object}"
  41. pipline_id = job.pipeline_id
  42. template_id = output.template_id
  43. input_file_info = job.input
  44. input_file = f"{input_file_info.bucket}:{input_file_info.object}"
  45. write_file(f"{job_id},{creation_time},{finish_time},{state},{duration},{template_id},{pipline_id},{input_file},{output_file}", dt_str)
  46. next_page_token = body.next_page_token
  47. if not next_page_token:
  48. break
  49. def run(self):
  50. config = models.Config(
  51. access_key_id=self.access_key_id,
  52. access_key_secret=self.access_key_secret,
  53. endpoint="mts.cn-hangzhou.aliyuncs.com"
  54. )
  55. # client = MTSClient(config)
  56. # template_ids = ["02ace648c50f4136afb546adede4eb49",
  57. # "19d56171d13b4b679bc057eb42b6563f",
  58. # "295ce1741a3e470983c7e1cf303f382e",
  59. # "794661a4f1384f6e9642da02f3190313",
  60. # "9ad1268fce31499884e2d440105ae51e",
  61. # "a7c5593789644fa1a010b579557e7fe2",
  62. # "adfcf35bdf3745c18d739dcb08428a80",
  63. # "b2098fcbc5534cce9c90d32fc5d5124c",
  64. # "bacabb6700564672804d8a84a07531eb",
  65. # "cb8429acf24544ff9bada946bc23e643",
  66. # "cc963a743d2140f083cace98a02b83b6",
  67. # "d34dfbd6ed944eeaad0555f212159eb3",
  68. # "e19880ead9ac477bbad75680bd400847",
  69. # "f4f25f0668db49c5805c823c61d011a5",
  70. # "fcaace386e4241fabddef70e3ce0d2cb"
  71. # ]
  72. # print("模板ID,模板名,编解码格式,宽*高,编码级别")
  73. # for template_id in template_ids:
  74. # request = QueryTemplateListRequest(
  75. # template_ids=template_id
  76. # )
  77. # response = client.query_template_list(request)
  78. # for template in response.body.template_list.template:
  79. # print(f"{template.id},{template.name},{template.video.codec},{template.video.width}*{template.video.height},{template.video.profile}")
  80. # today = datetime(2026, 1, 31, 0, 0, 0)
  81. # min_dt = datetime(2025, 12, 1, 0, 0, 0)
  82. # tasks = []
  83. # for i in range(0, 1000):
  84. # download_dt = today - timedelta(days=i)
  85. # if download_dt < min_dt:
  86. # break
  87. # tasks.append(lambda dt=download_dt, client=MTSClient(config): self.download_date(dt, client))
  88. #
  89. # process_tasks(tasks, 15)
  90. # self.download_date(dt=datetime(2026, 2, 10, 0, 0, 0), client=MTSClient(config))
  91. if __name__ == '__main__':
  92. monitor = MPSMonitor()
  93. monitor.run()