Exemplo n.º 1
0
    def __warning(self, ip: str, line: str):
        text = emoji.emojize(strings.warning_title) + strings.break_line + strings.break_line \
               + format_table_row(ip, end_line=False) + strings.space \
               + format_link(strings.location_text, strings.iplocation_url + ip) + strings.break_line \
               + format_table_row(line, separator=False)

        block_button = buttons.block.copy()
        block_button[1] += strings.hyphen + ip

        self.msg_mng.send_message(
            [text, [block_button, buttons.shutdown], [3, 3]])
Exemplo n.º 2
0
    def top(self) -> str:
        text = strings.empty

        if self.__top.__len__() > 0:
            self.__top = dict(
                sorted(self.__top.items(), key=lambda x: x[1], reverse=True))
            for ip in self.__top.keys():
                text += format_table_row(ip, self.__top[ip], 20)
        else:
            text = format_table_row(strings.no_registers, separator=False)

        return text
def ram_message():
    total = psutil.virtual_memory().total
    used = psutil.virtual_memory().used
    used_p = format_percent(used / total, 1)
    avail = psutil.virtual_memory().available
    avail_p = format_percent(avail / total, 1)
    cached = psutil.virtual_memory().cached
    cached_p = format_percent(cached / total, 1)
    free = psutil.virtual_memory().free
    free_p = format_percent(free / total, 1)

    text = strings.ram_text \
           + format_table_row('Used', format_bytes(used)) \
           + format_table_row(format_percent('Used'), used_p) \
           + strings.break_line \
           + format_table_row('Free', format_bytes(free)) \
           + format_table_row(format_percent('Free'), avail_p) \
           + strings.break_line \
           + format_table_row('Cached', format_bytes(cached)) \
           + format_table_row(format_percent('Cached'), cached_p) \
           + strings.break_line \
           + format_table_row('Avail.', format_bytes(avail)) \
           + format_table_row(format_percent('Avail.'), free_p)

    callbacks = [
        buttons.cpus, buttons.temps, buttons.back_info, buttons.processes,
        buttons.net, buttons.disks
    ]

    sizes = [3, 3, 3, 3, 3, 3]

    return text, callbacks, sizes
def info_message():
    text = ':information: Info' + '\n\n' \
           + format_table_row('Cores', str(psutil.cpu_count(True))) \
           + format_table_row('Threads', str(psutil.cpu_count())) \
           + format_table_row('Free RAM', format_bytes(psutil.virtual_memory().free)) \
           + format_table_row('Free Mem.', format_bytes(psutil.disk_usage('/').free))

    callbacks = [
        buttons.cpus, buttons.temps, buttons.ram, buttons.processes,
        buttons.net, buttons.disks
    ]

    sizes = [3, 3, 3, 3, 3, 3]

    return text, callbacks, sizes
def cpus_message():
    text = strings.cpus_text \
           + format_table_row('CPU', format_percent(psutil.cpu_percent()))

    i = 0
    for cpu_time in psutil.cpu_percent(percpu=True):
        i += 1
        text += format_table_row('Core' + str(i), format_percent(cpu_time))

    callbacks = [
        buttons.back_info, buttons.temps, buttons.ram, buttons.processes,
        buttons.net, buttons.disks
    ]

    sizes = [3, 3, 3, 3, 3, 3]

    return text, callbacks, sizes
def get_disk_info(route: str, title: str = None):
    text = ''

    try:
        disk_usage = psutil.disk_usage(route)

        text += format_table_row(title if is_str(title) else route)
        text += format_table_row('Used', format_bytes(disk_usage.used))
        text += format_table_row('Used%', format_percent(disk_usage.percent))
        text += format_table_row('Free', format_bytes(disk_usage.free))
        text += format_table_row('Free%',
                                 format_percent(100 - disk_usage.percent))

    except FileNotFoundError as e:
        logging.error(e.strerror)

    return text
def temps_message():
    text = strings.temps_text

    temps = psutil.sensors_temperatures()
    for tempKey in temps.keys():
        text += format_table_row(tempKey)

        for temp in temps.get(tempKey):
            label = temp.label if temp.label else strings.no_label
            text += format_table_row(label, format_temp(temp.current))

        text += '\n'

    callbacks = [
        buttons.cpus, buttons.back_info, buttons.ram, buttons.processes,
        buttons.net, buttons.disks
    ]

    sizes = [3, 3, 3, 3, 3, 3]

    return text, callbacks, sizes
def net_message():
    text = strings.net_text

    text += format_table_row('Public IP', get(strings.ipfy_url).text) + '\n'

    nets = psutil.net_io_counters(True)
    for netKey in nets.keys():
        if netKey != 'lo':
            net = nets.get(netKey)
            is_up = psutil.net_if_stats()[netKey].isup

            text += format_table_row(netKey)
            text += format_table_row('Is up', str(is_up))

            if is_up:
                text += format_table_row(
                    'Address',
                    psutil.net_if_addrs()[netKey][0].address)
                text += format_table_row('Sent', format_bytes(net.bytes_sent))
                text += format_table_row('Recv', format_bytes(net.bytes_recv))

            text += '\n'

    callbacks = [
        buttons.cpus, buttons.temps, buttons.ram, buttons.processes,
        buttons.back_info, buttons.disks
    ]

    sizes = [3, 3, 3, 3, 3, 3]

    return text, callbacks, sizes
def processes_message():
    text = strings.proc_text

    processes = get_process_by_cpu_percent()

    cpu_count = max(psutil.cpu_count(), 1)

    for process in processes:
        if process['cpu_percent'] > 0:
            text += format_table_row('Pid', process['pid']) \
                    + format_table_row('Program', process['name'])

            if is_list_of_min_size(process['cmdline'], 2):
                text += format_table_row('Args', process['cmdline'][1])

            text += format_table_row('User', process['username']) \
                    + format_table_row('Mem%', format_percent(process['memory_percent'])) \
                    + format_table_row('Cpu%', format_percent(process['cpu_percent'] / cpu_count)) + '\n'

    callbacks = [
        buttons.cpus, buttons.temps, buttons.ram, buttons.back_info,
        buttons.net, buttons.disks
    ]

    sizes = [3, 3, 3, 3, 3, 3]

    return text, callbacks, sizes
Exemplo n.º 10
0
 def __format_text(text: str):
     return format_table_row(get_date_hour(), separator=False) + '\n\n'\
            + emoji.emojize(str(text))