Exemplo n.º 1
0
    def _createTestSystemPerformanceData(self):
        spd = SystemPerformanceData()
        spd.setName(self.DEFAULT_NAME)

        spd.setCpuUtilization(self.DEFAULT_CPU_UTIL_DATA)
        spd.setDiskUtilization(self.DEFAULT_DISK_UTIL_DATA)
        spd.setMemoryUtilization(self.DEFAULT_MEM_UTIL_DATA)

        return spd
Exemplo n.º 2
0
    def _createTestSystemPerformanceData(self):
        spd = SystemPerformanceData()
        spd.setName(self.DEFAULT_NAME)

        spd.setCpuUtilization(self.DEFAULT_CPU_UTIL_DATA)
        spd.setDiskUtilization(self.DEFAULT_DISK_UTIL_DATA)
        spd.setMemoryUtilization(self.DEFAULT_MEM_UTIL_DATA)

        logging.info("System perf data as string: " + str(spd))

        return spd
Exemplo n.º 3
0
    def testFullUpdate(self):
        spd = SystemPerformanceData()
        spd2 = self._createTestSystemPerformanceData()

        self.assertEquals(spd.getName(), ConfigConst.SYSTEM_PERF_NAME)

        self.assertEquals(spd.getCpuUtilization(), ConfigConst.DEFAULT_VAL)
        self.assertEquals(spd.getMemoryUtilization(), ConfigConst.DEFAULT_VAL)

        spd.updateData(spd2)

        self.assertEquals(spd.getName(), self.DEFAULT_NAME)

        self.assertEquals(spd.getCpuUtilization(), self.DEFAULT_CPU_UTIL_DATA)
        self.assertEquals(spd.getMemoryUtilization(),
                          self.DEFAULT_MEM_UTIL_DATA)
	def jsonToSystemPerformanceData(self, jsonData) -> SystemPerformanceData:
		"""
		Convert json string to SystemPerformanceData Instance
		:param jsonData: Given json string
		:return: Decoded SystemPerformanceData Instance
		"""
		sysPerDict: dict = json.loads(jsonData)
		sysPerData = SystemPerformanceData(d=sysPerDict)
		return sysPerData
    def _updateTelemetry(self):
        sysPerfVal = random.uniform(1.0, 50.0)
        tempVal = random.uniform(18.0, 22.0)

        sysPerfData = SystemPerformanceData()
        sysPerfData.setName("SystemPerfMsg")
        sysPerfData.setCpuUtilization(sysPerfVal)
        sysPerfData.setDiskUtilization(sysPerfVal)
        sysPerfData.setMemoryUtilization(sysPerfData)

        # Uncomment the next SLOC to trigger data message listener callback for perf data
        #self.dataMsgListener.handleSystemPerformanceMessage(sysPerfData)

        sensorData = SensorData()
        sensorData.setName(ConfigConst.TEMP_SENSOR_NAME)
        sensorData.setValue(tempVal)

        self.dataMsgListener.handleSensorMessage(sensorData)
Exemplo n.º 6
0
	def testDefaultValues(self):
		spd = SystemPerformanceData()
		
		self.assertEquals(spd.getName(), ConfigConst.SYS_PERF_DATA)
		self.assertEquals(spd.getStatusCode(), SystemPerformanceData.DEFAULT_STATUS)
		
		self.assertEquals(spd.getCpuUtilization(), SystemPerformanceData.DEFAULT_VAL)
		self.assertEquals(spd.getDiskUtilization(), SystemPerformanceData.DEFAULT_VAL)
		self.assertEquals(spd.getMemoryUtilization(), SystemPerformanceData.DEFAULT_VAL)
	def testWriteSystemPerformanceDataToCdaDataPath(self):
		logging.info("\n\n----- [SystemPerformanceData to JSON to file] -----")
		
		dataObj  = SystemPerformanceData()
		dataStr  = self.dataUtil.sensorDataToJson(dataObj)
		fileName = self.cdaDataPath + '/SystemPerformanceData.dat'

		logging.info("Sample SystemPerformanceData JSON (validated): " + str(dataStr))
		logging.info("Writing SystemPerformanceData JSON to CDA data path: " + fileName)
		
		fileRef = Path(fileName)
		fileRef.write_text(dataStr, encoding = 'utf-8')
Exemplo n.º 8
0
	def handleTelemetry(self):
		"""
		Call getTelemetryValue() method to get the CPU utilization and memory utilization. 
		Logs the values of self.cpuUtilPct and self.memUtilPct
		
		"""
		
		self.cpuUtilPct = self.cpuUtilTask.getTelemetryValue()
		self.memUtilPct = self.memUtilTask.getTelemetryValue()
		
		cpuUtilSd = self.cpuUtilTask.generateTelemetry()
		memUtilSd = self.memUtilTask.generateTelemetry()
		
		##add by miaoyao in order to send SystemPerformanceData to gda instead of cpuUtilSd and memUtilSd
		systemPerformanceData = SystemPerformanceData()
		systemPerformanceData.setCpuUtilization(self.cpuUtilPct)
		systemPerformanceData.setMemoryUtilization(self.memUtilPct)
		
		
		
		
		
		
		##--add call back function to handle system information
		if self.dataMsgListener :
			##self.dataMsgListener.handleSystemPerformanceMessage(cpuUtilSd)
			##self.dataMsgListener.handleSystemPerformanceMessage(memUtilSd)
			self.dataMsgListener.handleSystemPerformanceMessage(systemPerformanceData)
		
		logging.info('CPU utilization is %s percent, and memory utilization is %s percent.', str(self.cpuUtilPct), str(self.memUtilPct))
