Пример #1
0
def findPerfStatics(request):

    counter_name = 'cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name = request.GET['counter_name']
    if request.POST.has_key('counter_name'):
        counter_name = request.POST['counter_name']
    print counter_name
    #paging prepare
    page = 1
    if request.GET.has_key('page'):
        page = request.GET['page']
    if request.POST.has_key('page'):
        page = request.POST['page']
    rows = 10
    if request.GET.has_key('rows'):
        rows = request.GET['rows']
    if request.POST.has_key('rows'):
        rows = request.POST['rows']

    str = '2016-01-11'
    timestamp = datetime.datetime.strptime(str, '%Y-%m-%d')
    # counter_name='cpu_util'

    #get record count
    count = MongoEngineUtil.findStaticsCountByTimestampAndCounter_name(
        timestamp, counter_name)
    staticsList = MongoEngineUtil.findLimitStaticsByTimestampAndCounter_name(
        timestamp, counter_name, 10)
    perfList = []
    tmpStat = {}
    for stat in staticsList:
        tmpStat['resource_name'] = stat.resource_id.resource_name
        tmpStat['counter_name'] = stat.counter_name
        tmpStat['counter_name'] = stat.counter_name
        tmpStat['resource_id'] = stat.resource_id.id
        tmpStat['timestamp'] = datetime.datetime.strftime(
            stat.timestamp, '%Y-%m-%d %H:%M:%S')
        tmpStat['avg'] = stat.avg
        tmpStat['unit'] = stat.unit
        tmpStat['count'] = stat.count
        tmpStat['max'] = stat.max
        tmpStat['user_id'] = stat.user_id
        tmpStat['val'] = stat.val
        tmpStat['min'] = stat.min
        tmpStat['sum'] = stat.sum
        tmpStat['period_start'] = datetime.datetime.strftime(
            stat.period_start, '%Y-%m-%d %H:%M:%S')
        tmpStat['period_end'] = datetime.datetime.strftime(
            stat.period_end, '%Y-%m-%d %H:%M:%S')
        perfList.append(tmpStat)
        tmpStat = {}
    result = {}
    result["total"] = count
    result["rows"] = perfList
    # print(json.dumps(result))
    return HttpResponse(json.dumps(result))
Пример #2
0
def findPerfStatics(request):

    counter_name='cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name=request.GET['counter_name'];
    if   request.POST.has_key('counter_name'):
        counter_name=request.POST['counter_name'];
    print counter_name
    #paging prepare
    page=1
    if request.GET.has_key('page'):
        page=request.GET['page'];
    if   request.POST.has_key('page'):
        page=request.POST['page'];
    rows=10
    if request.GET.has_key('rows'):
        rows=request.GET['rows'];
    if   request.POST.has_key('rows'):
        rows=request.POST['rows'];


    str = '2016-01-11'
    timestamp = datetime.datetime.strptime(str,'%Y-%m-%d')
    # counter_name='cpu_util'

    #get record count
    count=MongoEngineUtil.findStaticsCountByTimestampAndCounter_name(timestamp,counter_name)
    staticsList=MongoEngineUtil.findLimitStaticsByTimestampAndCounter_name(timestamp,counter_name,10)
    perfList=[]
    tmpStat={}
    for stat in staticsList:
        tmpStat['resource_name']=stat.resource_id.resource_name
        tmpStat['counter_name']=stat.counter_name
        tmpStat['counter_name']=stat.counter_name
        tmpStat['resource_id']=stat.resource_id.id
        tmpStat['timestamp']=datetime.datetime.strftime(stat.timestamp,'%Y-%m-%d %H:%M:%S')
        tmpStat['avg']=stat.avg
        tmpStat['unit']=stat.unit
        tmpStat['count']=stat.count
        tmpStat['max']=stat.max
        tmpStat['user_id']=stat.user_id
        tmpStat['val']=stat.val
        tmpStat['min']=stat.min
        tmpStat['sum']=stat.sum
        tmpStat['period_start']=datetime.datetime.strftime(stat.period_start,'%Y-%m-%d %H:%M:%S')
        tmpStat['period_end']=datetime.datetime.strftime(stat.period_end,'%Y-%m-%d %H:%M:%S')
        perfList.append(tmpStat)
        tmpStat={}
    result={}
    result["total"]=count;
    result["rows"]=perfList;
    # print(json.dumps(result))
    return HttpResponse(json.dumps(result))
