def getCpus(self): ''' Get information about CPUs: device ID, speed, manufacturer, name, number of cores. -> list(hostresource.Cpu) @command: SELECT DeviceId,MaxClockSpeed,Manufacturer,LoadPercentage,Name,NumberOfCores FROM Win32_Processor @raise Exception: if WMI query failed ''' builder = self._provider.getBuilder('Win32_Processor') builder.addWmiObjectProperties('DeviceId', 'MaxClockSpeed', 'Manufacturer', 'LoadPercentage', 'Name', 'NumberOfCores') processors = self._provider.getAgent().getWmiData(builder, timeout=45000) cpus = [] for processor in processors: cpu = Cpu(processor.DeviceId, name=processor.Name) numberOfCores = processor.NumberOfCores if str(numberOfCores).isdigit(): cpu.setCoresCount(numberOfCores) # CPU clockSpeed may vary with maxClockSpeed from defaultClockSpeed # Only Intel CPU took cared of here. m = re.match(r'Intel.*CPU.*(\d\.\d*)GHz', processor.Name) if m: cpu.setSpeedInMhz(int(float(m.group(1)) * 1000)) elif str(processor.MaxClockSpeed).isdigit(): cpu.setSpeedInMhz(processor.MaxClockSpeed) cpu.vendor = processor.Manufacturer logger.debug(cpu) cpus.append(cpu) return cpus
def getCpus(self): ''' Get information about CPUs: device ID, speed, manufacturer, name, number of cores. -> list(hostresource.Cpu) @command: SELECT DeviceId,MaxClockSpeed,Manufacturer,LoadPercentage,Name,NumberOfCores FROM Win32_Processor @raise Exception: if WMI query failed ''' builder = self._provider.getBuilder('Win32_Processor') builder.addWmiObjectProperties('DeviceId', 'MaxClockSpeed', 'Manufacturer', 'LoadPercentage', 'Name', 'NumberOfCores') processors = self._provider.getAgent().getWmiData(builder, timeout=45000) cpus = [] for processor in processors: cpu = Cpu(processor.DeviceId, name=processor.Name) numberOfCores = processor.NumberOfCores if str(numberOfCores).isdigit(): cpu.setCoresCount(numberOfCores) # CPU clockSpeed may vary with maxClockSpeed from defaultClockSpeed # Only Intel CPU took cared of here. m = re.match(r'Intel.*CPU.*(\d\.\d*)GHz', processor.Name) if m: cpu.setSpeedInMhz(int(float(m.group(1))*1000)) elif str(processor.MaxClockSpeed).isdigit(): cpu.setSpeedInMhz(processor.MaxClockSpeed) cpu.vendor = processor.Manufacturer logger.debug(cpu) cpus.append(cpu) return cpus
def getCpus(self): ''' Get information about CPUs: device ID, speed, manufacturer, name, number of cores. -> list(hostresource.Cpu) @command SELECT DeviceId,MaxClockSpeed,Manufacturer,LoadPercentage,Name,SocketDesignation FROM Win32_Processor @raise Exception: if WMI query failed ''' builder = self._provider.getBuilder('Win32_Processor') builder.addWmiObjectProperties('DeviceId', 'MaxClockSpeed', 'Manufacturer', 'LoadPercentage', 'Name', 'SocketDesignation') processors = self._provider.getAgent().getWmiData(builder, timeout=45000) socketDesignationToCpu = {} socketDesignationOccurences = {} for processor in processors: if socketDesignationOccurences.has_key( processor.SocketDesignation): occurences = socketDesignationOccurences[ processor.SocketDesignation] socketDesignationOccurences[ processor.SocketDesignation] = occurences + 1 else: socketDesignationOccurences[processor.SocketDesignation] = 1 if socketDesignationToCpu.has_key(processor.SocketDesignation): continue cpu = Cpu(processor.DeviceId, name=processor.Name) if str(processor.MaxClockSpeed).isdigit(): cpu.setSpeedInMhz(processor.MaxClockSpeed) cpu.vendor = processor.Manufacturer logger.debug(cpu) socketDesignationToCpu[processor.SocketDesignation] = cpu # LoadPercentage cpus = socketDesignationToCpu.values() if socketDesignationToCpu: coresCount = min(socketDesignationOccurences.values()) for cpu in cpus: cpu.setCoresCount(coresCount) return cpus
def getCpus(self): ''' Get information about CPUs: device ID, speed, manufacturer, name, number of cores. -> list(hostresource.Cpu) @command SELECT DeviceId,MaxClockSpeed,Manufacturer,LoadPercentage,Name,SocketDesignation FROM Win32_Processor @raise Exception: if WMI query failed ''' builder = self._provider.getBuilder('Win32_Processor') builder.addWmiObjectProperties('DeviceId', 'MaxClockSpeed', 'Manufacturer', 'LoadPercentage', 'Name', 'SocketDesignation') processors = self._provider.getAgent().getWmiData(builder, timeout = 45000) socketDesignationToCpu = {} socketDesignationOccurences = {} for processor in processors: if socketDesignationOccurences.has_key(processor.SocketDesignation): occurences = socketDesignationOccurences[processor.SocketDesignation] socketDesignationOccurences[processor.SocketDesignation] = occurences + 1 else: socketDesignationOccurences[processor.SocketDesignation] = 1 if socketDesignationToCpu.has_key(processor.SocketDesignation): continue cpu = Cpu(processor.DeviceId, name = processor.Name) if str(processor.MaxClockSpeed).isdigit(): cpu.setSpeedInMhz(processor.MaxClockSpeed) cpu.vendor = processor.Manufacturer logger.debug( cpu ) socketDesignationToCpu[processor.SocketDesignation] = cpu # LoadPercentage cpus = socketDesignationToCpu.values() if socketDesignationToCpu: coresCount = min(socketDesignationOccurences.values()) for cpu in cpus: cpu.setCoresCount(coresCount) return cpus