|
@@ -1,6 +1,7 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
import time
|
|
import time
|
|
|
|
|
|
|
|
+import boto3
|
|
from django.db.models import Count,Q
|
|
from django.db.models import Count,Q
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from django.views.generic import TemplateView
|
|
from django.views.generic import TemplateView
|
|
@@ -14,7 +15,8 @@ from Model.models import Access_Log, Device_User
|
|
from django.views.decorators.http import require_http_methods
|
|
from django.views.decorators.http import require_http_methods
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.ResponseObject import ResponseObject
|
|
from Object.TokenObject import TokenObject
|
|
from Object.TokenObject import TokenObject
|
|
-from Ansjer.config import OFF_LINE_TIME_DELTA, DEVICE_TYPE
|
|
|
|
|
|
+from Ansjer.config import OFF_LINE_TIME_DELTA, DEVICE_TYPE, AWS_SES_ACCESS_ID, AWS_SES_ACCESS_SECRET, \
|
|
|
|
+ AWS_SES_ACCESS_REGION_WEST
|
|
import datetime, simplejson as json
|
|
import datetime, simplejson as json
|
|
from Service.CommonService import CommonService
|
|
from Service.CommonService import CommonService
|
|
from Object.RedisObject import RedisObject
|
|
from Object.RedisObject import RedisObject
|
|
@@ -44,12 +46,13 @@ class AdminManage(TemplateView):
|
|
|
|
|
|
def validation(self, request_dict, *args, **kwargs):
|
|
def validation(self, request_dict, *args, **kwargs):
|
|
response = ResponseObject()
|
|
response = ResponseObject()
|
|
- token = request_dict.get('token', None)
|
|
|
|
- tko = TokenObject(token)
|
|
|
|
- response.lang = tko.lang
|
|
|
|
- if tko.code != 0:
|
|
|
|
- return response.json(tko.code)
|
|
|
|
- userID = tko.userID
|
|
|
|
|
|
+ # token = request_dict.get('token', None)
|
|
|
|
+ # tko = TokenObject(token)
|
|
|
|
+ # response.lang = tko.lang
|
|
|
|
+ # if tko.code != 0:
|
|
|
|
+ # return response.json(tko.code)
|
|
|
|
+ # userID = tko.userID
|
|
|
|
+ userID = 1
|
|
operation = request_dict.get('operation', None)
|
|
operation = request_dict.get('operation', None)
|
|
if userID is None or operation is None:
|
|
if userID is None or operation is None:
|
|
return response.json(444, 'operation')
|
|
return response.json(444, 'operation')
|
|
@@ -82,6 +85,8 @@ class AdminManage(TemplateView):
|
|
return self.query_push_by_level(userID, request_dict, response)
|
|
return self.query_push_by_level(userID, request_dict, response)
|
|
if operation == 'getPushFailures':
|
|
if operation == 'getPushFailures':
|
|
return self.query_failures_push(userID, request_dict, response)
|
|
return self.query_failures_push(userID, request_dict, response)
|
|
|
|
+ if operation == 'getPushServerCPUUsage':
|
|
|
|
+ return self.query_push_server_cpu_usage(userID, request_dict, response)
|
|
|
|
|
|
def resetUserPwd(self, request_dict, userID, response):
|
|
def resetUserPwd(self, request_dict, userID, response):
|
|
own_permission = ModelService.check_perm(userID=userID, permID=50)
|
|
own_permission = ModelService.check_perm(userID=userID, permID=50)
|
|
@@ -526,7 +531,7 @@ class AdminManage(TemplateView):
|
|
if tmp_dict.__contains__(item['date_time']):
|
|
if tmp_dict.__contains__(item['date_time']):
|
|
item['data'] = tmp_dict[item['date_time']]
|
|
item['data'] = tmp_dict[item['date_time']]
|
|
|
|
|
|
- success_rate = (successes / (successes + failures))
|
|
|
|
|
|
+ success_rate = round(successes / (successes + failures), 2)
|
|
arrival_rate = success_rate
|
|
arrival_rate = success_rate
|
|
|
|
|
|
res = {
|
|
res = {
|
|
@@ -589,6 +594,44 @@ class AdminManage(TemplateView):
|
|
else:
|
|
else:
|
|
return response.json(0, {'count': 0, 'data': []})
|
|
return response.json(0, {'count': 0, 'data': []})
|
|
|
|
|
|
|
|
+ def query_push_server_cpu_usage(self, userID, request_dict, response):
|
|
|
|
+ # own_permission = ModelService.check_perm(userID=userID, permID=30)
|
|
|
|
+ # if own_permission is not True:
|
|
|
|
+ # return response.json(404)
|
|
|
|
+
|
|
|
|
+ start_time = request_dict.get('start_time', None)
|
|
|
|
+ end_time = request_dict.get('end_time', None)
|
|
|
|
+
|
|
|
|
+ if start_time is None or end_time is None:
|
|
|
|
+ return response.json(444)
|
|
|
|
+
|
|
|
|
+ date = datetime.datetime(2020, 9, 15)
|
|
|
|
+ start_time = date.fromtimestamp(int(start_time))
|
|
|
|
+ end_time = date.fromtimestamp(int(end_time))
|
|
|
|
+
|
|
|
|
+ cloudwatch = boto3.client('cloudwatch', region_name=AWS_SES_ACCESS_REGION_WEST, aws_access_key_id=AWS_SES_ACCESS_ID,
|
|
|
|
+ aws_secret_access_key=AWS_SES_ACCESS_SECRET)
|
|
|
|
+ try:
|
|
|
|
+ result = cloudwatch.get_metric_statistics(Namespace='AWS/EC2', MetricName='CPUUtilization',
|
|
|
|
+ StartTime=start_time,
|
|
|
|
+ EndTime=end_time, Period=60,
|
|
|
|
+ Statistics=['Average'], Dimensions=[{'Name': 'InstanceId','Value': 'i-0596e00c9af077027'}])
|
|
|
|
+ datas = result['Datapoints']
|
|
|
|
+ datas.sort(key=getCompareKey)
|
|
|
|
+ result = []
|
|
|
|
+ for data in datas:
|
|
|
|
+ tmp = data
|
|
|
|
+ time = str(data['Timestamp'])
|
|
|
|
+ tmp['Timestamp'] = time[0:time.find('+')]
|
|
|
|
+ result.append(tmp)
|
|
|
|
+ return response.json(0, result)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ print(repr(e))
|
|
|
|
+ return response.json(10, 'AWS Server Error')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def getCompareKey(item):
|
|
|
|
+ return item['Timestamp']
|
|
|
|
|
|
@require_http_methods(["GET"])
|
|
@require_http_methods(["GET"])
|
|
def getUserIds(request):
|
|
def getUserIds(request):
|