Пример #3
0
def perf_searchVolumeStatic(request):
    resource_id = ''
    if request.GET.has_key('resource_id'):
        resource_id = request.GET['resource_id']
    if request.POST.has_key('resource_id'):
        resource_id = request.POST['resource_id']

    counter_name = 'cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name = request.GET['counter_name']
    if request.POST.has_key('counter_name'):
        counter_name = request.POST['counter_name']

    print(counter_name)

    tmpDate = DateTimeUtil.dayBefore(7)

    result = {}
    catagories = []
    series = []
    tmpMax = {}
    tmpMaxList = []
    # tmpMin={}
    # tmpMinList=[]
    # tmpAvg={}
    # tmpAvgList=[]

    #find volumes by instanceid
    volumeList = volumes.objects.all().using('cinder').filter(
        instance_uuid=resource_id)

    print(volumeList)
    tmpVolumeIds = []
    for vol in volumeList:
        tmpVolumeIds.append(vol.id)

    statList = MongoEngineUtil.findStaticsByTimestampAndCounter_nameAndResourceId(
        tmpDate, counter_name, tmpVolumeIds)
    for stat in statList:
        str = DateTimeUtil.datetime_toString(stat.timestamp, "%Y-%m-%d")
        catagories.append(str)
        tmpMaxList.append(stat.max)

    tmpMax['data'] = tmpMaxList
    tmpMax['type'] = 'line'
    tmpMax['name'] = 'max'
    series.append(tmpMax)

    result['categories'] = catagories
    result['series'] = series

    # print(staticsList)
    return HttpResponse(json.dumps(result))
Пример #4
0
def perf_searchVolumeStatic(request):
    resource_id=''
    if request.GET.has_key('resource_id'):
        resource_id=request.GET['resource_id'];
    if   request.POST.has_key('resource_id'):
        resource_id=request.POST['resource_id'];

    counter_name='cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name=request.GET['counter_name'];
    if   request.POST.has_key('counter_name'):
        counter_name=request.POST['counter_name'];

    print(counter_name)

    tmpDate=DateTimeUtil.dayBefore(7);

    result={}
    catagories=[]
    series=[]
    tmpMax={}
    tmpMaxList=[]
    # tmpMin={}
    # tmpMinList=[]
    # tmpAvg={}
    # tmpAvgList=[]

    #find volumes by instanceid
    volumeList=volumes.objects.all().using('cinder').filter(instance_uuid=resource_id)

    print(volumeList)
    tmpVolumeIds=[]
    for vol in volumeList:
        tmpVolumeIds.append(vol.id)

    statList=MongoEngineUtil.findStaticsByTimestampAndCounter_nameAndResourceId(tmpDate,counter_name,tmpVolumeIds)
    for stat in statList:
        str=DateTimeUtil.datetime_toString(stat.timestamp,"%Y-%m-%d")
        catagories.append(str)
        tmpMaxList.append(stat.max)

    tmpMax['data']=tmpMaxList
    tmpMax['type']='line'
    tmpMax['name']='max'
    series.append(tmpMax)

    result['categories']=catagories
    result['series']=series


    # print(staticsList)
    return HttpResponse(json.dumps(result))
