test.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. if __name__ == '__main__':
  37. # with session_maker() as session:
  38. # instance_info = session.query(InstanceList).filter(InstanceList.status==0).all()
  39. # for index in range(len(instance_info)):
  40. # print( instance_info[index].ipadd)
  41. requestUri_list = [
  42. '/longvideoapi/sys/config',
  43. '/longvideoapi/video/played',
  44. '/longvideoapi/video/shared/weixin/friend',
  45. '/longvideoapi/user/login/v2',
  46. '/longvideoapi/user/info/getUserInfoExt',
  47. '/longvideoapi/user/token/check',
  48. '/longvideoapi/user/token/refresh',
  49. '/longvideoapi/user/info/homepageHead',
  50. '/longvideoapi/user/share/homepage/circle',
  51. '/longvideoapi/user/idols',
  52. '/longvideoapi/user/fans',
  53. '/longvideoapi/user/recommend/list/v4',
  54. '/longvideoapi/user/outside/subscribeBatch',
  55. '/longvideoapi/user/info/getBaseUserInfo',
  56. '/longvideoapi/user/info/getTargetBaseUserInfo',
  57. '/longvideoapi/user/getWxUserInfoByCode',
  58. '/longvideoapi/user/follow',
  59. '/longvideoapi/user/unfollow',
  60. '/longvideoapi/video/favorite',
  61. '/longvideoapi/video/unfavorite',
  62. '/longvideoapi/video/shared/weixin/circle',
  63. '/longvideoapi/videoCollection/loadUserVideoCollections',
  64. '/longvideoapi/video/v2/sharePage/queryVideosByCollectionId',
  65. '/longvideoapi/video/v2/detailPage/queryVideosByCollectionId',
  66. '/longvideoapi/videoCollection/loadUserVideoCollectionsForShareOrDetailPage',
  67. '/longvideoapi/video/distribute/getAppInfo',
  68. '/longvideoapi/video/distribute/category/videoList/v2',
  69. '/longvideoapi/video/v2/followed',
  70. '/longvideoapi/video/v2/loadHotVideosByCollectionId',
  71. '/longvideoapi/video/v2/loadLatelyVideosByCollectionId',
  72. '/longvideoapi/video/v2/detail',
  73. '/longvideoapi/video/v2/sharePageDetail',
  74. '/longvideoapi/video/send',
  75. '/longvideoapi/video/getCoverImagePaths',
  76. '/longvideoapi/video/updateVideo',
  77. '/longvideoapi/video/deleteVideo',
  78. '/longvideoapi/video/barrage/send',
  79. '/longvideoapi/video/barrage/switch',
  80. '/longvideoapi/video/videoActionReport',
  81. '/longvideoapi/video/barrage/v2/list',
  82. '/longvideoapi/video/shared/h5"',
  83. '/longvideoapi/user/share/report',
  84. '/longvideoapi/oss/signature',
  85. '/longvideoapi/oss/completeUpload',
  86. '/longvideoapi/oss/producevideo/getStsToken',
  87. '/longvideoapi/operate/message/list',
  88. '/longvideoapi/video/message/list',
  89. '/longvideoapi/sys/message/list',
  90. '/longvideoapi/user/station/message/statistics/info',
  91. '/longvideoapi/user/station/message/statistics/read',
  92. '/longvideoapi/user/station/message/totalCount/v2',
  93. '/longvideoapi/user/station/message/totalRead',
  94. '/longvideoapi/user/station/notice/list',
  95. '/longvideoapi/user/station/message/share/list',
  96. '/longvideoapi/user/station/message/prise/list',
  97. '/longvideoapi/user/station/message/favorite/list',
  98. '/longvideoapi/user/station/message/comment/list',
  99. '/longvideoapi/user/station/message/barrage/list',
  100. '/longvideoapi/operation/message/list',
  101. '/longvideoapi/search/userandvideo/list',
  102. '/longvideoapi/search/tips',
  103. '/longvideoapi/search/user/list',
  104. '/longvideoapi/search/video/list',
  105. '/longvideoapi/search/hot/words',
  106. '/longvideoapi/search/hot/videos',
  107. '/longvideoapi/video/distribute/search/recommendVideoes/v2',
  108. '/longvideoapi/comment/top/save',
  109. '/longvideoapi/comment/top/page',
  110. '/longvideoapi/comment/praise',
  111. '/longvideoapi/comment/second/save',
  112. '/longvideoapi/comment/second/page',
  113. '/longvideoapi/comment/delete',
  114. '/longvideoapi/comment/updelete',
  115. '/longvideoapi/comment/hots',
  116. '/longvideoapi/bank/withdraw/getBankWithdrawConfig',
  117. '/longvideoapi/bank/withdraw/getBankWithdrawRecordList',
  118. '/longvideoapi/bank/withdraw/wxSamllapp/requestWithdraw',
  119. '/longvideoapi/purchase/video/list',
  120. '/longvideoapi/profits/myself/head',
  121. '/longvideoapi/profits/myself/list',
  122. '/longvideoapi/profits/myself/recordList/v2',
  123. '/longvideoapi/profits/reward/recordListAccordingToUser',
  124. '/longvideoapi/profits/reward/recordListAccordingToVideo',
  125. '/longvideoapi/video/reward/getVideoRewardHeadInfo',
  126. '/longvideoapi/video/reward/getVideoRewardRecordList',
  127. '/longvideoapi/video/reward/getVideoRewardConfig',
  128. '/longvideoapi/video/reward/getVideoRewardConfig/v2',
  129. '/longvideoapi/order/updateClientPayStatus',
  130. '/longvideoapi/order/purchase',
  131. '/longvideoapi/profits/videoPay/head',
  132. '/longvideoapi/profits/videoPay/list',
  133. '/longvideoapi/video/getPayedVideoPath',
  134. '/longvideoapi/order/reward',
  135. '/longvideoapi/video/reward/getVideoDetailRewardInfo',
  136. '/longvideoapi/video/recommend/detailPage/list',
  137. '/longvideoapi/video/recommend/sharePage/list',
  138. '/longvideoapi/measure/report/view',
  139. '/longvideoapi/video/validatePwd"',
  140. '/longvideoapi/video/validatePwdAuth"',
  141. '/longvideoapi/video/v2/getCutVideo',
  142. '/longvideoapi/frontConfig/getWxFrontConfig',
  143. '/longvideoapi/frontConfig/getVideoPlayConfig',
  144. '/longvideoapi/frontConfig/getUserFrontConfig',
  145. '/longvideoapi/rhythmapp/homepage/getAllVideos',
  146. '/longvideoapi/ad/position/info'
  147. ]
  148. # for i in range(len(instance_info["Instances"]["Instance"])):
  149. # instance_id = instance_info["Instances"]["Instance"][i]["InstanceId"]
  150. # ipaddr = instance_info["Instances"]["Instance"][i]["VpcAttributes"]["PrivateIpAddress"]["IpAddress"][0]
  151. # server_name = instance_info["Instances"]["Instance"][i]["Tags"]["Tag"][0]["TagValue"]
  152. # status = instance_info["Instances"]["Instance"][i]["Status"]
  153. # instance_name = instance_info["Instances"]["Instance"][i]["HostName"]
  154. # if status == "running":
  155. # # status = 1
  156. # for url in requestUri_list:
  157. # IntfaceInfo = None
  158. # IntfaceInfo = IntfaceList()
  159. # with session_maker() as session:
  160. # IntfaceInfo.app_type = "1"
  161. # IntfaceInfo.interface_url = url
  162. # session.add(IntfaceInfo)
  163. # #
  164. # c = pycurl.Curl()
  165. # 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=/")
  166. # c.setopt(pycurl.HTTPHEADER, ["Accept:"])
  167. # b = StringIO.StringIO()
  168. # c.setopt(pycurl.WRITEFUNCTION, b.write)
  169. # c.setopt(pycurl.FOLLOWLOCATION, 1)
  170. # c.setopt(pycurl.MAXREDIRS, 5)
  171. # c.perform()
  172. #
  173. #
  174. # info = c.getinfo(pycurl.INFO_FILETIME)
  175. #
  176. # print(info)
  177. # with open("/t3.txt", "r") as f: # 打开文件
  178. # data = f.read() # 读取文件
  179. # # print(data)
  180. # 20210716000000000111111
  181. # 20210726200800000000000
  182. # start_time = int(time.strftime("%Y%m%d%H%M", time.localtime())) * 100000000000
  183. # end_time = (int(time.strftime("%Y%m%d%H%M", time.localtime())) + 5) * 100000000000
  184. # print(start_time , end_time)
  185. HOST = 'rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com'
  186. PORT = '3306'
  187. DATABASE = 'devops'
  188. USERNAME = 'devops'
  189. PASSWORD = 'devops@123456'
  190. conn = pymysql.connect(host=HOST, user=USERNAME, password=PASSWORD, database=DATABASE, charset="utf8")
  191. cursor = conn.cursor()
  192. appType = ['0', '4', '5', '6', '12' ,'15']
  193. for index in range(len(appType)):
  194. type = appType[index]
  195. res = count_avg_max(type)
  196. for i in range(len(res.body)):
  197. url = res.body[i]["requestUri"]
  198. cnt = res.body[i]["cnt"]
  199. max_time = res.body[i]["max_time"]
  200. avg_time = res.body[i]["avg_time"]
  201. 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)
  202. cursor.execute(sql)
  203. conn.commit()
  204. for i in range(len(res.body)):
  205. url = res.body[i]["requestUri"]
  206. cnt = res.body[i]["cnt"]
  207. sql = "UPDATE `reuqest_url_list` set `rt_1`=%s WHERE `request_url` ='%s' and `apptype`=%s"%(cnt, url, type)
  208. cursor.execute(sql)
  209. conn.commit()
  210. res = count_rt_less_time_count(type, 200, 500)
  211. for i in range(len(res.body)):
  212. url = res.body[i]["requestUri"]
  213. cnt = res.body[i]["cnt"]
  214. sql = "UPDATE `reuqest_url_list` set `rt_2`=%s WHERE `request_url` ='%s' and `apptype`=%s" % (cnt, url, type)
  215. cursor.execute(sql)
  216. conn.commit()
  217. res = count_rt_less_time_count(type, 500, 1000)
  218. for i in range(len(res.body)):
  219. url = res.body[i]["requestUri"]
  220. cnt = res.body[i]["cnt"]
  221. sql = "UPDATE `reuqest_url_list` set `rt_3`=%s WHERE `request_url` ='%s' and `apptype`=%s" % (cnt, url, type)
  222. cursor.execute(sql)
  223. conn.commit()
  224. res = count_rt_less_time_count(type, 1000, 10000)
  225. for i in range(len(res.body)):
  226. url = res.body[i]["requestUri"]
  227. cnt = res.body[i]["cnt"]
  228. sql = "UPDATE `reuqest_url_list` set `rt_4`=%s WHERE `request_url` ='%s' and `apptype`=%s" % (cnt, url, type)
  229. cursor.execute(sql)
  230. conn.commit()