def send_init_info(self, group_name):
        key = next(key for key in self.process_state_db[group_name])
        # system_cpu_info
        mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu,
                                             self.last_time)
        sys_cpu = SystemCpuInfo()
        sys_cpu.num_socket = mem_cpu_usage_data.get_num_socket()
        sys_cpu.num_cpu = mem_cpu_usage_data.get_num_cpu()
        sys_cpu.num_core_per_socket = mem_cpu_usage_data.get_num_core_per_socket(
        )
        sys_cpu.num_thread_per_core = mem_cpu_usage_data.get_num_thread_per_core(
        )

        node_status = NodeStatus(
            name=self.process_state_db[group_name][key].name,
            system_cpu_info=sys_cpu,
            build_info=self.get_build_info())

        # installed/running package version
        installed_package_version = \
            NodeMgrUtils.get_package_version(self.get_package_name())
        if installed_package_version is None:
            self.msg_log(
                'Error getting %s package version' % (self.get_package_name()),
                SandeshLevel.SYS_ERR)
            exit(-1)
        else:
            self.installed_package_version = installed_package_version
            node_status.installed_package_version = installed_package_version
            node_status.running_package_version = installed_package_version

        node_status_uve = NodeStatusUVE(table=self.type_info._object_table,
                                        data=node_status)
        node_status_uve.send()
Beispiel #2
0
    def send_init_info(self):
        # system_cpu_info
        mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
        sys_cpu = SystemCpuInfo()
        sys_cpu.num_socket = mem_cpu_usage_data.get_num_socket()
        sys_cpu.num_cpu = mem_cpu_usage_data.get_num_cpu()
        sys_cpu.num_core_per_socket = mem_cpu_usage_data.get_num_core_per_socket()
        sys_cpu.num_thread_per_core = mem_cpu_usage_data.get_num_thread_per_core()

        node_status = NodeStatus(
                        name=socket.gethostname(),
                        system_cpu_info=sys_cpu,
                        build_info = self.get_build_info())

        # installed/running package version
        installed_package_version = \
            NodeMgrUtils.get_package_version(self.get_package_name())
        if installed_package_version is None:
            sys.stderr.write("Error getting %s package version\n"
                             % (self.get_package_name()))
            exit(-1)
        else:
            self.installed_package_version = installed_package_version
            node_status.installed_package_version = installed_package_version
            node_status.running_package_version = installed_package_version

        node_status_uve = NodeStatusUVE(table=self.table,
                                        data=node_status)
        node_status_uve.send()
    def send_init_info(self):
        self.group_names = list(set([pstat.group for pstat in self.process_state_db.values()]))
        for group in self.group_names:
            key = next(key for key, pstat in self.process_state_db.items() if pstat.group == group)
            # system_cpu_info
            mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
            sys_cpu = SystemCpuInfo()
            sys_cpu.num_socket = mem_cpu_usage_data.get_num_socket()
            sys_cpu.num_cpu = mem_cpu_usage_data.get_num_cpu()
            sys_cpu.num_core_per_socket = mem_cpu_usage_data.get_num_core_per_socket()
            sys_cpu.num_thread_per_core = mem_cpu_usage_data.get_num_thread_per_core()

            node_status = NodeStatus(
                            name=self.process_state_db[key].name,
                            system_cpu_info=sys_cpu,
                            build_info = self.get_build_info())

            # installed/running package version
            installed_package_version = \
                NodeMgrUtils.get_package_version(self.get_package_name())
            if installed_package_version is None:
                sys.stderr.write("Error getting %s package version\n"
                             % (self.get_package_name()))
                exit(-1)
            else:
                self.installed_package_version = installed_package_version
                node_status.installed_package_version = installed_package_version
                node_status.running_package_version = installed_package_version

            node_status_uve = NodeStatusUVE(table=self.type_info._object_table,
                                            data=node_status)
            node_status_uve.send()
    def send_init_info(self, group_name):
        key = next(key for key in self.process_state_db[group_name])
        # system_cpu_info
        mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
        sys_cpu = SystemCpuInfo()
        sys_cpu.num_socket = mem_cpu_usage_data.get_num_socket()
        sys_cpu.num_cpu = mem_cpu_usage_data.get_num_cpu()
        sys_cpu.num_core_per_socket = mem_cpu_usage_data.get_num_core_per_socket()
        sys_cpu.num_thread_per_core = mem_cpu_usage_data.get_num_thread_per_core()

        node_status = NodeStatus(
                        name=self.process_state_db[group_name][key].name,
                        system_cpu_info=sys_cpu,
                        build_info = self.get_build_info())

        # installed/running package version
        installed_package_version = \
            NodeMgrUtils.get_package_version(self.get_package_name())
        if installed_package_version is None:
            self.msg_log('Error getting %s package version' % (self.get_package_name()),
                          SandeshLevel.SYS_ERR)
            exit(-1)
        else:
            self.installed_package_version = installed_package_version
            node_status.installed_package_version = installed_package_version
            node_status.running_package_version = installed_package_version

        node_status_uve = NodeStatusUVE(table=self.type_info._object_table,
                                        data=node_status)
        node_status_uve.send()
