def _get_bot_status(self):
        process_uptime_value = TimeFormatter.format(
            self.__get_process_uptime())
        process_uptime = FormattedText()\
            .normal("Uptime: {bot_uptime}").start_format().bold(bot_uptime=process_uptime_value).end_format()

        process_memory_usage_value, process_memory_usage_attribute_name = self.__get_process_memory_usage(
        )
        process_memory_usage_formatted_value = SizeFormatter.format(
            process_memory_usage_value)
        process_memory_usage = FormattedText()\
            .normal("Memory usage: {memory_usage} ({memory_usage_attribute_name})").start_format()\
            .bold(memory_usage=process_memory_usage_formatted_value)\
            .normal(memory_usage_attribute_name=process_memory_usage_attribute_name).end_format()

        thread_number = WorkersAction.get_active_threads_number()

        workers_value = self.scheduler.get_running_workers()
        workers_number = WorkersAction.get_running_workers_number(
            workers_value)

        worker_pools_value = self.scheduler.get_worker_pools()
        worker_pools_number = WorkersAction.get_worker_pools_number(
            worker_pools_value)

        return FormattedText().newline().join(
            (FormattedText().bold("Bot status"), process_uptime,
             process_memory_usage, thread_number, workers_number,
             worker_pools_number))
Exemplo n.º 2
0
 def __log_command_execution(event, elapsed_seconds: float):
     event.logger.log(
         COMMAND_LOG_TAG,
         FormattedText().normal("{command} {args}").start_format().bold(
             command=event.command, args=event.command_args).end_format(),
         FormattedText().normal("User: {user}").start_format().bold(
             user=UserFormatter(
                 event.message.from_).full_data).end_format(),
         FormattedText().normal("Chat: {chat}").start_format().bold(
             chat=ChatFormatter(event.chat).full_data).end_format(),
         FormattedText().normal("Execution time: {time}").start_format().
         bold(time=TimeFormatter.format(elapsed_seconds)).end_format())
    def process(self, event):
        (message, response), benchmark_execution_time = self.__benchmark(
            lambda: self._do_benchmark(event))

        benchmark_execution_value = TimeFormatter.format(
            benchmark_execution_time)
        benchmark_time = FormattedText()\
            .normal("Benchmark duration: {benchmark_time}").start_format()\
            .bold(benchmark_time=benchmark_execution_value).end_format()
        response.newline().newline().concat(benchmark_time)

        self.api. async .send_message(
            response.build_message().to_chat_replying(message))
Exemplo n.º 4
0
 def full_printable_version(self, user_storage_handler):
     formatted_user = UserFormatter.retrieve_and_format(
         self.user_id, user_storage_handler)
     formatted_date = DateFormatter.format_full(self.date)
     formatted_duration = TimeFormatter.format(self.duration)
     formatted_size = SizeFormatter.format(self.file_size)
     text = "\U0001f446 That is the audio with id: {}\n\n".format(
         self.message_id)
     text += "Author: {}\n".format(formatted_user)
     text += "Sent at: {}\n".format(formatted_date)
     text += "Duration: {}\n".format(formatted_duration)
     text += "Size: {}".format(formatted_size)
     return Message.create(text).reply_to_message(
         message_id=self.message_id)
    def _get_system_status(self):
        system_uptime_value = TimeFormatter.format(
            self.__get_elapsed_seconds_since(psutil.boot_time()))
        system_uptime = FormattedText()\
            .normal("Uptime: {system_uptime}").start_format().bold(system_uptime=system_uptime_value).end_format()

        cpu_usage_value = str(
            psutil.cpu_percent(interval=self.cpu_usage_sample_seconds)) + " %"
        cpu_usage = FormattedText()\
            .normal("CPU usage: {cpu_usage} ({sample_interval} sec. sample)").start_format()\
            .bold(cpu_usage=cpu_usage_value).normal(sample_interval=self.cpu_usage_sample_seconds).end_format()

        return FormattedText().newline().join(
            (FormattedText().bold("System status"), system_uptime, cpu_usage))
    def _get_benchmark_result(self, event):
        message = FormattedText().bold(
            "Performing benchmark...").build_message().to_chat_replying(
                event.message)

        message, send_message_time = self.__benchmark_send_message(message)
        api_time_value = TimeFormatter.format(send_message_time)
        api_time = FormattedText()\
            .normal("API call RTT: {api_time}").start_format().bold(api_time=api_time_value).end_format()

        _, code_execution_time = self.__benchmark_code_execution()
        code_execution_value = TimeFormatter.format(code_execution_time)
        code_time = FormattedText()\
            .normal("Code execution: {code_time}").start_format().bold(code_time=code_execution_value).end_format()

        _, storage_access_time = self.__benchmark_storage_access()
        storage_access_value = TimeFormatter.format(storage_access_time)
        storage_time = FormattedText()\
            .normal("Storage access: {storage_time}").start_format()\
            .bold(storage_time=storage_access_value).end_format()

        return message, FormattedText().newline().join(
            (FormattedText().bold("Benchmark result"), api_time, code_time,
             storage_time))