Пример #5
0
def perf_searchNetworkStatic(request):
    resource_id = ''
    if request.GET.has_key('resource_id'):
        resource_id = request.GET['resource_id']
    if request.POST.has_key('resource_id'):
        resource_id = request.POST['resource_id']

    counter_name = 'cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name = request.GET['counter_name']
    if request.POST.has_key('counter_name'):
        counter_name = request.POST['counter_name']

    print(counter_name)

    tmpDate = DateTimeUtil.dayBefore(7)

    result = {}
    catagories = []
    series = []
    tmpMax = {}
    tmpMaxList = []
    # tmpMin={}
    # tmpMinList=[]
    # tmpAvg={}
    # tmpAvgList=[]

    statList = MongoEngineUtil.findNetworkStaticsByTimestampAndCounter_nameAndResourceId(
        tmpDate, counter_name, resource_id)
    for stat in statList:
        str = DateTimeUtil.datetime_toString(stat.timestamp, "%Y-%m-%d")
        catagories.append(str)
        tmpMaxList.append(stat.max)

    tmpMax['data'] = tmpMaxList
    tmpMax['type'] = 'line'
    tmpMax['name'] = 'max'
    series.append(tmpMax)

    result['categories'] = catagories
    result['series'] = series

    # print(staticsList)
    return HttpResponse(json.dumps(result))
Пример #6
0
def perf_searchNetworkStatic(request):
    resource_id=''
    if request.GET.has_key('resource_id'):
        resource_id=request.GET['resource_id'];
    if   request.POST.has_key('resource_id'):
        resource_id=request.POST['resource_id'];

    counter_name='cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name=request.GET['counter_name'];
    if   request.POST.has_key('counter_name'):
        counter_name=request.POST['counter_name'];

    print(counter_name)

    tmpDate=DateTimeUtil.dayBefore(7);

    result={}
    catagories=[]
    series=[]
    tmpMax={}
    tmpMaxList=[]
    # tmpMin={}
    # tmpMinList=[]
    # tmpAvg={}
    # tmpAvgList=[]

    statList=MongoEngineUtil.findNetworkStaticsByTimestampAndCounter_nameAndResourceId(tmpDate,counter_name,resource_id)
    for stat in statList:
        str=DateTimeUtil.datetime_toString(stat.timestamp,"%Y-%m-%d")
        catagories.append(str)
        tmpMaxList.append(stat.max)

    tmpMax['data']=tmpMaxList
    tmpMax['type']='line'
    tmpMax['name']='max'
    series.append(tmpMax)

    result['categories']=catagories
    result['series']=series


    # print(staticsList)
    return HttpResponse(json.dumps(result))
Пример #7
0
def perf_searchStaticByVm(request):
    resource_id = ''
    if request.GET.has_key('resource_id'):
        resource_id = request.GET['resource_id']
    if request.POST.has_key('resource_id'):
        resource_id = request.POST['resource_id']

    print(resource_id)

    tmpDate = DateTimeUtil.dayBefore(7)

    counter_name = 'cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name = request.GET['counter_name']
    if request.POST.has_key('counter_name'):
        counter_name = request.POST['counter_name']

    print(counter_name)

    #staticsList=mongoUtil.findStaticsByTimestampAndCounter_name(timestamp,counter_name,0,10)
    # staticsList=mongoUtil.findLimitStaticsByTimestampAndCounter_name(timestamp,counter_name,1)

    # resource_id='7dcc77ae-6bc6-44fe-a24b-f6580f9fcce1'
    # res=MongoEngineUtil.findResourcesById('7dcc77ae-6bc6-44fe-a24b-f6580f9fcce1')
    # print(res)
    resList = [resource_id]
    staticsList = MongoEngineUtil.findStaticsByTimestampAndCounter_nameAndResourceId(
        tmpDate, counter_name, resList)

    result = {}
    catagories = []
    series = []
    tmpMax = {}
    tmpMaxList = []
    tmpMin = {}
    tmpMinList = []
    tmpAvg = {}
    tmpAvgList = []

    for stat in staticsList:
        str = DateTimeUtil.datetime_toString(stat.timestamp, "%Y-%m-%d")
        catagories.append(str)
        tmpMaxList.append(stat.max)
        tmpMinList.append(stat.min)
        tmpAvgList.append(stat.avg)
    tmpMax['data'] = tmpMaxList
    tmpMax['type'] = 'line'
    tmpMax['name'] = 'max'

    tmpMin['data'] = tmpMinList
    tmpMin['type'] = 'line'
    tmpMin['name'] = 'min'

    tmpAvg['data'] = tmpAvgList
    tmpAvg['type'] = 'line'
    tmpAvg['name'] = 'avg'

    series.append(tmpMax)
    series.append(tmpMin)
    series.append(tmpAvg)

    # result['legends']=['ggg']
    # result['categories']=[1,2,3]
    # result['series']=[55,2,45]
    # for stat in staticsList:

    result['categories'] = catagories
    result['series'] = series

    # print(staticsList)
    return HttpResponse(json.dumps(result))
