Bläddra i källkod

调整视频合成成功率计算数据

panwang 3 år sedan
förälder
incheckning
f28974828f
4 ändrade filer med 26 tillägg och 9 borttagningar
  1. BIN
      __pycache__/app.cpython-37.pyc
  2. BIN
      __pycache__/utils.cpython-37.pyc
  3. 25 8
      app.py
  4. 1 1
      utils.py

BIN
__pycache__/app.cpython-37.pyc


BIN
__pycache__/utils.cpython-37.pyc


+ 25 - 8
app.py

@@ -24,7 +24,8 @@ registry = CollectorRegistry(auto_describe=False)
 # 定义后台执行调度器
 scheduler = BackgroundScheduler()
 scheduler.add_job(func=update_request_url_list, trigger="interval", seconds=300)
-scheduler.add_job(func=produce_video_ratio_cnt, trigger="interval", seconds=86400)
+scheduler.add_job(produce_video_ratio_cnt,  'cron', hour='00', minute='03')
+
 scheduler.start()
 atexit.register(lambda: scheduler.shutdown())
 
@@ -45,7 +46,7 @@ probe_http_first_byte_time = Gauge("http_first_byte_time", 'h5',['server_name'],
 slb_http_status_code = Gauge("slb_http_status_code", 'slb', ['server_name', 'status'], registry=registry)
 #视频合成
 produce_video_task_count = Gauge("produce_video_task_count", 'status', ['status'], registry=registry)
-produce_video_task_rate = Gauge("produce_video_task_rate", 'produce_video_rate', ['produce_video_rate'], registry=registry)
+produce_video_task_rate = Gauge("produce_video_task_rate", 'produce_video_rate', ['total_cnt','success_cnt','produce_video_rate'], registry=registry)
 produce_video_task_ratio = Gauge("produce_video_task_ratio", 'produce_video_ratio', ['ratio'], registry=registry)
 
 produce_video_tts_count = Gauge("tts_aliyun_azure", 'success', ['tts_channel'], registry=registry)
@@ -181,13 +182,13 @@ def all_metric():
     start_time = int(time.strftime("%Y%m%d%H%M", time.localtime())) * 100000000000
     end_time = (int(time.strftime("%Y%m%d%H%M", time.localtime())) + 5) * 100000000000
     print(start_time, end_time)
-    query_sql = ("select round((successCount + processingCount1)/totalCount * 100,2) from  "
+    query_sql = ("select totalCount , (successCount+processingCount1), round((successCount + processingCount1)/totalCount * 100,2) from  "
                 "(select count(*) as totalCount,"
                  "sum(case when produce_status in (5,6,7,8) then 1 else 0 end) as successCount,"
                  "sum(case when produce_status = 99 then 1 else 0 end) as failCount , "
                  "sum(case when produce_status in(0,1,2,3,4) then 1 else 0 end) as processingCount,"
-                 "sum(case when produce_status in(0,1,2,3,4) and (rate < 1 or rate is null) then 1 else 0 end) processingCount1,"
-                 "sum(case when produce_status in(0,1,2,3,4) and rate >= 1 then 1 else 0 end) processingCount2  from  "
+                 "sum(case when produce_status in(0,1,2,3,4) and (rate < 0.7 or rate is null) then 1 else 0 end) processingCount1,"
+                 "sum(case when produce_status in(0,1,2,3,4) and rate >= 0.7 then 1 else 0 end) processingCount2  from  "
                  "(select t1.project_id, t1.produce_status, round((t2.last_connect_timestamp - t1.submit_timestamp) / (t1.video_duration/1000), 1) as rate  from produce_video_project t1  "
                  "left join produce_video_project_connect_time t2 on t1.project_id = t2.project_id "
                  "where t1.project_id > %s and t1.project_id < %s and t1.app_type not in (1,13,15)) s1) ss1" %(start_time ,end_time)
@@ -196,9 +197,19 @@ def all_metric():
     res = db_query(query_sql)
 
     if res[0] is not None:
-        produce_video_task_rate.labels("produce_video_task_rate").set(res[0])
+        total_cnt = res[0]
+    else:
+        total_cnt = 0
+    if res[1] is not None:
+        success_cnt = res[1]
     else:
-        produce_video_task_rate.labels("produce_video_task_rate").set(-1)
+        success_cnt = 0
+    if res[2] is not None:
+        rate = res[2]
+    else:
+        rate = 100
+
+    produce_video_task_rate.labels(total_cnt, success_cnt, "produce_video_task_rate").set(rate)
 
 
 
@@ -274,7 +285,7 @@ def all_metric():
         produce_video_tts_count.labels("azure_success").set(res[0]["count"])
     else:
         produce_video_tts_count.labels("azure_success").set(0)
-    res = logs_tts_count("aliyun", 0)
+    res = logs_tts_count("azure", 0)
     if res is not None:
         produce_video_tts_count.labels("azure_fail").set(res[0]["count"])
     else:
@@ -394,6 +405,12 @@ def produce_video_data():
                )
 
 
+@app.route('/healthcheck')
+def healthcheck():
+
+    return "OK"
+
+
 if __name__ == '__main__':
     # app.run()
     app.run(host='192.168.201.1', port=9091)

+ 1 - 1
utils.py

@@ -499,7 +499,7 @@ def  produce_video_ratio_cnt():
     conn = pymysql.connect(host=HOST, user=USERNAME, password=PASSWORD, database=DATABASE, charset="utf8")
     cursor = conn.cursor()
     start_time = int((date.today() + timedelta(days=-1)).strftime("%Y%m%d")) * 1000000000000000
-    end_time = int(date.today().strftime("%Y%m%d")) * 1000000000000000
+    # end_time = int(date.today().strftime("%Y%m%d")) * 1000000000000000
     # end_time = int((date.today() + timedelta(days=0)).strftime("%Y%m%d")) * 1000000000000000
 
     sql = ("select count(*) as totalCount, "