panwang %!s(int64=3) %!d(string=hai) anos
pai
achega
c6b35acb55
Modificáronse 2 ficheiros con 23 adicións e 12 borrados
  1. 7 5
      app.py
  2. 16 7
      test.py

+ 7 - 5
app.py

@@ -182,8 +182,9 @@ 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
+    time_stamp = int(time.time())
+    end_time = int(datetime.datetime.fromtimestamp(time_stamp).strftime('%Y%m%d%H%M%S')) * 1000000000
+    start_time = int(datetime.datetime.fromtimestamp(time_stamp-300).strftime('%Y%m%d%H%M%S')) * 1000000000
     print(start_time, end_time)
     query_sql = ("select totalCount , (successCount+processingCount1), round((successCount + processingCount1)/totalCount * 100,2) from  "
                 "(select count(*) as totalCount,"
@@ -207,10 +208,11 @@ def all_metric():
         success_cnt = res[1]
     else:
         success_cnt = 0
-    if res[2] is not None:
-        rate = res[2]
-    else:
+
+    if  total_cnt == 0:
         rate = 100
+    else:
+        rate = (success_cnt/total_cnt) *100
 
     produce_video_task_rate.labels("produce_video_task_rate").set(rate)
     produce_video_task_total.labels('total_cnt').set(total_cnt)

+ 16 - 7
test.py

@@ -60,8 +60,9 @@ 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
+    time_stamp = int(time.time())
+    end_time = int(datetime.datetime.fromtimestamp(time_stamp).strftime('%Y%m%d%H%M%S')) * 1000000000
+    start_time = int(datetime.datetime.fromtimestamp(time_stamp-300).strftime('%Y%m%d%H%M%S')) * 1000000000
     print(start_time, end_time)
     query_sql = ("select totalCount , (successCount+processingCount1), round((successCount + processingCount1)/totalCount * 100,2) from  "
                 "(select count(*) as totalCount,"
@@ -76,7 +77,6 @@ def all_metric():
 
                 )
     res = db_query(query_sql)
-    print(res)
     if res[0] is not None:
         total_cnt = res[0]
     else:
@@ -85,10 +85,15 @@ def all_metric():
         success_cnt = res[1]
     else:
         success_cnt = 0
-    if res[2] is not None:
-        rate = res[2]
-    else:
+
+    if total_cnt == 0:
         rate = 100
+    else:
+        rate = round((success_cnt / total_cnt) ,2)* 100
+
+    # produce_video_task_rate.labels("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)
     print(total_cnt,success_cnt,rate)
 if __name__ == '__main__':
     # with session_maker() as session:
@@ -324,6 +329,10 @@ if __name__ == '__main__':
     #
     # if res[0] is not None:
     #     print(res[0])
-
+    time_stamp = int(time.time())
+    end_time = int(datetime.datetime.fromtimestamp(time_stamp).strftime('%Y%m%d%H%M%S')) * 1000000000
+    start_time = int(datetime.datetime.fromtimestamp(time_stamp-300).strftime('%Y%m%d%H%M%S')) * 1000000000
+    # rt - 300
+    print(start_time, end_time)
     all_metric()