Exemple #1
0
 def getThreadInfoByResourceId(resourceId, jumper_server):
     innerIP = UsingInstancesDBUtil.getUsingInstanceInnerIPById(resourceId)
     url = jumper_server + "/getSpecificThreadInfo?ip=" + str(innerIP)
     req = urllib2.Request(url)
     # TODO: retry mechanism might be added later
     infos = eval(urllib2.urlopen(req).read())
     # here simplify the model since our instance must has single cpu
     freq = infos[0][2]  # format => [[thread, freqStandard, freqReal]...]
     util = SampleUtil.getCpuUtilPeriodAVGByResourceId(resourceId)
     return {"cal": 1.0 * freq * util, "util": util}
Exemple #2
0
    def getThreadInfo(self, req):
        tarId = req.params.get('id')

        if not tarId:
            return errorResultJson('Please pass id!')

        if PMAndAZDBUtil.isPMId(tarId):
            tarIP = PMAndAZDBUtil.getInnerIPByPMId(tarId)
            if not tarIP:
                return errorResultJson(tarId + ' cannot be found')

            os.system('/home/sk/cloudEx/shellScript/getThreadInfo.sh ' + tarIP.split('.')[-1] + ' > /dev/null')

            df = open('/home/sk/cloudEx/tmpData/threadInfo.data')
            info = df.read()
            df.close()

        else:
            tarIP = UsingInstancesDBUtil.getUsingInstanceInnerIPById(tarId)

            if not tarIP:
                return errorResultJson(tarId + ' cannot be found')

            params = urllib.urlencode({'ip': tarIP})
            headers = {"Content-type": "application/x-www-form-urlencoded",
                       "Accept": "text/plain"}
            httpClient = httplib.HTTPConnection("202.120.40.20", 50020, timeout=300)
            httpClient.request("POST", "/getSpecificThreadInfo", params, headers)
            response = httpClient.getresponse()
            info = response.read()
            httpClient.close()

        infoList = eval(info)
        res = []
        for item in infoList:
            res.append({'thread_cnt': item[0], 'standard_freq': item[1], 'current_freq': item[2]})

        return res
Exemple #3
0
    def getPMOrVMUtil(self, req):
        tarId = req.params.get('id')
        periodNo = req.params.get('periodNo')

        if tarId and periodNo and isNumber(periodNo):
            periodNo = int(periodNo)

            # 是物理机
            if PMAndAZDBUtil.isPMId(tarId):
                # log
                cpuLogger.info('pmId:' + tarId + ' periodNo:' + str(periodNo))

                tarIP = PMAndAZDBUtil.getInnerIPByPMId(tarId)
                if not tarIP:
                    return errorResultJson(tarId + ' cannot be found')

                os.system('/home/sk/cloudEx/shellScript/getPMUtil.sh ' + tarIP.split('.')[-1] + ' > /dev/null')

                df = open('/home/sk/cloudEx/tmpData/result.data')
                line = df.readline()
                pmCPUUtil = round(float(line), 4) * 100
                df.close()

                if periodNo == 1:
                    PMCPUDBUtil.addFirstPeriodRealPMCPU(pmCPUUtil, tarId)
                else:
                    PMCPUDBUtil.addRealPMCPUToSpecificPeriod(periodNo, tarId, pmCPUUtil)

                addPMCPUUtilToPeriodicWindow(tarId, pmCPUUtil)
                ppi = PMCPUPredictUtil()
                pv = ppi.getNextPeriodWorkload(tarId)
                addPredictPMCPUUtilToPeriodicWindow(tarId, pv)

                PMCPUDBUtil.addPredictPMCPUToSpecificPeriod(periodNo + 1, pv, tarId)

            # 是虚拟机
            else:

                tarIP = UsingInstancesDBUtil.getUsingInstanceInnerIPById(tarId)

                # log
                cpuLogger.info('vmIP:' + tarIP + ' periodNo:' + str(periodNo))

                if not tarIP:
                    return errorResultJson(tarId + ' cannot be found')

                rv = round(SampleUtil.getCpuUtilPeriodAVGByResourceId(tarId), 2)

                if periodNo == 1:
                    VMCPUDBUtil.addFirstPeriodRealVMCPU(rv, tarIP)
                else:
                    VMCPUDBUtil.addRealVMCPUToSpecificPeriod(periodNo, rv, tarIP)

                addVMCPUUtilToPeriodicWindow(tarIP, rv)
                pvi = VMCPUPredictUtil()
                pv = pvi.getNextPeriodWorkload(tarIP)
                addPredictVMCPUUtilToPeriodicWindow(tarIP, pv)

                VMCPUDBUtil.addPredictVMCPUToSpecificPeriod(periodNo + 1, pv, tarIP)

            return {'util': pv}


        else:
            return errorResultJson('Please pass the vmId or pmId!')