panwang %!s(int64=3) %!d(string=hai) anos
pai
achega
7ed42b4b32
Modificáronse 4 ficheiros con 49 adicións e 0 borrados
  1. BIN=BIN
      __pycache__/app.cpython-37.pyc
  2. BIN=BIN
      __pycache__/utils.cpython-37.pyc
  3. 27 0
      app.py
  4. 22 0
      utils.py

BIN=BIN
__pycache__/app.cpython-37.pyc


BIN=BIN
__pycache__/utils.cpython-37.pyc


+ 27 - 0
app.py

@@ -309,6 +309,33 @@ def all_metric():
         azure_fail = 0
     produce_video_tts_count.labels("azure_fail").set(azure_fail)
 
+
+    """5m计算"""
+    res = logs_tts_ratio("aliyun", 1)
+    if res is not None:
+        aliyun_success = int(res[0]["count"])
+    else:
+        aliyun_success = 0
+
+    res = logs_tts_ratio("aliyun", 0)
+    if res is not None:
+        aliyun_fail = int(res[0]["count"])
+    else:
+        aliyun_fail = 0
+
+    res = logs_tts_ratio("azure", 1)
+    if res is not None:
+        azure_success = int(res[0]["count"])
+    else:
+        azure_success = 0
+
+    res = logs_tts_ratio("azure", 0)
+    if res is not None:
+        azure_fail = int(res[0]["count"])
+    else:
+        azure_fail = 0
+
+
     aliyun_cnt = aliyun_success + aliyun_fail
     azure_cnt =  azure_success + azure_fail
     aliyun_ratio = round((aliyun_success/aliyun_cnt)*100,4)

+ 22 - 0
utils.py

@@ -290,7 +290,27 @@ def logs_tts_count(tts_channel, tts_status):
     else:
         if res.body:
             return  res.body
+def logs_tts_ratio(tts_channel, tts_status):
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-monitor'
+    logstore = 'monitor-log'
 
+    topic = ""
+    end_time = int(time.time())
+    start_time = end_time - 300
+    print(start_time, end_time)
+    req = GetLogsRequest(project, logstore, start_time, end_time,  topic,
+                         "* and __topic__: producetts and channel:{} and  produceStatus:{}| select channel,produceStatus,count(*) as count group by channel,produceStatus".format(tts_channel, tts_status) , 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        avgs = 0
+    else:
+        if res.body:
+            return  res.body
 
 
 def  count_recommend_null():
@@ -618,3 +638,5 @@ def  produce_video_ratio_cnt():
 
 
 # if __name__ == '__main__':
+#     res = logs_tts_ratio("aliyun",1)
+#     print(res)