|
@@ -223,10 +223,25 @@ class oa2RtspStartView(TemplateView):
|
|
stream_name = ur_qs[0]['rtsp_url']
|
|
stream_name = ur_qs[0]['rtsp_url']
|
|
nick = ur_qs[0]['nick']
|
|
nick = ur_qs[0]['nick']
|
|
#RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA[region]
|
|
#RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA[region]
|
|
- RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['CN']
|
|
|
|
- #RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN']
|
|
|
|
- #rtsp://rtsp.zositech.xyz:443/elNGWlVURXRHU2swMlMwUlVRVVk1U2pFeE1VRT1M
|
|
|
|
|
|
+ # RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['CN']
|
|
|
|
+ RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN']
|
|
|
|
+
|
|
|
|
+ #如果是美国,则进行负载均衡
|
|
|
|
+ # if RESP_SERVER_DOMAIN == RESP_SERVER_DOMAIN_DATA['EN']:
|
|
|
|
+ # redisObj1 = RedisObject(db=1)
|
|
|
|
+ # key1 = 'rtsp.zositech.org'
|
|
|
|
+ # key2 = '18.222.107.129'
|
|
|
|
+ # redis_data1 = redisObj1.get_data(key1)
|
|
|
|
+ # redis_data2 = redisObj1.get_data(key2)
|
|
|
|
+ # 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']
|
|
#E
|
|
#E
|
|
|
|
+ #固定rtspServer,不采用负载均衡
|
|
|
|
+ RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN']
|
|
|
|
+
|
|
MSG = '{RTSP_PREFIX}://{RESP_SERVER_DOMAIN}:{PORT_PREFIX}/{stream_name}'. \
|
|
MSG = '{RTSP_PREFIX}://{RESP_SERVER_DOMAIN}:{PORT_PREFIX}/{stream_name}'. \
|
|
format(RESP_SERVER_DOMAIN=RESP_SERVER_DOMAIN,
|
|
format(RESP_SERVER_DOMAIN=RESP_SERVER_DOMAIN,
|
|
stream_name=stream_name,
|
|
stream_name=stream_name,
|
|
@@ -460,103 +475,6 @@ def test(request):
|
|
|
|
|
|
#test接口
|
|
#test接口
|
|
def loadBalancingServer(request):
|
|
def loadBalancingServer(request):
|
|
- 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:
|
|
try:
|
|
res1 = requests.get('http://rtsp.zositech.org:10008/api/v1/players', timeout=5)
|
|
res1 = requests.get('http://rtsp.zositech.org:10008/api/v1/players', timeout=5)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
@@ -565,11 +483,11 @@ def loadBalancingServer(request):
|
|
time1=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
time1=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
|
|
print("时间1:%s"%time1)
|
|
print("时间1:%s"%time1)
|
|
# ---------压测接口demo------------
|
|
# ---------压测接口demo------------
|
|
- redisObj8 = RedisObject(db=8)
|
|
|
|
- key1 = 'USA'
|
|
|
|
- key2 = 'USA1'
|
|
|
|
- redis_data1 = redisObj8.get_data(key1)
|
|
|
|
- redis_data2 = redisObj8.get_data(key2)
|
|
|
|
|
|
+ redisObj = RedisObject(db=1)
|
|
|
|
+ key1 = 'rtsp.zositech.org'
|
|
|
|
+ key2 = '18.222.107.129'
|
|
|
|
+ redis_data1 = redisObj.get_data(key1)
|
|
|
|
+ redis_data2 = redisObj.get_data(key2)
|
|
if redis_data1 and redis_data2:
|
|
if redis_data1 and redis_data2:
|
|
print("进缓存")
|
|
print("进缓存")
|
|
mm=min(redis_data1,redis_data2)
|
|
mm=min(redis_data1,redis_data2)
|
|
@@ -577,28 +495,25 @@ def loadBalancingServer(request):
|
|
RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN']
|
|
RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN']
|
|
elif redis_data2 == mm and redis_data2 != -1:
|
|
elif redis_data2 == mm and redis_data2 != -1:
|
|
RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN1']
|
|
RESP_SERVER_DOMAIN = RESP_SERVER_DOMAIN_DATA['EN1']
|
|
- #return JsonResponse({'msg': RESP_SERVER_DOMAIN, 'code': 0})
|
|
|
|
# ---------/压测demo------------
|
|
# ---------/压测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)
|
|
|
|
|
|
+ # 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']
|
|
return JsonResponse({'msg': 'The number of people online is :%s'%res1, 'code': 0})
|
|
return JsonResponse({'msg': 'The number of people online is :%s'%res1, 'code': 0})
|
|
|
|
|
|
|
|
|