Example #1
0
    def sys_get_proc(self, queries, is_local):
        """
        Get system informations (CPU, memory, IO read & write)
        for each process PID using psutil module.
        """
        processes = {}
        if not is_local:
            return processes
        for query in queries:
            try:
                psproc = PSProcess(query['pid'])
                process = Process(
                    pid = query['pid'],
                    database = query['database'],
                    user = query['user'],
                    client = query['client'],
                    duration = query['duration'],
                    wait = query['wait'],
                    query = clean_str(query['query']),
                    extras = {}
                    )

                process.set_extra('meminfo',
                    psproc.memory_info())
                process.set_extra('io_counters',
                    psproc.io_counters())
                process.set_extra('io_time',
                    time.time())
                process.set_extra('mem_percent',
                    psproc.memory_percent())
                process.set_extra('cpu_percent',
                    psproc.cpu_percent(interval=0))
                process.set_extra('cpu_times',
                    psproc.cpu_times())
                process.set_extra('read_delta', 0)
                process.set_extra('write_delta', 0)
                process.set_extra('io_wait',
                    self.__sys_get_iow_status(psproc.status_iow()))
                process.set_extra('psutil_proc', psproc)
                processes[process.pid] = process

            except psutil.NoSuchProcess:
                pass
            except psutil.AccessDenied:
                pass
        return processes
Example #2
0
    def sys_get_proc(self, queries, is_local):
        """
        Get system informations (CPU, memory, IO read & write)
        for each process PID using psutil module.
        """
        processes = {}
        if not is_local:
            return processes
        for query in queries:
            try:
                psproc = PSProcess(query['pid'])
                process = Process(pid=query['pid'],
                                  database=query['database'],
                                  user=query['user'],
                                  client=query['client'],
                                  duration=query['duration'],
                                  wait=query['wait'],
                                  query=clean_str(query['query']),
                                  extras={})

                process.set_extra('meminfo', psproc.memory_info())
                process.set_extra('io_counters', psproc.io_counters())
                process.set_extra('io_time', time.time())
                process.set_extra('mem_percent', psproc.memory_percent())
                process.set_extra('cpu_percent',
                                  psproc.cpu_percent(interval=0))
                process.set_extra('cpu_times', psproc.cpu_times())
                process.set_extra('read_delta', 0)
                process.set_extra('write_delta', 0)
                process.set_extra(
                    'io_wait', self.__sys_get_iow_status(psproc.status_iow()))
                process.set_extra('psutil_proc', psproc)
                processes[process.pid] = process

            except psutil.NoSuchProcess:
                pass
            except psutil.AccessDenied:
                pass
        return processes