Exemplo n.º 9
0
    def testDefaultValues(self):
        spd = SystemPerformanceData()

        self.assertEquals(spd.getName(), ConfigConst.SYSTEM_PERF_NAME)
        self.assertEquals(spd.getStatusCode(), ConfigConst.DEFAULT_STATUS)

        self.assertEquals(spd.getCpuUtilization(), ConfigConst.DEFAULT_VAL)
        self.assertEquals(spd.getDiskUtilization(), ConfigConst.DEFAULT_VAL)
        self.assertEquals(spd.getMemoryUtilization(), ConfigConst.DEFAULT_VAL)

        logging.info("System perf data as string: " + str(spd))
Exemplo n.º 10
0
 def jsonToSystemPerformanceData(self, jsonData):
     # process data
     jsonData = jsonData.replace("\'", "\"").replace('False',
                                                     'false').replace(
                                                         'True', 'true')
     # load json data
     adDict = json.loads(jsonData)
     # create object and put json data in it
     ad = SystemPerformanceData()
     # vars() get the properties dict of the object
     mvDict = vars(ad)
     # iter properties and fill it
     for key in adDict:
         if key in mvDict:
             setattr(ad, key, adDict[key])
     return ad
 def handleTelemetry(self):
     """
     Get system performance telemetry and send it to dataMsgListener as SystemPerformanceData
     :return:
     """
     cpuVal = self.cpuUtilTask.getTelemetryValue()
     memVal = self.memUtilTask.getTelemetryValue()
     sysPerfData = SystemPerformanceData()
     sysPerfData.setCpuUtilization(cpuVal)
     sysPerfData.setMemoryUtilization(memVal)
     logging.info(
         'CPU utilization is %s percent, and memory utilization is %s percent.',
         str(cpuVal), str(memVal))
     self.dataMsgListener.handleSystemPerformanceMessage(sysPerfData)
     pass
Exemplo n.º 12
0
	def testSystemPerformanceDataConversionsFromObject(self):
		logging.info("\n\n----- [JSON Conversions from SystemPerformanceData] -----")
		
		spdName = "Foobar2 SystemPerformanceData"
		spdObj1 = SystemPerformanceData()
		spdObj1.setName(spdName)
		
		spdObj1Str = self.dataUtil.systemPerformanceDataToJson(spdObj1)
		spdObj2    = self.dataUtil.jsonToSystemPerformanceData(spdObj1Str)
		spdObj2Str = self.dataUtil.systemPerformanceDataToJson(spdObj2)
		
		logging.info("Sample SystemPerformanceData: " + str(spdObj1))
		logging.info("SystemPerformanceData to JSON: " + str(spdObj1Str))
		logging.info("JSON back to SystemPerformanceData: " + str(spdObj2))
		logging.info("SystemPerformanceData back to JSON: " + str(spdObj2Str))

		self.assertEqual(spdName, spdObj1.getName())
		self.assertEqual(spdObj1.getName(), spdObj2.getName())
		self.assertEqual(spdObj1.getTimeStamp(), spdObj2.getTimeStamp())
		self.assertEqual(spdObj1Str, spdObj2Str)
Exemplo n.º 13
0
    def jsonToSystemPerformanceData(self, jsonData):
        """
		Convert JSON to an SystemPerformanceDat instance
		
		@return SystemPerformanceDat
		"""

        jsonData = jsonData.replace("\'", "\"").replace('False',
                                                        'false').replace(
                                                            'True', 'true')
        logging.info('Convert JSON to an SystemPerformanceData instance: ' +
                     jsonData)
        ## Load the dictionary data for the JSON string
        sysdDict = json.loads(jsonData)

        ##Create an instance of SensorData, extract the variables, then map the JSON dict into the new object via an iterative lookup of each key / value pair.
        sysd = SystemPerformanceData()
        mvDict = vars(sysd)

        for key in sysdDict:
            if key in mvDict:
                setattr(sysd, key, sysdDict[key])

        return sysd
Exemplo n.º 14
0
    def testWriteSystemPerformanceDataToCdaDataPath(self):
        logging.info("\n\n----- [SystemPerformanceData to JSON to file] -----")

        dataObj = SystemPerformanceData()
        """
		set CpuUtilization and MemoryUtilization
		"""
        scut = SystemCpuUtilTask()
        smut = SystemMemUtilTask()
        dataObj.setCpuUtilization(scut.getTelemetryValue())
        dataObj.setMemoryUtilization(smut.getTelemetryValue())

        dataStr = self.dataUtil.sensorDataToJson(dataObj)
        fileName = self.cdaDataPath + '/SystemPerformanceData.dat'

        logging.info("Sample SystemPerformanceData JSON (validated): " +
                     str(dataStr))
        logging.info("Writing SystemPerformanceData JSON to CDA data path: " +
                     fileName)

        fileRef = Path(fileName)
        fileRef.write_text(dataStr, encoding='utf-8')