def crawl(self, vm_desc, **kwargs): logger.debug('Crawling %s' % self.get_feature()) if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init( domain_name, domain_name, kernel_version, distro, arch) interfaces = self._crawl_interface_counters(vm_context) for (interface_name, curr_count) in interfaces: feature_key = '{0}-{1}'.format('interface', interface_name) cache_key = '{0}-{1}'.format('OUTVM', feature_key) (prev_count, prev_time) = self._cache_get_value(cache_key) self._cache_put_value(cache_key, curr_count) if prev_count and prev_time: d = time.time() - prev_time diff = [(a - b) / d for (a, b) in zip(curr_count, prev_count)] else: # first measurement diff = [0] * 6 feature_attributes = InterfaceFeature._make(diff) yield (feature_key, feature_attributes, 'interface')
def crawl(self, vm_desc, **kwargs): logger.debug('Crawling %s' % self.get_feature()) if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) interfaces = self._crawl_interface_counters(vm_context) for (interface_name, curr_count) in interfaces: feature_key = '{0}-{1}'.format('interface', interface_name) cache_key = '{0}-{1}'.format('OUTVM', feature_key) (prev_count, prev_time) = self._cache_get_value(cache_key) self._cache_put_value(cache_key, curr_count) if prev_count and prev_time: d = time.time() - prev_time diff = [(a - b) / d for (a, b) in zip(curr_count, prev_count)] else: # first measurement diff = [0] * 6 feature_attributes = InterfaceFeature._make(diff) yield (feature_key, feature_attributes, 'interface')
def crawl(self, vm_desc, **kwargs): created_since = -1 if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init( domain_name, domain_name, kernel_version, distro, arch) proc_list = psvmi.process_iter(vm_context) for p in proc_list: pid = (p.pid() if hasattr(p.pid, '__call__') else p.pid) status = (p.status() if hasattr(p.status, '__call__' ) else p.status) if status == psutil.STATUS_ZOMBIE: continue create_time = ( p.create_time() if hasattr( p.create_time, '__call__') else p.create_time) name = (p.name() if hasattr(p.name, '__call__') else p.name) if create_time <= created_since: continue for conn in p.get_connections(): yield crawl_single_connection(conn, pid, name)
def crawl(self, vm_desc, **kwargs): created_since = -1 if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) proc_list = psvmi.process_iter(vm_context) for p in proc_list: pid = (p.pid() if hasattr(p.pid, '__call__') else p.pid) status = (p.status() if hasattr(p.status, '__call__') else p.status) if status == psutil.STATUS_ZOMBIE: continue create_time = (p.create_time() if hasattr( p.create_time, '__call__') else p.create_time) name = (p.name() if hasattr(p.name, '__call__') else p.name) if create_time <= created_since: continue for conn in p.get_connections(): yield crawl_single_connection(conn, pid, name)
def crawl(self, vm_desc, **kwargs): created_since = -1 logger.debug('Crawling Metrics') if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) list = psvmi.process_iter(vm_context) for p in list: create_time = (p.create_time() if hasattr( p.create_time, '__call__') else p.create_time) if create_time <= created_since: continue name = (p.name() if hasattr(p.name, '__call__') else p.name) pid = (p.pid() if hasattr(p.pid, '__call__') else p.pid) status = (p.status() if hasattr(p.status, '__call__') else p.status) if status == psutil.STATUS_ZOMBIE: continue username = (p.username() if hasattr(p.username, '__call__') else p.username) meminfo = (p.get_memory_info() if hasattr( p.get_memory_info, '__call__') else p.memory_info) ioinfo = (p.get_io_counters() if hasattr( p.get_io_counters, '__call__') else p.io_counters) cpu_percent = self._crawl_metrics_cpu_percent(p) memory_percent = (p.get_memory_percent() if hasattr( p.get_memory_percent, '__call__') else p.memory_percent) feature_key = '{0}/{1}'.format(name, pid) yield (feature_key, MetricFeature( round(cpu_percent, 2), round(memory_percent, 2), name, pid, ioinfo.read_bytes, meminfo.rss, str(status), username, meminfo.vms, ioinfo.write_bytes, ), 'metric')
def crawl(self, vm_desc, **kwargs): if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: not good, context_init was being done once per VM # in previous monolithic model, now it's once per plugin/feature vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) sys = psvmi.system_info(vm_context) feature_attributes = OSFeature(sys.boottime, 'unknown', sys.ipaddr, sys.ostype, sys.osversion, sys.osrelease, sys.osplatform) feature_key = sys.ostype return [(feature_key, feature_attributes, 'os')]
def crawl(self, vm_desc, **kwargs): if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) created_since = -1 for p in psvmi.process_iter(vm_context): create_time = (p.create_time() if hasattr( p.create_time, '__call__') else p.create_time) if create_time <= created_since: continue yield self._crawl_single_process(p)
def crawl(self, vm_desc, **kwargs): if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) sysmem = psvmi.system_memory_info(vm_context) feature_attributes = MemoryFeature( sysmem.memory_used, sysmem.memory_buffered, sysmem.memory_cached, sysmem.memory_free, (sysmem.memory_used * 100 / (sysmem.memory_used + sysmem.memory_free))) return [('memory', feature_attributes, 'memory')]
def crawl(self, vm_desc, **kwargs): if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init( domain_name, domain_name, kernel_version, distro, arch) created_since = -1 for p in psvmi.process_iter(vm_context): create_time = ( p.create_time() if hasattr( p.create_time, '__call__') else p.create_time) if create_time <= created_since: continue yield self._crawl_single_process(p)
def crawl(self, vm_desc, **kwargs): if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init( domain_name, domain_name, kernel_version, distro, arch) sysmem = psvmi.system_memory_info(vm_context) feature_attributes = MemoryFeature( sysmem.memory_used, sysmem.memory_buffered, sysmem.memory_cached, sysmem.memory_free, (sysmem.memory_used * 100 / (sysmem.memory_used + sysmem.memory_free))) return [('memory', feature_attributes, 'memory')]
def crawl(self, vm_desc, **kwargs): if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: not good, context_init was being done once per VM # in previous monolithic model, now it's once per plugin/feature vm_context = psvmi.context_init( domain_name, domain_name, kernel_version, distro, arch) sys = psvmi.system_info(vm_context) feature_attributes = OSFeature( sys.boottime, 'unknown', sys.ipaddr, sys.ostype, sys.osversion, sys.osrelease, sys.osplatform ) feature_key = sys.ostype return [(feature_key, feature_attributes, 'os')]
def crawl(self, vm_desc, **kwargs): created_since = -1 logger.debug('Crawling Metrics') if psvmi is None: raise NotImplementedError() else: (domain_name, kernel_version, distro, arch) = vm_desc # XXX: this has to be read from some cache instead of # instead of once per plugin/feature vm_context = psvmi.context_init( domain_name, domain_name, kernel_version, distro, arch) list = psvmi.process_iter(vm_context) for p in list: create_time = ( p.create_time() if hasattr( p.create_time, '__call__') else p.create_time) if create_time <= created_since: continue name = (p.name() if hasattr(p.name, '__call__' ) else p.name) pid = (p.pid() if hasattr(p.pid, '__call__') else p.pid) status = (p.status() if hasattr(p.status, '__call__' ) else p.status) if status == psutil.STATUS_ZOMBIE: continue username = ( p.username() if hasattr( p.username, '__call__') else p.username) meminfo = ( p.get_memory_info() if hasattr( p.get_memory_info, '__call__') else p.memory_info) ioinfo = ( p.get_io_counters() if hasattr( p.get_io_counters, '__call__') else p.io_counters) cpu_percent = self._crawl_metrics_cpu_percent(p) memory_percent = ( p.get_memory_percent() if hasattr( p.get_memory_percent, '__call__') else p.memory_percent) feature_key = '{0}/{1}'.format(name, pid) yield (feature_key, MetricFeature( round(cpu_percent, 2), round(memory_percent, 2), name, pid, ioinfo.read_bytes, meminfo.rss, str(status), username, meminfo.vms, ioinfo.write_bytes, ), 'metric')
import psvmi import sys # Test script that prints the list of processes and system info for a kvm guest _vm_name = sys.argv[1] _qemu_pid = sys.argv[2] _kernel_version = sys.argv[3] _distro = sys.argv[4] _arch = sys.argv[5] RUNNING_VM = sys.argv[6] vm_context = psvmi.context_init(qemu_pid=_qemu_pid, kernel_version=_kernel_version, distro=_distro, arch=_arch) output = psvmi.system_info(vm_context) assert 'Linux' in output assert len(list(output)) > 0 output = psvmi.cpuHw_info(vm_context) assert 'QEMU' in str(output) assert len(list(output)) > 0 output = psvmi.interface_iter(vm_context) assert any('lo' in i for i in output) output = psvmi.module_iter(vm_context) assert len(list(output)) > 0
def get_vm_context(self): if self.vm_context is None: (domain_name, kernel_version, distro, arch) = self.vm self.vm_context = psvmi.context_init(domain_name, domain_name, kernel_version, distro, arch) return self.vm_context