panwang преди 3 години
родител
ревизия
e3e2fa8493
променени са 3 файла, в които са добавени 43 реда и са изтрити 7 реда
  1. BIN
      __pycache__/app.cpython-37.pyc
  2. 7 2
      app.py
  3. 36 5
      test.py

BIN
__pycache__/app.cpython-37.pyc


+ 7 - 2
app.py

@@ -46,7 +46,10 @@ 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', ['total_cnt','success_cnt','produce_video_rate'], registry=registry)
+produce_video_task_rate = Gauge("produce_video_task_rate", 'rate', ['rate'], registry=registry)
+produce_video_task_total = Gauge("produce_video_task_total", 'total', ['total_cnt'], registry=registry)
+produce_video_task_sucess = Gauge("produce_video_task_sucess", 'sucess', ['sucess_cnt'], 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)
@@ -209,7 +212,9 @@ def all_metric():
     else:
         rate = 100
 
-    produce_video_task_rate.labels(total_cnt, success_cnt, "produce_video_task_rate").set(rate)
+    # produce_video_task_rate.labels(total_cnt, success_cnt, "produce_video_task_rate").set(rate)
+    produce_video_task_total.labels('total_cnt').set(total_cnt)
+    produce_video_task_sucess.labels('success_cnt').set(success_cnt)
 
 
 

+ 36 - 5
test.py

@@ -55,6 +55,41 @@ def produce_video_data():
               " 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)
                )
 
+
+def all_metric():
+    """视频合成类metrics"""
+
+    """视频合成成功率"""
+    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 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 < 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)
+
+                )
+    res = db_query(query_sql)
+    print(res)
+    if res[0] is not None:
+        total_cnt = res[0]
+    else:
+        total_cnt = 0
+    if res[1] is not None:
+        success_cnt = res[1]
+    else:
+        success_cnt = 0
+    if res[2] is not None:
+        rate = res[2]
+    else:
+        rate = 100
+    print(total_cnt,success_cnt,rate)
 if __name__ == '__main__':
     # with session_maker() as session:
     #     instance_info = session.query(InstanceList).filter(InstanceList.status==0).all()
@@ -290,9 +325,5 @@ if __name__ == '__main__':
     # if res[0] is not None:
     #     print(res[0])
 
-    from datetime import date, timedelta
-
-    yesterday = (date.today() + timedelta(days=-1)).strftime("%Y%m%d")
-    today = date.today().strftime("%Y%m%d")
-    print(yesterday,today)
+    all_metric()