(request, test_id)
return JsonResponse(data, safe=False)
Return monitoring data for some test and server
Return monitoring data for some test and server
Return monitoring data for some test and server
def server_monitoring_data(request, test_id):
    '''Return monitoring data for some test and server'''
    data = []
    if request.method == 'POST':
        server_id = request.POST.get('server_id', '0')
        metric = request.POST.get('metric', '0')
        source = request.POST.get('source', '0')

        min_timestamp = ServerMonitoringData.objects. \
            filter(test_id=test_id, server_id=server_id, source=source). \
            values("test_id"). \
            aggregate(min_timestamp=Min(
                RawSQL("((data->>%s)::timestamp)",
                      ('timestamp',))))['min_timestamp']

        if metric == 'CPU_all':
            metric_mapping = {
                metric:
                RawSQL("(((data->>%s)::numeric)+((data->>%s)::numeric)+"
                       "((data->>%s)::numeric))", (
                           'CPU_iowait',
                           'CPU_user',
                           'CPU_system',
                       ))
            }
        else:
            metric_mapping = {
                metric: RawSQL("((data->>%s)::numeric)", (metric, ))
            }
        x = ServerMonitoringData.objects. \
            filter(test_id=test_id, server_id=server_id,
                   source=source, data_resolution_id=1). \
            annotate(timestamp=RawSQL("((data->>%s)::timestamp)",
                    ('timestamp',)) - min_timestamp).\
            annotate(**metric_mapping). \
            values('timestamp', metric)
        data = json.loads(
            json.dumps(list(x), indent=4, sort_keys=True, default=str))
    return JsonResponse(data, safe=False)
def server_monitoring_data ( request , test_id ) : data = [ ] if request . method == 'POST' : server_id = request . POST . get ( 'server_id' , '0' ) metric = request . POST . get ( 'metric' , '0' ) source = request . POST . get ( 'source' , '0' ) min_timestamp = ServerMonitoringData . objects . filter ( test_id = test_id , server_id = server_id , source = source ) . values ( "test_id" ) . aggregate ( min_timestamp = Min ( RawSQL ( "((data->>%s)::timestamp)" , ( 'timestamp' , ) ) ) ) [ 'min_timestamp' ] if metric == 'CPU_all' : metric_mapping = { metric : RawSQL ( "(((data->>%s)::numeric)+((data->>%s)::numeric)+" "((data->>%s)::numeric))" , ( 'CPU_iowait' , 'CPU_user' , 'CPU_system' , ) ) } else : metric_mapping = { metric : RawSQL ( "((data->>%s)::numeric)" , ( metric , ) ) } x = ServerMonitoringData . objects . filter ( test_id = test_id , server_id = server_id , source = source , data_resolution_id = 1 ) . annotate ( timestamp = RawSQL ( "((data->>%s)::timestamp)" , ( 'timestamp' , ) ) - min_timestamp ) . annotate ( * * metric_mapping ) . values ( 'timestamp' , metric ) data = json . loads ( json . dumps ( list ( x ) , indent = 4 , sort_keys = True , default = str ) ) return JsonResponse ( data , safe = False )