test.py 15 KB

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