コード例 #1
0
ファイル: dcs.py プロジェクト: theendsofinvention/esst
        async def _no_more_mr_nice_guy():
            if not self.app or not self.app.is_running():
                return True
            LOGGER.debug('killing dcs.exe application')
            self.app.kill()
            now_ = utils.now()
            while self.app.is_running():
                await asyncio.sleep(1)
                if utils.now() - now_ > 10:
                    return False

            return True
コード例 #2
0
ファイル: server.py プロジェクト: theendsofinvention/esst
    def _update_status():
        while not CTX.exit:

            cpu_usage = psutil.cpu_percent(1)

            net_io = psutil.net_io_counters()
            bytes_sent = net_io.bytes_sent
            bytes_recv = net_io.bytes_recv

            ServerStatus.cpu_usage = cpu_usage
            if CTX.server_show_cpu_usage or CTX.server_show_cpu_usage_once:
                DISCORD.say(f'Server cpu usage: {cpu_usage}%')
                CTX.server_show_cpu_usage_once = False

            ServerStatus.used_memory = ServerStatus.total_memory - psutil.virtual_memory().free
            ServerStatus.mem_usage = round(
                ServerStatus.used_memory / ServerStatus.total_memory * 100, 2)
            ServerStatus.swap_used = psutil.swap_memory().used

            now_ = now()
            CTX.server_cpu_history.append((now_, cpu_usage))
            CTX.server_mem_history.append((now_, ServerStatus.mem_usage))

            # noinspection PyProtectedMember
            if ServerStatus.bytes_recv_ != 0:
                bytes_sent_ = bytes_sent - ServerStatus.bytes_sent_
                bytes_recv_ = bytes_recv - ServerStatus.bytes_recv_
                ServerStatus.bytes_sent = bytes_sent_
                ServerStatus.bytes_recv = bytes_recv_
                CTX.server_bytes_sent_history.append((now_, bytes_sent_))
                CTX.server_bytes_recv_history.append((now_, bytes_recv_))
            ServerStatus.bytes_recv_ = bytes_recv
            ServerStatus.bytes_sent_ = bytes_sent

            time.sleep(5)
コード例 #3
0
ファイル: dcs.py プロジェクト: theendsofinvention/esst
        async def _ask_politely():
            if not self.app or not self.app.is_running():
                return True
            LOGGER.debug('sending socket command to DCS for graceful exit')
            commands.LISTENER.exit_dcs()
            await asyncio.sleep(1)
            LOGGER.debug(
                'waiting on DCS to close itself (grace period: %s seconds)',
                DCSConfig.DCS_CLOSE_GRACE_PERIOD())
            now_ = utils.now()
            while self.app.is_running():
                await asyncio.sleep(1)
                if utils.now() - now_ > DCSConfig.DCS_CLOSE_GRACE_PERIOD():
                    LOGGER.debug('grace period time out!')
                    return False

            LOGGER.info('DCS closed itself, nice')
            return True
コード例 #4
0
ファイル: listener.py プロジェクト: theendsofinvention/esst
    def _parse_ping(self, data: dict):
        if Status.paused != data.get('paused'):
            if not data.get('paused'):
                LOGGER.info('DCS server is ready!')
        players = data.get('players', set())
        if players != Status.players:
            players, old_players = set(players), set(Status.players)
            joined = players - old_players
            left = old_players - players
            if joined:
                LOGGER.info('player(s) joined: %s', ', '.join(joined))
            if left:
                LOGGER.info('player(s) left: %s', ', '.join(left))
        self.last_ping = time.time()
        Status.server_age = data.get('time', 'unknown')
        Status.mission_time = data.get('model_time', 'unknown')
        Status.paused = data.get('paused', 'unknown')
        Status.mission_file = data.get('mission_filename', 'unknown')
        Status.mission_name = data.get('mission_name', 'unknown')
        Status.players = data.get('players', set())

        CTX.players_history.append((now(), len(Status.players)))
コード例 #5
0
ファイル: dcs.py プロジェクト: theendsofinvention/esst
    def monitor_cpu_usage(self):
        """
        Gets the CPU usage of "DCS.exe" over 5 seconds, and sends an alert if the given threshold is exceeded

        Threshold is set via the config value "DCS_HIGH_CPU_USAGE", and it defaults to 80%
        """
        while not core.CTX.exit:
            try:
                if self.app and self.app.is_running():
                    cpu_usage = int(
                        self.app.cpu_percent(
                            DCSConfig.DCS_HIGH_CPU_USAGE_INTERVAL()))
                    mem_usage = int(self.app.memory_percent())
                    core.Status.dcs_cpu_usage = f'{cpu_usage}%'
                    if core.CTX.dcs_show_cpu_usage or core.CTX.dcs_show_cpu_usage_once:
                        commands.DISCORD.say(f'DCS cpu usage: {cpu_usage}%')
                        core.CTX.dcs_show_cpu_usage_once = False
                    if DCSConfig.DCS_HIGH_CPU_USAGE():
                        if cpu_usage > DCSConfig.DCS_HIGH_CPU_USAGE(
                        ) and not core.Status.paused:
                            LOGGER.warning(
                                'DCS cpu usage has been higher than %s%% for %s seconds',
                                DCSConfig.DCS_HIGH_CPU_USAGE(),
                                DCSConfig.DCS_HIGH_CPU_USAGE_INTERVAL(),
                            )

                    now_ = utils.now()
                    core.CTX.dcs_mem_history.append((now_, mem_usage))
                    core.CTX.dcs_cpu_history.append((now_, cpu_usage))

            except psutil.NoSuchProcess:
                pass

            # I didn't think it could, happen, but of course it did ...
            # See https://github.com/132nd-vWing/ESST/issues/59
            except AttributeError:
                pass