Пример #8
0
def perf_searchStaticByVm(request):
    resource_id=''
    if request.GET.has_key('resource_id'):
        resource_id=request.GET['resource_id'];
    if   request.POST.has_key('resource_id'):
        resource_id=request.POST['resource_id'];

    print(resource_id)

    tmpDate=DateTimeUtil.dayBefore(7);

    counter_name='cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name=request.GET['counter_name'];
    if   request.POST.has_key('counter_name'):
        counter_name=request.POST['counter_name'];

    print(counter_name)

    #staticsList=mongoUtil.findStaticsByTimestampAndCounter_name(timestamp,counter_name,0,10)
    # staticsList=mongoUtil.findLimitStaticsByTimestampAndCounter_name(timestamp,counter_name,1)

    # resource_id='7dcc77ae-6bc6-44fe-a24b-f6580f9fcce1'
    # res=MongoEngineUtil.findResourcesById('7dcc77ae-6bc6-44fe-a24b-f6580f9fcce1')
    # print(res)
    resList=[resource_id]
    staticsList=MongoEngineUtil.findStaticsByTimestampAndCounter_nameAndResourceId(tmpDate,counter_name,resList)

    result={}
    catagories=[]
    series=[]
    tmpMax={}
    tmpMaxList=[]
    tmpMin={}
    tmpMinList=[]
    tmpAvg={}
    tmpAvgList=[]

    for stat in staticsList:
        str=DateTimeUtil.datetime_toString(stat.timestamp,"%Y-%m-%d")
        catagories.append(str)
        tmpMaxList.append(stat.max)
        tmpMinList.append(stat.min)
        tmpAvgList.append(stat.avg)
    tmpMax['data']=tmpMaxList
    tmpMax['type']='line'
    tmpMax['name']='max'

    tmpMin['data']=tmpMinList
    tmpMin['type']='line'
    tmpMin['name']='min'

    tmpAvg['data']=tmpAvgList
    tmpAvg['type']='line'
    tmpAvg['name']='avg'

    series.append(tmpMax)
    series.append(tmpMin)
    series.append(tmpAvg)



    # result['legends']=['ggg']
    # result['categories']=[1,2,3]
    # result['series']=[55,2,45]
    # for stat in staticsList:

    result['categories']=catagories
    result['series']=series


    # print(staticsList)
    return HttpResponse(json.dumps(result))
