def _crawl_connections(self):

        assert (self.crawl_mode is not Modes.OUTCONTAINER)

        created_since = -1
        logger.debug('Crawling Connections: since={0}'.format(created_since))
        if self.crawl_mode == Modes.OUTVM:
            if psvmi is None:
                raise NotImplementedError()
            proc_list = psvmi.process_iter(self.get_vm_context())
        else:
            proc_list = psutil.process_iter()

        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 self._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)
Example #3
0
    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_metrics(self):

        assert (self.crawl_mode is not Modes.OUTCONTAINER)

        created_since = -1
        logger.debug('Crawling Metrics')

        if self.crawl_mode == Modes.OUTVM:
            if psvmi is None:
                raise NotImplementedError()
            else:
                list = psvmi.process_iter(self.get_vm_context())
        else:
            list = psutil.process_iter()

        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
            try:
                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,
                       ))
            except Exception as e:
                logger.error('Error crawling metric for process %s' % pid,
                             exc_info=True)
                raise CrawlError(e)
Example #5
0
    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')
Example #6
0
    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_processes(self):

        created_since = -1
        logger.debug('Crawling Processes: since={0}'.format(created_since))

        if self.crawl_mode == Modes.OUTVM:
            if psvmi is None:
                raise NotImplementedError()
            proc_list = psvmi.process_iter(self.get_vm_context())
        else:
            proc_list = psutil.process_iter()

        for p in proc_list:
            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)

            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)
Example #9
0
import psvmi

# Test script that prints the list of processes and system info for a kvm guest
KERNEL = "3.13.0-83-generic"
KERNEL_LONG = "3.13.0-83.127"
ARCH = "x86_64"
INSTANCE = "25738"

# This is ubuntu kernel version format
KERNEL_VERSION = '{0}_{1}.{2}'.format(KERNEL, KERNEL_LONG, ARCH)

for p in psvmi.process_iter(qemu_pid=INSTANCE, kernel_version=KERNEL_VERSION, distro='ubuntu', arch=ARCH):
    print p.name(), p.pid, p.get_connections(), p.get_open_files()
print
print psvmi.system_info(qemu_pid=INSTANCE, kernel_version=KERNEL_VERSION, distro='ubuntu', arch=ARCH)
    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')
Example #11
0
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

if RUNNING_VM is -1:
    output = psvmi.process_iter(vm_context)
    assert any('psvmi_test_init' in i.name() for i in output)

for p in psvmi.process_iter(vm_context):
    if p.pid == 0:
        assert 'swapper' in str(p.name())

    elif p.name() == 'psvmi_test_init':
        assert p.get_memory_info().rss > 0
        assert p.get_memory_info().vms > 0
        assert p.get_memory_percent() > 0
        assert list(p.get_cpu_times())[1] > 0
        assert 'fd=0' in str(p.get_open_files())
        assert 'devconsole' in str(p.get_open_files())

    else:
Example #12
0
import psvmi

# Test script that prints the list of processes and system info for a kvm guest
KERNEL = "3.13.0-83-generic"
KERNEL_LONG = "3.13.0-83.127"
ARCH = "x86_64"
INSTANCE = "25738"

# This is ubuntu kernel version format
KERNEL_VERSION = '{0}_{1}.{2}'.format(KERNEL, KERNEL_LONG, ARCH)

for p in psvmi.process_iter(qemu_pid=INSTANCE,
                            kernel_version=KERNEL_VERSION,
                            distro='ubuntu',
                            arch=ARCH):
    print p.name(), p.pid, p.get_connections(), p.get_open_files()
print
print psvmi.system_info(qemu_pid=INSTANCE,
                        kernel_version=KERNEL_VERSION,
                        distro='ubuntu',
                        arch=ARCH)