瀏覽代碼

增加app首页接口数据采集

panwang 3 年之前
父節點
當前提交
3222652a62
共有 4 個文件被更改,包括 30 次插入3 次删除
  1. 二進制
      __pycache__/app.cpython-37.pyc
  2. 二進制
      __pycache__/utils.cpython-37.pyc
  3. 9 2
      app.py
  4. 21 1
      utils.py

二進制
__pycache__/app.cpython-37.pyc


二進制
__pycache__/utils.cpython-37.pyc


+ 9 - 2
app.py

@@ -194,7 +194,7 @@ def all_metric():
         #     produce_video_task_rate.labels("produce_video_task_rate").set(0)
         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
-        sql = "select  round(successCount/totalCount * 100,2) as 成功率 from  (select count(*) as totalCount, sum(case when produce_status != 99 then 1 else 0 end) as successCount from produce_video_project where project_id > {} and project_id < {} and app_type not in (13,15)) t1".format(start_time, end_time)
+        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])
@@ -288,13 +288,18 @@ def all_metric():
     return Response(generate_latest(registry), mimetype="text/plain")
 @app.route('/qps_avgtime/metrics')
 def qps_avgtime_metrics():
+    res, url = app_openapi_qps_avgtime_count()
+    qps =  int(res.body[0]["cnt"])
+    avgtime = int(float(res.body[0]["avg_time"]))
+    app_type_temp = 1
+    url_http_qps.labels(app_type_temp, url).set(qps)
+    url_http_avgtime.labels(app_type_temp, url).set(avgtime)
     app_type = ['1', '0', '4', '5', '6', '12', '13']
     for i in range(len(app_type)):
         appType = app_type[i]
         res = count_qps_avgtime(appType)
         for i in range(len(res.body)):
             url = res.body[i]["requestUri"]
-
             qps = int(res.body[i]["cnt"])
             avgtime = int(float(res.body[i]["avg_time"]))
             url_http_qps.labels(appType, url).set(qps)
@@ -324,6 +329,8 @@ def qps_avgtime_metrics():
             count = res.body[i]["cnt"]
             url_http_expendtime_summary.labels(appType, url, ">1000").set(count)
 
+
+
     return Response(generate_latest(registry), mimetype="text/plain")
 
 

+ 21 - 1
utils.py

@@ -316,6 +316,26 @@ def  count_rt_less_time_count(appType, than, less):
 
     return  res
 
+def app_openapi_qps_avgtime_count():
+    endpoint = 'cn-hangzhou.log.aliyuncs.com'
+    accessKeyId = 'LTAIWYUujJAm7CbH'
+    accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
+    logstore = 'request-log'
+    client = LogClient(endpoint, accessKeyId, accessKey)
+    project = 'wqsd-longvideoapi'
+    topic = ""
+    start_time = int(time.time())
+    end_time = start_time - 60
+    url = '/longvideoapi/openapi/video/distribute/category/videoList/v2'
+    req = GetLogsRequest(project, logstore, end_time, start_time, topic,
+                         "requestUri=%s| select requestUri,count(1) as cnt  , avg(expendTime)  as avg_time group by requestUri  order by requestUri,cnt desc limit  1000"%(url) , 30, 0, False)
+    try:
+        res = client.get_logs(req)
+    except Exception as e:
+        avgs = 0
+
+    return  res,url
+
 
 
 if __name__ == '__main__':
@@ -353,5 +373,5 @@ if __name__ == '__main__':
     #     avgtime = round(float(res.body[i]["avg_time"]), 2)
     #     print(url,qps ,avgtime)
 
-    res = count_rt_less_time_count(0, 1000, 10000)
+    res = app_openapi_qps_avgtime_count()
     print(res.body)