Ver código fonte

修改合成成功率计算方法

panwang 3 anos atrás
pai
commit
e726385d0a
3 arquivos alterados com 40 adições e 8 exclusões
  1. 6 0
      .idea/vcs.xml
  2. 20 6
      app.py
  3. 14 2
      utils.py

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 20 - 6
app.py

@@ -171,14 +171,28 @@ def  slb_request_status_metric():
 @app.route('/metrics')
 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
+    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
+    query_sql = ("select 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  "
+                 "(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)
+
+                )
+    res = db_query(query_sql)
+
 #     sql = "".format(start_time, end_time)
 #     res = db_query(sql)
-#     if res[0] is not None:
-#         produce_video_task_rate.labels("produce_video_task_rate").set(res[0])
-#     else:
-#         produce_video_task_rate.labels("produce_video_task_rate").set(100)
+    if res[0] is not None:
+        produce_video_task_rate.labels("produce_video_task_rate").set(res[0])
+    else:
+        produce_video_task_rate.labels("produce_video_task_rate").set(0)
 #
 #     sql = "select v1 as 平均合成耗时,v2 as 平均视频时长, round(v2/v1,1) as 时长耗时比 from  (select avg(produce_done_timestamp - submit_timestamp) as v1, avg(video_duration/1000) as v2 from produce_video_project where project_id > {} and project_id < {} and app_type not in (13,15) and produce_status in (5,6,7,8)) as t1".format(start_time, end_time)
 # #tts

+ 14 - 2
utils.py

@@ -373,5 +373,17 @@ if __name__ == '__main__':
     #     avgtime = round(float(res.body[i]["avg_time"]), 2)
     #     print(url,qps ,avgtime)
 
-    res = app_openapi_qps_avgtime_count()
-    print(res.body)
+    query_sql = ("select 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  "
+                 "(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 > '20210804000000000111111' and t1.project_id < '20210805000000000111111' and t1.app_type not in (1,13,15)) s1) ss1"
+
+                )
+    res = db_query(query_sql)
+    print(res)