test.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. from flask import Flask
  2. import pycurl
  3. from io import StringIO
  4. import time
  5. from DBSession import session_maker
  6. from model import InstanceList
  7. app = Flask(__name__)
  8. from utils import *
  9. def test():
  10. return ipaddr
  11. def h5_curl():
  12. c = pycurl.Curl()
  13. c.setopt(pycurl.URL, "https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=/")
  14. c.setopt(pycurl.HTTPHEADER, ["Accept:"])
  15. c.setopt(pycurl.WRITEFUNCTION, StringIO.write)
  16. c.setopt(pycurl.FOLLOWLOCATION, 1)
  17. c.setopt(pycurl.MAXREDIRS, 5)
  18. c.perform()
  19. info = c.getinfo(pycurl.INFO_FILETIME)
  20. print(info)
  21. def requesl_url_list(apptype):
  22. endpoint = 'cn-hangzhou.log.aliyuncs.com'
  23. accessKeyId = 'LTAIWYUujJAm7CbH'
  24. accessKey = 'RfSjdiWwED1sGFlsjXv0DlfTnZTG1P'
  25. logstore = 'request-log'
  26. client = LogClient(endpoint, accessKeyId, accessKey)
  27. project = 'wqsd-longvideoapi'
  28. topic = ""
  29. start_time = int(time.time())
  30. end_time = start_time - 86400
  31. # url = '/longvideoapi/user/idolsUpdated'
  32. req = GetLogsRequest(project, logstore, end_time, start_time, topic,
  33. "params.appType=%s | select requestUri group by requestUri " %(apptype), 30, 0, False)
  34. res = client.get_logs(req)
  35. return res
  36. def produce_video_data():
  37. start_time = (int(time.strftime("%Y%m%d%H%M", time.localtime())) - 30) * 100000000000
  38. end_time = (int(time.strftime("%Y%m%d%H%M", time.localtime()))) * 100000000000
  39. sum_sql = ("select count(*) as totalCount from"
  40. "(select t1.project_id, t1.produce_status "
  41. "from produce_video_project t1 "
  42. "left join produce_video_project_connect_time t2 on t1.project_id = t2.project_id "
  43. " 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)
  44. )
  45. def all_metric():
  46. """视频合成类metrics"""
  47. """视频合成成功率"""
  48. time_stamp = int(time.time())
  49. end_time = int(datetime.datetime.fromtimestamp(time_stamp).strftime('%Y%m%d%H%M%S')) * 1000000000
  50. start_time = int(datetime.datetime.fromtimestamp(time_stamp-300).strftime('%Y%m%d%H%M%S')) * 1000000000
  51. print(start_time, end_time)
  52. query_sql = ("select totalCount , (successCount+processingCount1), round((successCount + processingCount1)/totalCount * 100,2) from "
  53. "(select count(*) as totalCount,"
  54. "sum(case when produce_status in (5,6,7,8) then 1 else 0 end) as successCount,"
  55. "sum(case when produce_status = 99 then 1 else 0 end) as failCount , "
  56. "sum(case when produce_status in(0,1,2,3,4) then 1 else 0 end) as processingCount,"
  57. "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,"
  58. "sum(case when produce_status in(0,1,2,3,4) and rate >= 0.7 then 1 else 0 end) processingCount2 from "
  59. "(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 "
  60. "left join produce_video_project_connect_time t2 on t1.project_id = t2.project_id "
  61. "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)
  62. )
  63. res = db_query(query_sql)
  64. if res[0] is not None:
  65. total_cnt = res[0]
  66. else:
  67. total_cnt = 0
  68. if res[1] is not None:
  69. success_cnt = res[1]
  70. else:
  71. success_cnt = 0
  72. if total_cnt == 0:
  73. rate = 100
  74. else:
  75. rate = round((success_cnt / total_cnt) ,2)* 100
  76. # produce_video_task_rate.labels("produce_video_task_rate").set(rate)
  77. # produce_video_task_total.labels('total_cnt').set(total_cnt)
  78. # produce_video_task_sucess.labels('success_cnt').set(success_cnt)
  79. print(total_cnt,success_cnt,rate)
  80. if __name__ == '__main__':
  81. # with session_maker() as session:
  82. # instance_info = session.query(InstanceList).filter(InstanceList.status==0).all()
  83. # for index in range(len(instance_info)):
  84. # print( instance_info[index].ipadd)
  85. HOST = 'rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com'
  86. PORT = '3306'
  87. DATABASE = 'devops'
  88. USERNAME = 'devops'
  89. PASSWORD = 'devops@123456'
  90. conn = pymysql.connect(host=HOST, user=USERNAME, password=PASSWORD, database=DATABASE, charset="utf8")
  91. cursor = conn.cursor()
  92. requestUri_list = [
  93. '/longvideoapi/sys/config',
  94. '/longvideoapi/video/played',
  95. '/longvideoapi/video/shared/weixin/friend',
  96. '/longvideoapi/user/login/v2',
  97. '/longvideoapi/user/info/getUserInfoExt',
  98. '/longvideoapi/user/token/check',
  99. '/longvideoapi/user/token/refresh',
  100. '/longvideoapi/user/info/homepageHead',
  101. '/longvideoapi/user/share/homepage/circle',
  102. '/longvideoapi/user/idols',
  103. '/longvideoapi/user/fans',
  104. '/longvideoapi/user/recommend/list/v4',
  105. '/longvideoapi/user/outside/subscribeBatch',
  106. '/longvideoapi/user/info/getBaseUserInfo',
  107. '/longvideoapi/user/info/getTargetBaseUserInfo',
  108. '/longvideoapi/user/getWxUserInfoByCode',
  109. '/longvideoapi/user/follow',
  110. '/longvideoapi/user/unfollow',
  111. '/longvideoapi/video/favorite',
  112. '/longvideoapi/video/unfavorite',
  113. '/longvideoapi/video/shared/weixin/circle',
  114. '/longvideoapi/videoCollection/loadUserVideoCollections',
  115. '/longvideoapi/video/v2/sharePage/queryVideosByCollectionId',
  116. '/longvideoapi/video/v2/detailPage/queryVideosByCollectionId',
  117. '/longvideoapi/videoCollection/loadUserVideoCollectionsForShareOrDetailPage',
  118. '/longvideoapi/video/distribute/getAppInfo',
  119. '/longvideoapi/video/distribute/category/videoList/v2',
  120. '/longvideoapi/video/v2/followed',
  121. '/longvideoapi/video/v2/loadHotVideosByCollectionId',
  122. '/longvideoapi/video/v2/loadLatelyVideosByCollectionId',
  123. '/longvideoapi/video/v2/detail',
  124. '/longvideoapi/video/v2/sharePageDetail',
  125. '/longvideoapi/video/send',
  126. '/longvideoapi/video/getCoverImagePaths',
  127. '/longvideoapi/video/updateVideo',
  128. '/longvideoapi/video/deleteVideo',
  129. '/longvideoapi/video/barrage/send',
  130. '/longvideoapi/video/barrage/switch',
  131. '/longvideoapi/video/videoActionReport',
  132. '/longvideoapi/video/barrage/v2/list',
  133. '/longvideoapi/video/shared/h5"',
  134. '/longvideoapi/user/share/report',
  135. '/longvideoapi/oss/signature',
  136. '/longvideoapi/oss/completeUpload',
  137. '/longvideoapi/oss/producevideo/getStsToken',
  138. '/longvideoapi/operate/message/list',
  139. '/longvideoapi/video/message/list',
  140. '/longvideoapi/sys/message/list',
  141. '/longvideoapi/user/station/message/statistics/info',
  142. '/longvideoapi/user/station/message/statistics/read',
  143. '/longvideoapi/user/station/message/totalCount/v2',
  144. '/longvideoapi/user/station/message/totalRead',
  145. '/longvideoapi/user/station/notice/list',
  146. '/longvideoapi/user/station/message/share/list',
  147. '/longvideoapi/user/station/message/prise/list',
  148. '/longvideoapi/user/station/message/favorite/list',
  149. '/longvideoapi/user/station/message/comment/list',
  150. '/longvideoapi/user/station/message/barrage/list',
  151. '/longvideoapi/operation/message/list',
  152. '/longvideoapi/search/userandvideo/list',
  153. '/longvideoapi/search/tips',
  154. '/longvideoapi/search/user/list',
  155. '/longvideoapi/search/video/list',
  156. '/longvideoapi/search/hot/words',
  157. '/longvideoapi/search/hot/videos',
  158. '/longvideoapi/video/distribute/search/recommendVideoes/v2',
  159. '/longvideoapi/comment/top/save',
  160. '/longvideoapi/comment/top/page',
  161. '/longvideoapi/comment/praise',
  162. '/longvideoapi/comment/second/save',
  163. '/longvideoapi/comment/second/page',
  164. '/longvideoapi/comment/delete',
  165. '/longvideoapi/comment/updelete',
  166. '/longvideoapi/comment/hots',
  167. '/longvideoapi/bank/withdraw/getBankWithdrawConfig',
  168. '/longvideoapi/bank/withdraw/getBankWithdrawRecordList',
  169. '/longvideoapi/bank/withdraw/wxSamllapp/requestWithdraw',
  170. '/longvideoapi/purchase/video/list',
  171. '/longvideoapi/profits/myself/head',
  172. '/longvideoapi/profits/myself/list',
  173. '/longvideoapi/profits/myself/recordList/v2',
  174. '/longvideoapi/profits/reward/recordListAccordingToUser',
  175. '/longvideoapi/profits/reward/recordListAccordingToVideo',
  176. '/longvideoapi/video/reward/getVideoRewardHeadInfo',
  177. '/longvideoapi/video/reward/getVideoRewardRecordList',
  178. '/longvideoapi/video/reward/getVideoRewardConfig',
  179. '/longvideoapi/video/reward/getVideoRewardConfig/v2',
  180. '/longvideoapi/order/updateClientPayStatus',
  181. '/longvideoapi/order/purchase',
  182. '/longvideoapi/profits/videoPay/head',
  183. '/longvideoapi/profits/videoPay/list',
  184. '/longvideoapi/video/getPayedVideoPath',
  185. '/longvideoapi/order/reward',
  186. '/longvideoapi/video/reward/getVideoDetailRewardInfo',
  187. '/longvideoapi/video/recommend/detailPage/list',
  188. '/longvideoapi/video/recommend/sharePage/list',
  189. '/longvideoapi/measure/report/view',
  190. '/longvideoapi/video/validatePwd"',
  191. '/longvideoapi/video/validatePwdAuth"',
  192. '/longvideoapi/video/v2/getCutVideo',
  193. '/longvideoapi/frontConfig/getWxFrontConfig',
  194. '/longvideoapi/frontConfig/getVideoPlayConfig',
  195. '/longvideoapi/frontConfig/getUserFrontConfig',
  196. '/longvideoapi/rhythmapp/homepage/getAllVideos',
  197. '/longvideoapi/ad/position/info'
  198. ]
  199. # for i in range(len(instance_info["Instances"]["Instance"])):
  200. # instance_id = instance_info["Instances"]["Instance"][i]["InstanceId"]
  201. # ipaddr = instance_info["Instances"]["Instance"][i]["VpcAttributes"]["PrivateIpAddress"]["IpAddress"][0]
  202. # server_name = instance_info["Instances"]["Instance"][i]["Tags"]["Tag"][0]["TagValue"]
  203. # status = instance_info["Instances"]["Instance"][i]["Status"]
  204. # instance_name = instance_info["Instances"]["Instance"][i]["HostName"]
  205. # if status == "running":
  206. # # status = 1
  207. # for url in requestUri_list:
  208. # sql = "UPDATE `reuqest_url_list` set `level`=0 WHERE `request_url` ='%s' and `apptype` in (1,13)"%(url)
  209. # cursor.execute(sql)
  210. # conn.commit()
  211. # #
  212. # c = pycurl.Curl()
  213. # c.setopt(pycurl.URL, "https://longvideoh5.piaoquantv.com/core/share?shareSource=customerMessage&fromAppType=0&qrAppType=0&versionCode=321&shareUid=12463024&shareMachineCode=weixin_openid_o0w175fPwp8yrtOGihYJhvnT9Ag4&h5WxrootPageSource=vlog-pages___category&videoId=2689415&isRecommendShare=1&h5ShareId=backend493cd67dd28f4ee395781d59881567211625976055926&shareDepth=0&state=/")
  214. # c.setopt(pycurl.HTTPHEADER, ["Accept:"])
  215. # b = StringIO.StringIO()
  216. # c.setopt(pycurl.WRITEFUNCTION, b.write)
  217. # c.setopt(pycurl.FOLLOWLOCATION, 1)
  218. # c.setopt(pycurl.MAXREDIRS, 5)
  219. # c.perform()
  220. #
  221. #
  222. # info = c.getinfo(pycurl.INFO_FILETIME)
  223. #
  224. # print(info)
  225. # with open("/t3.txt", "r") as f: # 打开文件
  226. # data = f.read() # 读取文件
  227. # # print(data)
  228. # 20210716000000000111111
  229. # 20210726200800000000000
  230. # start_time = int(time.strftime("%Y%m%d%H%M", time.localtime())) * 100000000000
  231. # end_time = (int(time.strftime("%Y%m%d%H%M", time.localtime())) + 5) * 100000000000
  232. # print(start_time , end_time)
  233. #
  234. # appType = ['0', '4', '5', '6', '12' ,'15','1','13']
  235. #
  236. # #
  237. # for index in range(len(appType)):
  238. # type = appType[index]
  239. # # res = requesl_url_list(type)
  240. # # for i in range(len(res.body)):
  241. # # url = res.body[i]["requestUri"]
  242. # # sql = "insert into `reuqest_url_list` (`apptype`, `request_url`) VALUES (%s, '%s')"%(type, url)
  243. # # print(sql)
  244. # # cursor.execute(sql)
  245. # # conn.commit()
  246. #
  247. #
  248. #
  249. # res = count_avg_max(type)
  250. # for i in range(len(res.body)):
  251. # url = res.body[i]["requestUri"]
  252. # cnt = res.body[i]["cnt"]
  253. # max_time = res.body[i]["max_time"]
  254. # avg_time = res.body[i]["avg_time"]
  255. # sql = "UPDATE `reuqest_url_list` set `qps`=%s, `max_time`=%s, `avg_time`=%s WHERE `request_url` ='%s' and `apptype`=%s"%(cnt, max_time, avg_time, url, type)
  256. # cursor.execute(sql)
  257. # conn.commit()
  258. # for i in range(len(res.body)):
  259. # url = res.body[i]["requestUri"]
  260. # cnt = res.body[i]["cnt"]
  261. # sql = "UPDATE `reuqest_url_list` set `rt_1`=%s WHERE `request_url` ='%s' and `apptype`=%s"%(cnt, url, type)
  262. # cursor.execute(sql)
  263. # conn.commit()
  264. #
  265. # res = count_rt_less_time_count(type, 200, 500)
  266. # for i in range(len(res.body)):
  267. # url = res.body[i]["requestUri"]
  268. # cnt = res.body[i]["cnt"]
  269. # sql = "UPDATE `reuqest_url_list` set `rt_2`=%s WHERE `request_url` ='%s' and `apptype`=%s" % (cnt, url, type)
  270. # cursor.execute(sql)
  271. # conn.commit()
  272. #
  273. # res = count_rt_less_time_count(type, 500, 1000)
  274. # for i in range(len(res.body)):
  275. # url = res.body[i]["requestUri"]
  276. # cnt = res.body[i]["cnt"]
  277. # sql = "UPDATE `reuqest_url_list` set `rt_3`=%s WHERE `request_url` ='%s' and `apptype`=%s" % (cnt, url, type)
  278. # cursor.execute(sql)
  279. # conn.commit()
  280. #
  281. # res = count_rt_less_time_count(type, 1000, 10000)
  282. # for i in range(len(res.body)):
  283. # url = res.body[i]["requestUri"]
  284. # cnt = res.body[i]["cnt"]
  285. # sql = "UPDATE `reuqest_url_list` set `rt_4`=%s WHERE `request_url` ='%s' and `apptype`=%s" % (cnt, url, type)
  286. # cursor.execute(sql)
  287. # conn.commit()
  288. #
  289. #
  290. # start_time = int(time.strftime("%Y%m%d%H%M", time.localtime())) * 100000000000
  291. # end_time = (int(time.strftime("%Y%m%d%H%M", time.localtime())) + 5) * 100000000000
  292. # query_sql = ("select round((successCount + processingCount1)/totalCount * 100,2) from "
  293. # "(select count(*) as totalCount,"
  294. # "sum(case when produce_status in (5,6,7,8) then 1 else 0 end) as successCount,"
  295. # "sum(case when produce_status = 99 then 1 else 0 end) as failCount , "
  296. # "sum(case when produce_status in(0,1,2,3,4) then 1 else 0 end) as processingCount,"
  297. # "sum(case when produce_status in(0,1,2,3,4) and (rate < 1 or rate is null) then 1 else 0 end) processingCount1,"
  298. # "sum(case when produce_status in(0,1,2,3,4) and rate >= 1 then 1 else 0 end) processingCount2 from "
  299. # "(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 "
  300. # "left join produce_video_project_connect_time t2 on t1.project_id = t2.project_id "
  301. # "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)
  302. #
  303. # )
  304. # res = db_query(query_sql)
  305. #
  306. # if res[0] is not None:
  307. # print(res[0])
  308. time_stamp = int(time.time())
  309. end_time = int(datetime.datetime.fromtimestamp(time_stamp).strftime('%Y%m%d%H%M%S')) * 1000000000
  310. start_time = int(datetime.datetime.fromtimestamp(time_stamp-300).strftime('%Y%m%d%H%M%S')) * 1000000000
  311. # rt - 300
  312. print(start_time, end_time)
  313. all_metric()