Пример #9
0
def findTopPerfStatics(request):

    tmpDate=DateTimeUtil.dayBefore(7);
    str=DateTimeUtil.datetime_toString(tmpDate,"%Y-%m-%d")

    bdt=str
    if request.GET.has_key('bdt'):
        bdt=request.GET['bdt'];
    if   request.POST.has_key('bdt'):
        bdt=request.POST['bdt'];


    edt=str
    if request.GET.has_key('edt'):
        edt=request.GET['edt'];
    if   request.POST.has_key('edt'):
        edt=request.POST['edt'];


    counter_name='cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name=request.GET['counter_name'];
    if   request.POST.has_key('counter_name'):
        counter_name=request.POST['counter_name'];

    order='aesc'
    if request.GET.has_key('order'):
        order=request.GET['order'];
    if   request.POST.has_key('order'):
        order=request.POST['order'];

    sortby='avg'
    if request.GET.has_key('sortby'):
        sortby=request.GET['sortby'];
    if   request.POST.has_key('sortby'):
        sortby=request.POST['sortby'];

    limit=10
    if request.GET.has_key('limit'):
        limit=request.GET['limit'];
    if   request.POST.has_key('limit'):
        limit=request.POST['limit'];


    print counter_name
    print order
    print sortby
    print limit


    # str = '2016-01-11'
    bdtime = datetime.datetime.strptime(bdt,'%Y-%m-%d')
    edtime = datetime.datetime.strptime(edt,'%Y-%m-%d')


    #get record count
    staticsList=MongoEngineUtil.findLimitStaticsByTimestampAndCounter_name(bdtime,edtime,counter_name,int(limit),order,sortby)
    perfList=[]
    tmpStat={}
    for stat in staticsList:


        #counter name is network.incoming.bytes.rate
        # instance-0000322e-3f6c30d6-e029-49c6-ab20-aa502fdbe557-tape7c7968e-bf
        uuid = stat.resource_id
        if counter_name.__contains__('network'):
            uuid=stat.resource_id[18:54]
        elif counter_name.__contains__('volume'):
            volList=volumes.objects.all().using('cinder').filter(id=stat.resource_id)
            if volList:
                uuid=volList[0].instance_uuid

        # print(uuid)
        res=MongoEngineUtil.findResourcesById(uuid)
        #get instance info
        insList=instances.objects.all().filter(uuid=uuid)
        if insList:
            tmpStat['vm_state']=insList[0].vm_state
            tmpStat['launched_at']=insList[0].launched_at
            tmpStat['scheduled_at']=insList[0].scheduled_at
            tmpStat['terminated_at']=insList[0].terminated_at
            tmpStat['vcpus']=insList[0].vcpus
            tmpStat['memory_mb']=insList[0].memory_mb
            tmpStat['host']=insList[0].host
            tmpStat['root_gb']=insList[0].root_gb

            image=images.objects.all().using('glance').filter(id=insList[0].image_ref)
            print(image)
            if image:
                tmpStat['image']=image[0].name
            else:
                tmpStat['image']='null'


            proList=project.objects.all().using('keystone').filter(id=insList[0].project_id)
            if proList:
                tmpStat['project_name']=proList[0].name

        tmpStat['resource_name']=res.resource_name
        tmpStat['counter_name']=stat.counter_name
        tmpStat['counter_name']=stat.counter_name
        tmpStat['resource_id']=stat.resource_id
        tmpStat['timestamp']=datetime.datetime.strftime(stat.timestamp,'%Y-%m-%d %H:%M:%S')
        tmpStat['avg']=stat.avg
        tmpStat['unit']=stat.unit
        tmpStat['count']=stat.count
        tmpStat['max']=stat.max
        tmpStat['user_id']=stat.user_id
        tmpStat['val']=stat.val
        tmpStat['min']=stat.min
        tmpStat['sum']=stat.sum
        tmpStat['period_start']=datetime.datetime.strftime(stat.period_start,'%Y-%m-%d %H:%M:%S')
        tmpStat['period_end']=datetime.datetime.strftime(stat.period_end,'%Y-%m-%d %H:%M:%S')
        perfList.append(tmpStat)
        tmpStat={}
    result={}
    result["total"]=result.__len__();
    result["rows"]=perfList;

    # print(json.dumps(result))
    return HttpResponse(json.dumps(result,cls = DateTimeEncoder))