Beispiel #5
0
    def send_init_info(self):
        # system_cpu_info
        mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
        sys_cpu = SystemCpuInfo()
        sys_cpu.num_socket = mem_cpu_usage_data.get_num_socket()
        sys_cpu.num_cpu = mem_cpu_usage_data.get_num_cpu()
        sys_cpu.num_core_per_socket = mem_cpu_usage_data.get_num_core_per_socket()
        sys_cpu.num_thread_per_core = mem_cpu_usage_data.get_num_thread_per_core()

        node_status = NodeStatus(
                        name=socket.gethostname(),
                        system_cpu_info=sys_cpu,
                        build_info = self.get_build_info())

        # installed/running package version
        installed_package_version = \
            NodeMgrUtils.get_package_version(self.get_package_name())
        if installed_package_version is None:
            sys.stderr.write("Error getting %s package version\n"
                             % (self.get_package_name()))
            exit(-1)
        else:
            self.installed_package_version = installed_package_version
            node_status.installed_package_version = installed_package_version
            node_status.running_package_version = installed_package_version

        node_status_uve = NodeStatusUVE(table=self.type_info._object_table,
                                        data=node_status)
        node_status_uve.send()
    def event_tick_60(self):
        self.tick_count += 1

        for group in self.process_state_db:
            key = next(key for key in self.process_state_db[group])
            # get disk usage info periodically
            disk_usage_info = self.get_disk_usage()

            # typical ntp sync time is about 5 min - first time,
            # we scan only after 10 min
            if self.tick_count >= 10:
                self.check_ntp_status()
            if self.update_process_core_file_list():
                self.send_process_state_db([group])

            process_mem_cpu_usage = self.get_group_processes_mem_cpu_usage(
                group)

            # get system mem/cpu usage
            system_mem_cpu_usage_data = MemCpuUsageData(
                os.getpid(), self.last_cpu, self.last_time)
            system_mem_usage = system_mem_cpu_usage_data.get_sys_mem_info(
                self.type_info._uve_node_type)
            system_cpu_usage = system_mem_cpu_usage_data.get_sys_cpu_info(
                self.type_info._uve_node_type)

            # update last_cpu/time after all processing is complete
            self.last_cpu = system_mem_cpu_usage_data.last_cpu
            self.last_time = system_mem_cpu_usage_data.last_time

            # send above encoded buffer
            node_status = NodeStatus(
                name=self.process_state_db[group][key].name,
                disk_usage_info=disk_usage_info,
                system_mem_usage=system_mem_usage,
                system_cpu_usage=system_cpu_usage,
                process_mem_cpu_usage=process_mem_cpu_usage)
            # encode other core file
            if self.update_all_core_file():
                node_status.all_core_file_list = self.all_core_file_list

            installed_package_version = \
                NodeMgrUtils.get_package_version(self.get_package_name())
            if installed_package_version is None:
                self.msg_log(
                    'Error getting %s package version' %
                    (self.get_package_name()), SandeshLevel.SYS_ERR)
                installed_package_version = "package-version-unknown"
            if (installed_package_version != self.installed_package_version):
                node_status.installed_package_version = installed_package_version
            node_status_uve = NodeStatusUVE(table=self.type_info._object_table,
                                            data=node_status)
            node_status_uve.send()
        self.installed_package_version = installed_package_version
    def event_tick_60(self):
        self.tick_count += 1

        for group in self.process_state_db:
            key = next(key for key in self.process_state_db[group])
            # get disk usage info periodically
            disk_usage_info = self.get_disk_usage()

            # typical ntp sync time is about 5 min - first time,
            # we scan only after 10 min
            if self.tick_count >= 10:
                self.check_ntp_status()
            if self.update_process_core_file_list():
                self.send_process_state_db([group])

            process_mem_cpu_usage = self.get_group_processes_mem_cpu_usage(group)

            # get system mem/cpu usage
            system_mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
            system_mem_usage = system_mem_cpu_usage_data.get_sys_mem_info(
                self.type_info._uve_node_type)
            system_cpu_usage = system_mem_cpu_usage_data.get_sys_cpu_info(
                self.type_info._uve_node_type)

            # update last_cpu/time after all processing is complete
            self.last_cpu = system_mem_cpu_usage_data.last_cpu
            self.last_time = system_mem_cpu_usage_data.last_time

            # send above encoded buffer
            node_status = NodeStatus(name=self.process_state_db[group][key].name,
                                     disk_usage_info=disk_usage_info,
                                     system_mem_usage=system_mem_usage,
                                     system_cpu_usage=system_cpu_usage,
                                     process_mem_cpu_usage=process_mem_cpu_usage)
            # encode other core file
            if self.update_all_core_file():
                node_status.all_core_file_list = self.all_core_file_list

            installed_package_version = \
                NodeMgrUtils.get_package_version(self.get_package_name())
            if installed_package_version is None:
                self.msg_log('Error getting %s package version' % (self.get_package_name()),
                              SandeshLevel.SYS_ERR)
                installed_package_version = "package-version-unknown"
            if (installed_package_version != self.installed_package_version):
                node_status.installed_package_version = installed_package_version
            node_status_uve = NodeStatusUVE(table=self.type_info._object_table,
                                            data=node_status)
            node_status_uve.send()
        self.installed_package_version = installed_package_version
    def event_tick_60(self):
        self.tick_count += 1
        # get disk usage info periodically
        disk_usage_info = self.get_disk_usage()

        # typical ntp sync time is about 5 min - first time,
        # we scan only after 10 min
        if self.tick_count >= 10:
            self.check_ntp_status()
        if self.update_process_core_file_list():
            self.send_process_state_db(['default'])

        process_mem_cpu_usage = self.get_all_processes_mem_cpu_usage()

        # get system mem/cpu usage
        system_mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu,
                                                    self.last_time)
        system_mem_usage = system_mem_cpu_usage_data.get_sys_mem_info(
            self.type_info._uve_node_type)
        system_cpu_usage = system_mem_cpu_usage_data.get_sys_cpu_info(
            self.type_info._uve_node_type)

        # update last_cpu/time after all processing is complete
        self.last_cpu = system_mem_cpu_usage_data.last_cpu
        self.last_time = system_mem_cpu_usage_data.last_time

        # send above encoded buffer
        node_status = NodeStatus(name=socket.gethostname(),
                                 disk_usage_info=disk_usage_info,
                                 system_mem_usage=system_mem_usage,
                                 system_cpu_usage=system_cpu_usage,
                                 process_mem_cpu_usage=process_mem_cpu_usage)
        # encode other core file
        if self.update_all_core_file():
            node_status.all_core_file_list = self.all_core_file_list

        installed_package_version = \
            NodeMgrUtils.get_package_version(self.get_package_name())
        if installed_package_version is None:
            sys.stderr.write("Error getting %s package version\n" %
                             (self.get_package_name()))
            installed_package_version = "package-version-unknown"
        if (installed_package_version != self.installed_package_version):
            self.installed_package_version = installed_package_version
            node_status.installed_package_version = installed_package_version
        node_status_uve = NodeStatusUVE(table=self.type_info._object_table,
                                        data=node_status)
        node_status_uve.send()
