test.py 15 KB

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