Esempio n. 1
0
    def refresh(self):
        template = [
            SingleTextRow("Buffer: " + self.buffer.display_name,
                          maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
            SingleTextRow(""),
            SingleTextRow(self.buffer.description,
                          maps={"normal": "main_list_dg", "focus": MAIN_LIST_FOCUS}),
            SingleTextRow(""),
            SingleTextRow("Global Keybindings",
                          maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
            SingleTextRow(""),
        ]

        template.extend(assemble_rows(
            [[SelectableText(key, maps=get_map("main_list_yellow")),
              SelectableText(command, maps=get_map("main_list_lg"))]
             for key, command in self.global_keybinds.items()],
            ignore_columns=[1], dividechars=3))
        if self.buffer.keybinds:
            template += [
                SingleTextRow(""),
                SingleTextRow("Buffer-specific Keybindings",
                              maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
                SingleTextRow(""),
            ]
            template.extend(assemble_rows(
                [[SelectableText(key, maps=get_map("main_list_yellow")),
                  SelectableText(command, maps=get_map("main_list_lg"))]
                 for key, command in self.buffer.keybinds.items()],
                ignore_columns=[1], dividechars=3))

        self.set_body(template)
        self.set_focus(0)
Esempio n. 2
0
def get_detailed_image_row(docker_image):
    row = []
    image_id = SelectableText(docker_image.short_id, maps=get_map())
    row.append(image_id)

    command = SelectableText(docker_image.command,
                             maps=get_map(defult="main_list_ddg"))
    row.append(command)

    base_image = docker_image.base_image()
    base_image_text = ""
    if base_image:
        base_image_text = base_image.short_name
    base_image_w = SelectableText(base_image_text, maps=get_map())
    row.append(base_image_w)

    time = SelectableText(docker_image.display_time_created(),
                          maps=get_time_attr_map(docker_image.created))
    row.append(time)

    image_names_markup = get_image_names_markup(docker_image)
    # urwid.Text([]) tracebacks
    if image_names_markup:
        image_names = SelectableText(image_names_markup)
    else:
        image_names = SelectableText("")
    row.append(image_names)

    return row
Esempio n. 3
0
def get_detailed_image_row(docker_image):
    row = []
    image_id = SelectableText(docker_image.short_id, maps=get_map())
    row.append(image_id)

    command = SelectableText(docker_image.command, maps=get_map(defult="main_list_ddg"))
    row.append(command)

    base_image = docker_image.base_image()
    base_image_text = ""
    if base_image:
        base_image_text = base_image.short_name
    base_image_w = SelectableText(base_image_text, maps=get_map())
    row.append(base_image_w)

    time = SelectableText(docker_image.display_time_created(),
                          maps=get_time_attr_map(docker_image.created))
    row.append(time)

    image_names_markup = get_image_names_markup(docker_image)
    # urwid.Text([]) tracebacks
    if image_names_markup:
        image_names = SelectableText(image_names_markup)
    else:
        image_names = SelectableText("")
    row.append(image_names)

    return row
Esempio n. 4
0
 def _basic_data(self):
     data = [
         [
             SelectableText("Id", maps=get_map("main_list_green")),
             SelectableText(self.docker_container.container_id)
         ],
         [
             SelectableText("Status", maps=get_map("main_list_green")),
             ContainerStatusWidget(self.docker_container, nice_status=False)
         ],
         [
             SelectableText("Created", maps=get_map("main_list_green")),
             SelectableText("{0}, {1}".format(
                 self.docker_container.display_formal_time_created(),
                 self.docker_container.display_time_created()))
         ],
         [
             SelectableText("Command", maps=get_map("main_list_green")),
             SelectableText(self.docker_container.command)
         ],
     ]
     # TODO: add exit code, created, started, finished, pid
     if self.docker_container.names:
         data.append([
             SelectableText("Name", maps=get_map("main_list_green")),
             SelectableText("".join(self.docker_container.names))
         ], )
     self.view_widgets.extend(assemble_rows(data, ignore_columns=[1]))
Esempio n. 5
0
 def _labels(self):
     if not self.docker_container.labels:
         return []
     data = []
     self.walker.append(RowWidget([SelectableText("Labels", maps=get_map("main_list_white"))]))
     for label_key, label_value in self.docker_container.labels.items():
         data.append([SelectableText(label_key, maps=get_map("main_list_green")), SelectableText(label_value)])
     self.walker.extend(assemble_rows(data, ignore_columns=[1]))
Esempio n. 6
0
def get_container_status_markup(docker_container, nice_status=True):
    if docker_container.running:
        attr_map = get_map("main_list_green")
    elif docker_container.status_created:
        attr_map = get_map("main_list_yellow")
    elif docker_container.exited_well:
        attr_map = get_map("main_list_orange")
    else:
        attr_map = get_map("main_list_red")
    if nice_status:
        return docker_container.nice_status, attr_map
    else:
        return docker_container.simple_status_cap, attr_map
Esempio n. 7
0
 def _basic_data(self):
     data = [
         [SelectableText("Id", maps=get_map("main_list_green")),
          SelectableText(self.docker_image.image_id)],
         [SelectableText("Created", maps=get_map("main_list_green")),
          SelectableText("{0}, {1}".format(self.docker_image.display_formal_time_created(),
                                           self.docker_image.display_time_created()))],
         [SelectableText("Size", maps=get_map("main_list_green")),
          SelectableText(humanize_bytes(self.docker_image.size))],
         [SelectableText("Command", maps=get_map("main_list_green")),
          SelectableText(self.docker_image.container_command)],
     ]
     self.walker.extend(assemble_rows(data, ignore_columns=[1]))
Esempio n. 8
0
def get_time_attr_map(t):
    """
                                                       now -> |
                            hour ago -> |
        day ago -> |
    |--------------|--------------------|---------------------|
    """
    now = datetime.datetime.now()
    if t + datetime.timedelta(hours=3) > now:
        return get_map("main_list_white")
    if t + datetime.timedelta(days=3) > now:
        return get_map("main_list_lg")
    else:
        return get_map("main_list_dg")
Esempio n. 9
0
def get_time_attr_map(t):
    """
                                                       now -> |
                            hour ago -> |
        day ago -> |
    |--------------|--------------------|---------------------|
    """
    now = datetime.datetime.now()
    if t + datetime.timedelta(hours=3) > now:
        return get_map("main_list_white")
    if t + datetime.timedelta(days=3) > now:
        return get_map("main_list_lg")
    else:
        return get_map("main_list_dg")
Esempio n. 10
0
    def _layers(self):
        self.walker.append(RowWidget([SelectableText("")]))
        self.walker.append(RowWidget([SelectableText("Layers", maps=get_map("main_list_white"))]))

        i = self.docker_image
        parent = i.parent_image
        layers = self.docker_image.layers
        index = 0

        if isinstance(parent, RootImage) and len(layers) > 0:  # pulled image, docker 1.10+
            for image in layers:
                self.walker.append(
                    RowWidget([LayerWidget(self.ui, image, index=index)])
                )
                index += 1
        else:
            self.walker.append(RowWidget([LayerWidget(self.ui, self.docker_image, index=index)]))
            while True:
                index += 1
                parent = i.parent_image
                if parent:
                    self.walker.append(RowWidget([LayerWidget(self.ui, parent, index=index)]))
                    i = parent
                else:
                    break
Esempio n. 11
0
 def _image_names(self):
     if not self.docker_image.names:
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Image Names", maps=get_map("main_list_white"))]))
     for n in self.docker_image.names:
         self.walker.append(RowWidget([TagWidget(self.docker_image, n)]))
Esempio n. 12
0
 def _containers(self):
     if not self.docker_image.containers():
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Containers", maps=get_map("main_list_white"))]))
     for container in self.docker_image.containers():
         self.walker.append(RowWidget([ContainerOneLinerWidget(self.ui, container)]))
Esempio n. 13
0
 def _containers(self):
     if not self.docker_image.containers():
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Containers", maps=get_map("main_list_white"))]))
     for container in self.docker_image.containers():
         self.walker.append(RowWidget([ContainerOneLinerWidget(self.ui, container)]))
Esempio n. 14
0
 def _image_names(self):
     if not self.docker_image.names:
         return
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Image Names", maps=get_map("main_list_white"))]))
     for n in self.docker_image.names:
         self.walker.append(RowWidget([TagWidget(self.docker_image, n)]))
Esempio n. 15
0
    def _layers(self):
        self.walker.append(RowWidget([SelectableText("")]))
        self.walker.append(
            RowWidget(
                [SelectableText("Layers", maps=get_map("main_list_white"))]))

        i = self.docker_image
        parent = i.parent_image
        layers = self.docker_image.layers
        index = 0

        if isinstance(
                parent,
                RootImage) and len(layers) > 0:  # pulled image, docker 1.10+
            for image in layers:
                self.walker.append(
                    RowWidget([LayerWidget(self.ui, image, index=index)]))
                index += 1
        else:
            self.walker.append(
                RowWidget(
                    [LayerWidget(self.ui, self.docker_image, index=index)]))
            while True:
                index += 1
                parent = i.parent_image
                if parent:
                    self.walker.append(
                        RowWidget([LayerWidget(self.ui, parent, index=index)]))
                    i = parent
                else:
                    break
Esempio n. 16
0
 def _image(self):
     self.view_widgets.append(RowWidget([SelectableText("")]))
     self.view_widgets.append(
         RowWidget(
             [SelectableText("Image", maps=get_map("main_list_white"))]))
     self.view_widgets.append(
         RowWidget([LayerWidget(self.ui, self.docker_container.image)]))
Esempio n. 17
0
 def _process_tree(self):
     top = self.docker_container.top().response
     logger.debug(top)
     if top:
         self.walker.append(RowWidget([SelectableText("")]))
         self.walker.append(RowWidget([SelectableText("Process Tree",
                                                      maps=get_map("main_list_white"))]))
         self.walker.append(BoxAdapter(ProcessTree(top), len(top)))
Esempio n. 18
0
 def _logs(self):
     operation = self.docker_container.logs(follow=False, lines=10)
     if operation.response:
         self.walker.append(RowWidget([SelectableText("")]))
         self.walker.append(RowWidget([SelectableText("Logs",
                                                      maps=get_map("main_list_white"))]))
         for x in operation.response.splitlines():
             self.walker.append(RowWidget([SelectableText(x)]))
Esempio n. 19
0
 def _logs(self):
     operation = self.docker_container.logs(follow=False, lines=10)
     if operation.response:
         l = []
         l.append(RowWidget([SelectableText("")]))
         l.append(RowWidget([SelectableText("Logs", maps=get_map("main_list_white"))]))
         l.extend([RowWidget([SelectableText(x)]) for x in operation.response.splitlines()])
         self.view_widgets.extend(l)
Esempio n. 20
0
 def _basic_data(self):
     data = [
         [SelectableText("Id", maps=get_map("main_list_green")),
          SelectableText(self.docker_container.container_id)],
         [SelectableText("Status", maps=get_map("main_list_green")),
          ContainerStatusWidget(self.docker_container, nice_status=False)],
         [SelectableText("Created", maps=get_map("main_list_green")),
          SelectableText("{0}, {1}".format(self.docker_container.display_formal_time_created(),
                                           self.docker_container.display_time_created()))],
         [SelectableText("Command", maps=get_map("main_list_green")),
          SelectableText(self.docker_container.command)],
     ]
     # TODO: add exit code, created, started, finished, pid
     if self.docker_container.names:
         data.append(
             [SelectableText("Name", maps=get_map("main_list_green")),
              SelectableText("".join(self.docker_container.names))],
         )
     self.walker.extend(assemble_rows(data, ignore_columns=[1]))
Esempio n. 21
0
    def _net(self):
        try:
            net = self.docker_container.net
        except NotAvailableAnymore:
            raise NotifyError("Container %s is not available anymore" %
                              self.docker_container)
        ports = net.ports
        data = []
        if ports:
            data.extend([[SelectableText("")],
                         [
                             SelectableText("Host Port",
                                            maps=get_map("main_list_white")),
                             SelectableText("Container Port",
                                            maps=get_map("main_list_white"))
                         ]])
            for container_port, host_port in ports.items():
                if host_port and container_port:
                    data.append([
                        SelectableText(host_port),
                        SelectableText(container_port)
                    ])

        ips = net.ips
        logger.debug(ips)
        if ips:
            data.extend([[SelectableText("")],
                         [
                             SelectableText("Network Name",
                                            maps=get_map("main_list_white")),
                             SelectableText("IP Address",
                                            maps=get_map("main_list_white"))
                         ]])
            for net_name, net_data in ips.items():
                a4 = net_data.get("ip_address4", "none")
                a6 = net_data.get("ip_address6", "")
                data.append([SelectableText(net_name), SelectableText(a4)])
                if a6:
                    data.append([SelectableText(net_name), SelectableText(a6)])
        if data:
            self.view_widgets.extend(
                assemble_rows(data, dividechars=3, ignore_columns=[1]))
Esempio n. 22
0
    def refresh(self):
        invocation = ["[{}=value]".format(a.name) for a in self.command.options_definitions] + \
                     ["<{}>".format(o.name) for o in self.command.arguments_definitions]
        template = [
            SingleTextRow("Command: {} {}".format(self.command.name, " ".join(invocation)),
                          maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
            SingleTextRow(""),
        ]
        template += [SingleTextRow(s, maps={"normal": "main_list_dg", "focus": MAIN_LIST_FOCUS})
                     for s in self.command.description.split("\n")]
        template += [SingleTextRow("")]

        if self.command.arguments_definitions:
            template += [
                SingleTextRow(""),
                SingleTextRow("Arguments",
                              maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
                SingleTextRow(""),
            ]
            template.extend(assemble_rows(
                [[SelectableText(argument.name, maps=get_map("main_list_yellow")),
                  SelectableText(argument.description, maps=get_map("main_list_lg"))]
                 for argument in self.command.arguments_definitions],
                ignore_columns=[1], dividechars=3))

        if self.command.options_definitions:
            template += [
                SingleTextRow(""),
                SingleTextRow("Options",
                              maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
                SingleTextRow(""),
            ]
            template.extend(assemble_rows(
                [[SelectableText(option.name, maps=get_map("main_list_yellow")),
                  SelectableText(option.description, maps=get_map("main_list_lg"))]
                 for option in self.command.options_definitions],
                ignore_columns=[1], dividechars=3))

        self.set_body(template)
        self.set_focus(0)
Esempio n. 23
0
    def refresh(self):
        invocation = ["[{}=value]".format(a.name) for a in self.command.argument_definitions] + \
                     ["<{}>".format(o.name) for o in self.command.option_definitions]
        template = [
            SingleTextRow("Command: {} {}".format(self.command.name, " ".join(invocation)),
                          maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
            SingleTextRow(""),
        ]
        template += [SingleTextRow(s, maps={"normal": "main_list_dg", "focus": MAIN_LIST_FOCUS})
                     for s in self.command.description.split("\n")]
        template += [SingleTextRow("")]

        if self.command.option_definitions:
            template += [
                SingleTextRow(""),
                SingleTextRow("Arguments",
                              maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
                SingleTextRow(""),
            ]
            template.extend(assemble_rows(
                [[SelectableText(option.name, maps=get_map("main_list_yellow")),
                  SelectableText(option.description, maps=get_map("main_list_lg"))]
                 for option in self.command.option_definitions],
                ignore_columns=[1], dividechars=3))

        if self.command.argument_definitions:
            template += [
                SingleTextRow(""),
                SingleTextRow("Options",
                              maps={"normal": "main_list_white", "focus": MAIN_LIST_FOCUS}),
                SingleTextRow(""),
            ]
            template.extend(assemble_rows(
                [[SelectableText(argument.name, maps=get_map("main_list_yellow")),
                  SelectableText(argument.description, maps=get_map("main_list_lg"))]
                 for argument in self.command.argument_definitions],
                ignore_columns=[1], dividechars=3))

        self.set_body(template)
        self.set_focus(0)
Esempio n. 24
0
 def _basic_data(self):
     data = [
         [
             SelectableText("Id", maps=get_map("main_list_green")),
             SelectableText(self.docker_image.image_id)
         ],
         [
             SelectableText("Created", maps=get_map("main_list_green")),
             SelectableText("{0}, {1}".format(
                 self.docker_image.display_formal_time_created(),
                 self.docker_image.display_time_created()))
         ],
         [
             SelectableText("Size", maps=get_map("main_list_green")),
             SelectableText(humanize_bytes(self.docker_image.size))
         ],
         [
             SelectableText("Command", maps=get_map("main_list_green")),
             SelectableText(self.docker_image.container_command)
         ],
     ]
     self.walker.extend(assemble_rows(data, ignore_columns=[1]))
Esempio n. 25
0
    def _net(self):
        try:
            net = self.docker_container.net
        except NotAvailableAnymore:
            raise NotifyError("Container %s is not available anymore" % self.docker_container)
        ports = net.ports
        data = []
        if ports:
            data.extend([[SelectableText("")], [
                SelectableText("Host Port", maps=get_map("main_list_white")),
                SelectableText("Container Port", maps=get_map("main_list_white"))
            ]])
            for container_port, host_port in ports.items():
                if host_port and container_port:
                    data.append([
                        SelectableText(host_port), SelectableText(container_port)
                    ])

        ips = net.ips
        logger.debug(ips)
        if ips:
            data.extend([[SelectableText("")], [
                SelectableText("Network Name", maps=get_map("main_list_white")),
                SelectableText("IP Address", maps=get_map("main_list_white"))
            ]])
            for net_name, net_data in ips.items():
                a4 = net_data.get("ip_address4", "none")
                a6 = net_data.get("ip_address6", "")
                data.append([
                    SelectableText(net_name), SelectableText(a4)
                ])
                if a6:
                    data.append([
                        SelectableText(net_name), SelectableText(a6)
                    ])
        if data:
            self.walker.extend(assemble_rows(data, dividechars=3, ignore_columns=[1]))
Esempio n. 26
0
def get_detailed_container_row(docker_container):
    row = []
    container_id = SelectableText(docker_container.short_id)
    row.append(container_id)

    command = SelectableText(docker_container.command, get_map(defult="main_list_ddg"))
    row.append(command)

    image = SelectableText(docker_container.image_name())
    row.append(image)

    row.append(ContainerStatusWidget(docker_container))

    name = SelectableText(docker_container.short_name)
    row.append(name)

    return row
Esempio n. 27
0
def get_detailed_container_row(docker_container):
    row = []
    container_id = SelectableText(docker_container.short_id)
    row.append(container_id)

    commands = docker_container.command.split("\n")
    command_str = commands[0]
    if len(commands) > 0:
        command_str += "..."
    command = SelectableText(command_str, get_map(defult="main_list_ddg"))
    row.append(command)

    image = SelectableText(docker_container.image_name())
    row.append(image)

    row.append(ContainerStatusWidget(docker_container))

    name = SelectableText(docker_container.short_name)
    row.append(name)

    return row
Esempio n. 28
0
    def _resources(self):
        self.view_widgets.append(RowWidget([SelectableText("")]))
        self.view_widgets.append(
            RowWidget([
                SelectableText("Resource Usage",
                               maps=get_map("main_list_white"))
            ]))
        cpu_g = ContainerInfoGraph("graph_lines_cpu_tips", "graph_lines_cpu")
        mem_g = ContainerInfoGraph("graph_lines_mem_tips", "graph_lines_mem")
        blk_r_g = ContainerInfoGraph("graph_lines_blkio_r_tips",
                                     "graph_lines_blkio_r")
        blk_w_g = ContainerInfoGraph("graph_lines_blkio_w_tips",
                                     "graph_lines_blkio_w")
        net_r_g = ContainerInfoGraph("graph_lines_net_r_tips",
                                     "graph_lines_net_r")
        net_w_g = ContainerInfoGraph("graph_lines_net_w_tips",
                                     "graph_lines_net_w")

        cpu_label = ColorText("CPU ", "graph_lines_cpu_legend")
        cpu_value = ColorText("0.0 %", "graph_lines_cpu_legend")
        mem_label = ColorText("Memory ", "graph_lines_mem_legend")
        mem_value = ColorText("0.0 %", "graph_lines_mem_legend")
        blk_r_label = ColorText("I/O Read ", "graph_lines_blkio_r_legend")
        blk_r_value = ColorText("0 B", "graph_lines_blkio_r_legend")
        blk_w_label = ColorText("I/O Write ", "graph_lines_blkio_w_legend")
        blk_w_value = ColorText("0 B", "graph_lines_blkio_w_legend")
        net_r_label = ColorText("Net Rx ", "graph_lines_net_r_legend")
        net_r_value = ColorText("0 B", "graph_lines_net_r_legend")
        net_w_label = ColorText("Net Tx ", "graph_lines_net_w_legend")
        net_w_value = ColorText("0 B", "graph_lines_net_w_legend")
        self.view_widgets.append(
            urwid.Columns([
                BoxAdapter(cpu_g, 12),
                BoxAdapter(mem_g, 12),
                ("weight", 0.5, BoxAdapter(blk_r_g, 12)),
                ("weight", 0.5, BoxAdapter(blk_w_g, 12)),
                ("weight", 0.5, BoxAdapter(net_r_g, 12)),
                ("weight", 0.5, BoxAdapter(net_w_g, 12)),
                BoxAdapter(
                    UnselectableListBox(
                        urwid.SimpleFocusListWalker([
                            UnselectableRowWidget([(12, cpu_label),
                                                   cpu_value]),
                            UnselectableRowWidget([(12, mem_label),
                                                   mem_value]),
                            UnselectableRowWidget([(12, blk_r_label),
                                                   blk_r_value]),
                            UnselectableRowWidget([(12, blk_w_label),
                                                   blk_w_value]),
                            UnselectableRowWidget([(12, net_r_label),
                                                   net_r_value]),
                            UnselectableRowWidget([(12, net_w_label),
                                                   net_w_value]),
                        ])), 12),
            ]))
        self.view_widgets.append(RowWidget([SelectableText("")]))

        @log_traceback
        def realtime_updates():
            g = self.docker_container.stats().response
            while True:
                try:
                    update = next(g)
                except Exception as ex:
                    if "Timeout" in ex.__class__.__name__:
                        logger.info("timeout when reading stats: %r", ex)
                        g = self.docker_container.stats().response
                        continue
                    logger.error("error while getting stats: %r", ex)
                    self.ui.notify_message("Error while getting stats: %s" %
                                           ex,
                                           level="error")
                    break

                if self.stop.is_set():
                    break
                logger.debug(update)
                cpu_percent = update["cpu_percent"]
                cpu_value.text = "%.2f %%" % cpu_percent
                cpu_g.rotate_value(int(cpu_percent), max_val=100)

                mem_percent = update["mem_percent"]
                mem_current = humanize_bytes(update["mem_current"])
                mem_value.text = "%.2f %% (%s)" % (mem_percent, mem_current)
                mem_g.rotate_value(int(mem_percent), max_val=100)

                blk_read = update["blk_read"]
                blk_write = update["blk_write"]
                blk_r_value.text = humanize_bytes(blk_read)
                blk_w_value.text = humanize_bytes(blk_write)
                r_max_val = blk_r_g.rotate_value(blk_read, adaptive_max=True)
                w_max_val = blk_w_g.rotate_value(blk_write, adaptive_max=True)
                blk_r_g.set_max(max((r_max_val, w_max_val)))
                blk_w_g.set_max(max((r_max_val, w_max_val)))

                net_read = update["net_rx"]
                net_write = update["net_tx"]
                net_r_value.text = humanize_bytes(net_read)
                net_w_value.text = humanize_bytes(net_write)
                r_max_val = net_r_g.rotate_value(net_read, adaptive_max=True)
                w_max_val = net_w_g.rotate_value(net_write, adaptive_max=True)
                net_r_g.set_max(max((r_max_val, w_max_val)))
                net_w_g.set_max(max((r_max_val, w_max_val)))

        self.thread = threading.Thread(target=realtime_updates, daemon=True)
        self.thread.start()
Esempio n. 29
0
 def _image(self):
     self.walker.append(RowWidget([SelectableText("")]))
     self.walker.append(RowWidget([SelectableText("Image", maps=get_map("main_list_white"))]))
     self.walker.append(RowWidget([LayerWidget(self.ui, self.docker_container.image)]))
Esempio n. 30
0
    def _resources(self):
        self.walker.append(RowWidget([SelectableText("")]))
        self.walker.append(RowWidget([SelectableText("Resource Usage",
                                                     maps=get_map("main_list_white"))]))
        cpu_g = ContainerInfoGraph("graph_lines_cpu_tips", "graph_lines_cpu")
        mem_g = ContainerInfoGraph("graph_lines_mem_tips", "graph_lines_mem")
        blk_r_g = ContainerInfoGraph("graph_lines_blkio_r_tips", "graph_lines_blkio_r")
        blk_w_g = ContainerInfoGraph("graph_lines_blkio_w_tips", "graph_lines_blkio_w")
        net_r_g = ContainerInfoGraph("graph_lines_net_r_tips", "graph_lines_net_r")
        net_w_g = ContainerInfoGraph("graph_lines_net_w_tips", "graph_lines_net_w")

        cpu_label = ColorText("CPU ", "graph_lines_cpu_legend")
        cpu_value = ColorText("0.0 %", "graph_lines_cpu_legend")
        mem_label = ColorText("Memory ", "graph_lines_mem_legend")
        mem_value = ColorText("0.0 %", "graph_lines_mem_legend")
        blk_r_label = ColorText("I/O Read ", "graph_lines_blkio_r_legend")
        blk_r_value = ColorText("0 B", "graph_lines_blkio_r_legend")
        blk_w_label = ColorText("I/O Write ", "graph_lines_blkio_w_legend")
        blk_w_value = ColorText("0 B", "graph_lines_blkio_w_legend")
        net_r_label = ColorText("Net Rx ", "graph_lines_net_r_legend")
        net_r_value = ColorText("0 B", "graph_lines_net_r_legend")
        net_w_label = ColorText("Net Tx ", "graph_lines_net_w_legend")
        net_w_value = ColorText("0 B", "graph_lines_net_w_legend")
        self.walker.append(urwid.Columns([
            BoxAdapter(cpu_g, 12),
            BoxAdapter(mem_g, 12),
            ("weight", 0.5, BoxAdapter(blk_r_g, 12)),
            ("weight", 0.5, BoxAdapter(blk_w_g, 12)),
            ("weight", 0.5, BoxAdapter(net_r_g, 12)),
            ("weight", 0.5, BoxAdapter(net_w_g, 12)),
            BoxAdapter(UnselectableListBox(urwid.SimpleFocusListWalker([
                UnselectableRowWidget([(12, cpu_label), cpu_value]),
                UnselectableRowWidget([(12, mem_label), mem_value]),
                UnselectableRowWidget([(12, blk_r_label), blk_r_value]),
                UnselectableRowWidget([(12, blk_w_label), blk_w_value]),
                UnselectableRowWidget([(12, net_r_label), net_r_value]),
                UnselectableRowWidget([(12, net_w_label), net_w_value]),
            ])), 12),
        ]))
        self.walker.append(RowWidget([SelectableText("")]))

        @log_traceback
        def realtime_updates():
            g = self.docker_container.stats().response
            while True:
                try:
                    update = next(g)
                except Exception as ex:
                    if "Timeout" in ex.__class__.__name__:
                        logger.info("timeout when reading stats: %r", ex)
                        g = self.docker_container.stats().response
                        continue
                    logger.error("error while getting stats: %r", ex)
                    self.ui.notify_message("Error while getting stats: %s" % ex, level="error")
                    break

                if self.stop.is_set():
                    break
                logger.debug(update)
                cpu_percent = update["cpu_percent"]
                cpu_value.text = "%.2f %%" % cpu_percent
                cpu_g.rotate_value(int(cpu_percent), max_val=100)

                mem_percent = update["mem_percent"]
                mem_current = humanize_bytes(update["mem_current"])
                mem_value.text = "%.2f %% (%s)" % (mem_percent, mem_current)
                mem_g.rotate_value(int(mem_percent), max_val=100)

                blk_read = update["blk_read"]
                blk_write = update["blk_write"]
                blk_r_value.text = humanize_bytes(blk_read)
                blk_w_value.text = humanize_bytes(blk_write)
                r_max_val = blk_r_g.rotate_value(blk_read, adaptive_max=True)
                w_max_val = blk_w_g.rotate_value(blk_write, adaptive_max=True)
                blk_r_g.set_max(max((r_max_val, w_max_val)))
                blk_w_g.set_max(max((r_max_val, w_max_val)))

                net_read = update["net_rx"]
                net_write = update["net_tx"]
                net_r_value.text = humanize_bytes(net_read)
                net_w_value.text = humanize_bytes(net_write)
                r_max_val = net_r_g.rotate_value(net_read, adaptive_max=True)
                w_max_val = net_w_g.rotate_value(net_write, adaptive_max=True)
                net_r_g.set_max(max((r_max_val, w_max_val)))
                net_w_g.set_max(max((r_max_val, w_max_val)))

        self.thread = threading.Thread(target=realtime_updates, daemon=True)
        self.thread.start()