Exemplo n.º 7
0
 def printable_version(self, event, user_storage_handler, format_string):
     format_dict = {
         "formatted_user":
         UserFormatter.retrieve_and_format(self.user_id,
                                           user_storage_handler),
         "formatted_date":
         DateFormatter.format(self.date),
         "formatted_duration":
         TimeFormatter.format(self.duration),
         "formatted_size":
         SizeFormatter.format(self.file_size),
         "formatted_command":
         UnderscoredCommandBuilder.build_command(event.command,
                                                 self.message_id),
     }
     return format_string.format(**format_dict)
Exemplo n.º 8
0
 def get_full_content(self):
     text = self._full_content_header()
     video_note = self.message.video_note
     description = FormattedText()\
         .normal("{bullet}Message is a {dimensions}, {duration}{size} {video_note}")\
         .start_format()\
         .normal(bullet=self.bullet)\
         .concat(dimensions=FormattedText().bold(video_note.length).bold("px"))\
         .bold(duration=TimeFormatter.format(video_note.duration))\
         .concat(size=self._formatted_size(video_note.file_size))\
         .bold(video_note=self.printable_type)\
         .end_format()
     text.concat(description)
     text.newline().newline()
     text.normal(self.start_content).bold("Following is the video message:")
     video_note_message = VideoNote.create_video_note(
         video_note.file_id, video_note.length)
     return [text.build_message(), video_note_message]
Exemplo n.º 9
0
 def get_full_content(self):
     text = self._full_content_header()
     voice = self.message.voice
     description = FormattedText()\
         .normal("{bullet}Message is a {duration}{size} {voice}")\
         .start_format()\
         .normal(bullet=self.bullet)\
         .bold(duration=TimeFormatter.format(voice.duration))\
         .concat(size=self._formatted_size(voice.file_size))\
         .bold(voice=self.printable_type)\
         .end_format()
     text.concat(description)
     text.concat(self._formatted_mime_type(voice.mime_type))
     text.concat(
         self._full_content("caption", prepend_newlines_if_content=True))
     text.newline().newline()
     text.normal(self.start_content).bold("Following is the voice:")
     voice_message = Voice.create_voice(voice.file_id)
     self._add_caption_if_present(voice_message)
     return [text.build_message(), voice_message]
Exemplo n.º 10
0
 def get_full_content(self):
     text = self._full_content_header()
     video = self.message.video
     description = FormattedText()\
         .normal("{bullet}Message is a {dimensions}, {duration}{size} {video}")\
         .start_format()\
         .normal(bullet=self.bullet)\
         .bold(dimensions=self._printable_dimensions(video.width, video.height))\
         .bold(duration=TimeFormatter.format(video.duration))\
         .concat(size=self._formatted_size(video.file_size))\
         .bold(video=self.printable_type)\
         .end_format()
     text.concat(description)
     text.concat(self._formatted_mime_type(video.mime_type))
     text.concat(
         self._full_content("caption", prepend_newlines_if_content=True))
     text.newline().newline()
     text.normal(self.start_content).bold("Following is the video:")
     video_message = Video.create_video(video.file_id)
     self._add_caption_if_present(video_message)
     return [text.build_message(), video_message]
Exemplo n.º 11
0
 def get_full_content(self):
     text = self._full_content_header()
     audio = self.message.audio
     description = FormattedText()\
         .normal("{bullet}Message is a {duration}{size} {audio}")\
         .start_format()\
         .normal(bullet=self.bullet)\
         .bold(duration=TimeFormatter.format(audio.duration))\
         .concat(size=self._formatted_size(audio.file_size))\
         .bold(audio=self.printable_type)\
         .end_format()
     text.concat(description)
     text.concat(
         self._formatted_line_if_present(audio.performer, "Performer"))
     text.concat(self._formatted_line_if_present(audio.title, "Title"))
     text.concat(self._formatted_mime_type(audio.mime_type))
     text.concat(
         self._full_content("caption", prepend_newlines_if_content=True))
     text.newline().newline()
     text.normal(self.start_content).bold("Following is the audio:")
     audio_message = Audio.create_audio(audio.file_id)
     self._add_caption_if_present(audio_message)
     return [text.build_message(), audio_message]
Exemplo n.º 12
0
 def caching_time(caching_seconds: float):
     return FormattedText().normal("Caching time: {caching_time}").start_format()\
         .bold(caching_time=TimeFormatter.format(caching_seconds)).end_format()
Exemplo n.º 13
0
 def processing_time(processing_seconds: float):
     return FormattedText().normal("Processing time: {processing_time}").start_format()\
         .bold(processing_time=TimeFormatter.format(processing_seconds)).end_format()