Пример #10
0
def findTopPerfStatics(request):

    tmpDate = DateTimeUtil.dayBefore(7)
    str = DateTimeUtil.datetime_toString(tmpDate, "%Y-%m-%d")

    bdt = str
    if request.GET.has_key('bdt'):
        bdt = request.GET['bdt']
    if request.POST.has_key('bdt'):
        bdt = request.POST['bdt']

    edt = str
    if request.GET.has_key('edt'):
        edt = request.GET['edt']
    if request.POST.has_key('edt'):
        edt = request.POST['edt']

    counter_name = 'cpu_util'
    if request.GET.has_key('counter_name'):
        counter_name = request.GET['counter_name']
    if request.POST.has_key('counter_name'):
        counter_name = request.POST['counter_name']

    order = 'aesc'
    if request.GET.has_key('order'):
        order = request.GET['order']
    if request.POST.has_key('order'):
        order = request.POST['order']

    sortby = 'avg'
    if request.GET.has_key('sortby'):
        sortby = request.GET['sortby']
    if request.POST.has_key('sortby'):
        sortby = request.POST['sortby']

    limit = 10
    if request.GET.has_key('limit'):
        limit = request.GET['limit']
    if request.POST.has_key('limit'):
        limit = request.POST['limit']

    print counter_name
    print order
    print sortby
    print limit

    # str = '2016-01-11'
    bdtime = datetime.datetime.strptime(bdt, '%Y-%m-%d')
    edtime = datetime.datetime.strptime(edt, '%Y-%m-%d')

    #get record count
    staticsList = MongoEngineUtil.findLimitStaticsByTimestampAndCounter_name(
        bdtime, edtime, counter_name, int(limit), order, sortby)
    perfList = []
    tmpStat = {}
    for stat in staticsList:

        #counter name is network.incoming.bytes.rate
        # instance-0000322e-3f6c30d6-e029-49c6-ab20-aa502fdbe557-tape7c7968e-bf
        uuid = stat.resource_id
        if counter_name.__contains__('network'):
            uuid = stat.resource_id[18:54]
        elif counter_name.__contains__('volume'):
            volList = volumes.objects.all().using('cinder').filter(
                id=stat.resource_id)
            if volList:
                uuid = volList[0].instance_uuid

        # print(uuid)
        res = MongoEngineUtil.findResourcesById(uuid)
        #get instance info
        insList = instances.objects.all().filter(uuid=uuid)
        if insList:
            tmpStat['vm_state'] = insList[0].vm_state
            tmpStat['launched_at'] = insList[0].launched_at
            tmpStat['scheduled_at'] = insList[0].scheduled_at
            tmpStat['terminated_at'] = insList[0].terminated_at
            tmpStat['vcpus'] = insList[0].vcpus
            tmpStat['memory_mb'] = insList[0].memory_mb
            tmpStat['host'] = insList[0].host
            tmpStat['root_gb'] = insList[0].root_gb

            image = images.objects.all().using('glance').filter(
                id=insList[0].image_ref)
            print(image)
            if image:
                tmpStat['image'] = image[0].name
            else:
                tmpStat['image'] = 'null'

            proList = project.objects.all().using('keystone').filter(
                id=insList[0].project_id)
            if proList:
                tmpStat['project_name'] = proList[0].name

        tmpStat['resource_name'] = res.resource_name
        tmpStat['counter_name'] = stat.counter_name
        tmpStat['counter_name'] = stat.counter_name
        tmpStat['resource_id'] = stat.resource_id
        tmpStat['timestamp'] = datetime.datetime.strftime(
            stat.timestamp, '%Y-%m-%d %H:%M:%S')
        tmpStat['avg'] = stat.avg
        tmpStat['unit'] = stat.unit
        tmpStat['count'] = stat.count
        tmpStat['max'] = stat.max
        tmpStat['user_id'] = stat.user_id
        tmpStat['val'] = stat.val
        tmpStat['min'] = stat.min
        tmpStat['sum'] = stat.sum
        tmpStat['period_start'] = datetime.datetime.strftime(
            stat.period_start, '%Y-%m-%d %H:%M:%S')
        tmpStat['period_end'] = datetime.datetime.strftime(
            stat.period_end, '%Y-%m-%d %H:%M:%S')
        perfList.append(tmpStat)
        tmpStat = {}
    result = {}
    result["total"] = result.__len__()
    result["rows"] = perfList

    # print(json.dumps(result))
    return HttpResponse(json.dumps(result, cls=DateTimeEncoder))