Beispiel #9
0
    def event_tick_60(self):
        self.tick_count += 1
        # get disk usage info periodically
        disk_usage_info = self.get_disk_usage()

        # typical ntp sync time is about 5 min - first time,
        # we scan only after 10 min
        if self.tick_count >= 10:
            self.check_ntp_status()
        if self.update_process_core_file_list():
            self.send_process_state_db(['default'])

        process_mem_cpu_usage = self.get_all_processes_mem_cpu_usage()

        # get system mem/cpu usage
        system_mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
        system_mem_usage = system_mem_cpu_usage_data.get_sys_mem_info(self.uve_node_type)
        system_cpu_usage = system_mem_cpu_usage_data.get_sys_cpu_info(self.uve_node_type)

        # update last_cpu/time after all processing is complete
        self.last_cpu = system_mem_cpu_usage_data.last_cpu
        self.last_time = system_mem_cpu_usage_data.last_time

        # send above encoded buffer
        node_status = NodeStatus(name=socket.gethostname(),
                                 disk_usage_info=disk_usage_info,
                                 system_mem_usage=system_mem_usage,
                                 system_cpu_usage=system_cpu_usage,
                                 process_mem_cpu_usage=process_mem_cpu_usage)
        # encode other core file
        if self.update_all_core_file():
            node_status.all_core_file_list = self.all_core_file_list

        installed_package_version = \
            NodeMgrUtils.get_package_version(self.get_package_name())
        if installed_package_version is None:
            sys.stderr.write("Error getting %s package version\n"
                             % (self.get_package_name()))
            installed_package_version = "package-version-unknown"
        if (installed_package_version != self.installed_package_version):
            self.installed_package_version = installed_package_version
            node_status.installed_package_version = installed_package_version
        node_status_uve = NodeStatusUVE(table=self.table,
                                        data=node_status)
        node_status_uve.send()

        current_time = int(time.time())
        if ((abs(current_time - self.prev_current_time)) > 300):
            # update all process start_times with the updated time
            # Compute the elapsed time and subtract them from
            # current time to get updated values
            sys.stderr.write(
                "Time lapse detected " +
                str(abs(current_time - self.prev_current_time)) + "\n")
            for key in self.process_state_db:
                pstat = self.process_state_db[key]
                if pstat.start_time is not '':
                    pstat.start_time = str(
                        (int(current_time - (self.prev_current_time -
                             ((int)(pstat.start_time)) / 1000000))) * 1000000)
                if (pstat.process_state == 'PROCESS_STATE_STOPPED'):
                    if pstat.stop_time is not '':
                        pstat.stop_time = str(
                            int(current_time - (self.prev_current_time -
                                ((int)(pstat.stop_time)) / 1000000)) *
                            1000000)
                if (pstat.process_state == 'PROCESS_STATE_EXITED'):
                    if pstat.exit_time is not '':
                        pstat.exit_time = str(
                            int(current_time - (self.prev_current_time -
                                ((int)(pstat.exit_time)) / 1000000)) *
                            1000000)
                # update process state database
                self.process_state_db[key] = pstat
            try:
                json_file = '/var/log/contrail/process_state' + \
                    self.node_type + ".json"
                f = open(json_file, 'w')
                f.write(
                    json.dumps(
                        self.process_state_db,
                        default=lambda obj: obj.__dict__))
            except:
                sys.stderr.write("Unable to write json")
                pass
            self.send_process_state_db(self.group_names)
        self.prev_current_time = int(time.time())
    def event_tick_60(self):
        self.tick_count += 1
        
        for group in self.group_names:
            key = next(key for key, pstat in self.process_state_db.items() if pstat.group == group)
            # get disk usage info periodically
            disk_usage_info = self.get_disk_usage()

            # typical ntp sync time is about 5 min - first time,
            # we scan only after 10 min
            if self.tick_count >= 10:
                self.check_ntp_status()
            if self.update_process_core_file_list():
                self.send_process_state_db(['default'])

            process_mem_cpu_usage = self.get_group_processes_mem_cpu_usage(group)

            # get system mem/cpu usage
            system_mem_cpu_usage_data = MemCpuUsageData(os.getpid(), self.last_cpu, self.last_time)
            system_mem_usage = system_mem_cpu_usage_data.get_sys_mem_info(self.uve_node_type)
            system_cpu_usage = system_mem_cpu_usage_data.get_sys_cpu_info(self.uve_node_type)

            # update last_cpu/time after all processing is complete
            self.last_cpu = system_mem_cpu_usage_data.last_cpu
            self.last_time = system_mem_cpu_usage_data.last_time

            # send above encoded buffer
            node_status = NodeStatus(name=self.process_state_db[key].name,
                                     disk_usage_info=disk_usage_info,
                                     system_mem_usage=system_mem_usage,
                                     system_cpu_usage=system_cpu_usage,
                                     process_mem_cpu_usage=process_mem_cpu_usage)
            # encode other core file
            if self.update_all_core_file():
                node_status.all_core_file_list = self.all_core_file_list

            installed_package_version = \
                NodeMgrUtils.get_package_version(self.get_package_name())
            if installed_package_version is None:
                sys.stderr.write("Error getting %s package version\n"
                                 % (self.get_package_name()))
                installed_package_version = "package-version-unknown"
            if (installed_package_version != self.installed_package_version):
                node_status.installed_package_version = installed_package_version
            node_status_uve = NodeStatusUVE(table=self.table,
                                            data=node_status)
            node_status_uve.send()
        self.installed_package_version = installed_package_version

        current_time = int(time.time())
        if ((abs(current_time - self.prev_current_time)) > 300):
            # update all process start_times with the updated time
            # Compute the elapsed time and subtract them from
            # current time to get updated values
            sys.stderr.write(
                "Time lapse detected " +
                str(abs(current_time - self.prev_current_time)) + "\n")
            for key in self.process_state_db:
                pstat = self.process_state_db[key]
                if pstat.start_time is not '':
                    pstat.start_time = str(
                        (int(current_time - (self.prev_current_time -
                             ((int)(pstat.start_time)) / 1000000))) * 1000000)
                if (pstat.process_state == 'PROCESS_STATE_STOPPED'):
                    if pstat.stop_time is not '':
                        pstat.stop_time = str(
                            int(current_time - (self.prev_current_time -
                                ((int)(pstat.stop_time)) / 1000000)) *
                            1000000)
                if (pstat.process_state == 'PROCESS_STATE_EXITED'):
                    if pstat.exit_time is not '':
                        pstat.exit_time = str(
                            int(current_time - (self.prev_current_time -
                                ((int)(pstat.exit_time)) / 1000000)) *
                            1000000)
                # update process state database
                self.process_state_db[key] = pstat
            try:
                json_file = '/var/log/contrail/process_state' + \
                    self.node_type + ".json"
                f = open(json_file, 'w')
                f.write(
                    json.dumps(
                        self.process_state_db,
                        default=lambda obj: obj.__dict__))
            except:
                sys.stderr.write("Unable to write json")
                pass
            self.send_process_state_db(self.group_names)
        self.prev_current_time = int(time.time())