|
@@ -286,7 +286,7 @@ class oa2RtspStartView(TemplateView):
|
|
|
'pwd':PWD,
|
|
|
'msg':MSG
|
|
|
}
|
|
|
- redisObj.set_data(key=key, val=str(res_json), expire=30)
|
|
|
+ redisObj.set_data(key=key, val=str(res_json), expire=15)
|
|
|
return JsonResponse(res_json, safe=False)
|
|
|
else:
|
|
|
return JsonResponse({'msg': 'wrong'})
|
|
@@ -458,11 +458,149 @@ def testRunStream(request):
|
|
|
def test(request):
|
|
|
return JsonResponse({'msg': 'Server running normal', 'code': 0})
|
|
|
|
|
|
-#压测负载均衡接口
|
|
|
+#test接口
|
|
|
def loadBalancingServer(request):
|
|
|
- res = requests.get('http://rtsp.zositech.xyz:10008/api/v1/players')
|
|
|
- return JsonResponse({'msg': res, 'code': 0})
|
|
|
- # return JsonResponse({'msg': 'tesring', 'code': 0})
|
|
|
+ try:
|
|
|
+ res1 = requests.get('http://rtsp.zositech.org:10008/api/v1/players', timeout=0.001)
|
|
|
+ except Exception as e:
|
|
|
+ res1 = "server error"
|
|
|
+ print(res1)
|
|
|
+ #res2 = requests.get('http://18.222.107.129:10008/api/v1/players', timeout=0.001)
|
|
|
+ print("res1请求时间:%s"%res1)
|
|
|
+ # print("res2请求时间:%s"%res2)
|
|
|
+ # rtsp = 'rtsp.zositech.xyz'
|
|
|
+ # rtsp1 = 'rtsp.zositech.org'
|
|
|
+ # rtsp2 = 'rtsp.zositech.org'
|
|
|
+ # RD = RedisObject(db=9)
|
|
|
+ # # #国内
|
|
|
+ # key = 'CHINA'
|
|
|
+ # # #国外1
|
|
|
+ # key1 = 'USA1'
|
|
|
+ # # #国外2
|
|
|
+ # key2 = 'USA2'
|
|
|
+ # total = RD.get_data(key=key)
|
|
|
+ # total1 = RD.get_data(key=key1)
|
|
|
+ # total2 = RD.get_data(key=key2)
|
|
|
+ from datetime import datetime
|
|
|
+ # res1 = requests.get('http://rtsp.zositech.org:10008/api/v1/players')
|
|
|
+ # time3=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ # print("时间3:%s"%time3)
|
|
|
+ # res2 = requests.get('http://18.222.107.129:10008/api/v1/players')
|
|
|
+ # time4=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ # print("时间4:%s"%time4)
|
|
|
+ # res_data1 = res1.json()
|
|
|
+ # res_data2 = res1.json()
|
|
|
+ # total1 = res_data1['total']
|
|
|
+ # total2 = res_data2['total']
|
|
|
+ # RD.set_data()
|
|
|
+ # mm=min(total,total1)
|
|
|
+ # print(mm)
|
|
|
+ # if total1 == mm:
|
|
|
+ # return JsonResponse({'msg': rtsp1, 'code': 0})
|
|
|
+ # else:
|
|
|
+ # return JsonResponse({'msg': rtsp2, 'code': 0})
|
|
|
+
|
|
|
+ # RD = RedisObject(db=9)
|
|
|
+ # rtsp = 'rtsp.zositech.xyz'
|
|
|
+ # rtsp1 = 'rtsp.zositech.org'
|
|
|
+ # rtsp2 = 'rtsp.zositech.org'
|
|
|
+ # print("1")
|
|
|
+ # #国内
|
|
|
+ # key = 'CHINA'
|
|
|
+ # #国外1
|
|
|
+ # key1 = 'USA1'
|
|
|
+ # #国外2
|
|
|
+ # key2 = 'USA2'
|
|
|
+ # total = RD.get_data(key=key)
|
|
|
+ # total1 = RD.get_data(key=key1)
|
|
|
+ # total2 = RD.get_data(key=key2)
|
|
|
+ # print("2")
|
|
|
+ # #读缓存判断在线人数,返回人少的服务器ip
|
|
|
+ # if total:
|
|
|
+ # print("进缓存了")
|
|
|
+ # mm = min(total,total1,total2)
|
|
|
+ # if total == mm:
|
|
|
+ # return JsonResponse({'msg': rtsp, 'code': 0})
|
|
|
+ # elif total1 == mm:
|
|
|
+ # return JsonResponse({'msg': rtsp1, 'code': 0})
|
|
|
+ # else:
|
|
|
+ # return JsonResponse({'msg': rtsp2, 'code': 0})
|
|
|
+ # print("3")
|
|
|
+ # from datetime import datetime
|
|
|
+ # time1=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ # print("时间1:%s"%time1)
|
|
|
+ # res = requests.get('http://rtsp.zositech.xyz:10008/api/v1/players')
|
|
|
+ # time2=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ # print("时间2:%s"%time2)
|
|
|
+ # res1 = requests.get('http://rtsp.zositech.org:10008/api/v1/players')
|
|
|
+ # time3=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ # print("时间3:%s"%time3)
|
|
|
+ # res2 = requests.get('http://18.222.107.129:10008/api/v1/players')
|
|
|
+ # time4=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ # print("时间4:%s"%time4)
|
|
|
+ # res_data = res.json()
|
|
|
+ # res_data1 = res1.json()
|
|
|
+ # res_data2 = res2.json()
|
|
|
+ # total = res_data['total']
|
|
|
+ # total1 = res_data1['total']
|
|
|
+ # total2 = res_data2['total']
|
|
|
+ # #redis存内容
|
|
|
+ # RD.set_data(key=key, val=total, expire=10)
|
|
|
+ # RD.set_data(key=key1, val=total1, expire=10)
|
|
|
+ # RD.set_data(key=key2, val=total2, expire=10)
|
|
|
+ # print("4")
|
|
|
+ # mm=min(total,total1,total2)
|
|
|
+ # if total == mm:
|
|
|
+ # return JsonResponse({'msg': rtsp, 'code': 0})
|
|
|
+ # elif total1 == mm:
|
|
|
+ # return JsonResponse({'msg': rtsp1, 'code': 0})
|
|
|
+ # else:
|
|
|
+ # return JsonResponse({'msg': rtsp2, 'code': 0})
|
|
|
+ #
|
|
|
+ try:
|
|
|
+ res1 = requests.get('http://rtsp.zositech.org:10008/api/v1/players', timeout=5)
|
|
|
+ except Exception as e:
|
|
|
+ res1 = -1
|
|
|
+
|
|
|
+ time1=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ print("时间1:%s"%time1)
|
|
|
+ # ---------压测接口demo------------
|
|
|
+ redisObj8 = RedisObject(db=8)
|
|
|
+ key1 = 'USA'
|
|
|
+ key2 = 'USA1'
|
|
|
+ redis_data1 = redisObj8.get_data(key1)
|
|
|
+ redis_data2 = redisObj8.get_data(key2)
|
|
|
+ if redis_data1 and redis_data2:
|
|
|
+ print("进缓存")
|
|
|
+ mm=min(redis_data1,redis_data2)
|
|
|
+ if redis_data1 == mm and redis_data1 != -1:
|
|
|
+ RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN']
|
|
|
+ elif redis_data2 == mm and redis_data2 != -1:
|
|
|
+ RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN1']
|
|
|
+ #return JsonResponse({'msg': RESP_SERVER_DOMAIN, 'code': 0})
|
|
|
+ # ---------/压测demo------------
|
|
|
+ else:
|
|
|
+ print("第一次")
|
|
|
+ res1 = requests.get('http://rtsp.zositech.org:10008/api/v1/players', timeout=0.001)
|
|
|
+ res2 = requests.get('http://18.222.107.129:10008/api/v1/players', timeout=0.001)
|
|
|
+ res_data1 = res1.json()
|
|
|
+ res_data2 = res1.json()
|
|
|
+ total1 = res_data1['total']
|
|
|
+ total2 = res_data2['total']
|
|
|
+ print(total1)
|
|
|
+ print(total2)
|
|
|
+ redisObj8.set_data(key=key1, val=total1, expire=30)
|
|
|
+ redisObj8.set_data(key=key2, val=total2, expire=30)
|
|
|
+ mm=min(total1,total2)
|
|
|
+ print(mm)
|
|
|
+ if total1 == mm:
|
|
|
+ RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN']
|
|
|
+ else:
|
|
|
+ RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN1']
|
|
|
+ time1=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
|
+ print("时间1:%s"%time1)
|
|
|
+ return JsonResponse({'msg': 'The number of people online is :%s'%res1, 'code': 0})
|
|
|
+
|
|
|
|
|
|
|
|
|
|