Пример #1
0
def show_summary(report, cluster):
    t = html2.HTMLTable(["Setting", "Value"])
    t.add_cells("Collected at", cluster.report_collected_at_local)
    t.add_cells("Collected at GMT", cluster.report_collected_at_gmt)
    t.add_cells("Status", cluster.overall_status)
    t.add_cells("PG count", cluster.num_pgs)
    t.add_cells("Pool count", len(cluster.pools))
    t.add_cells("Used", b2ssize(cluster.bytes_used, False))
    t.add_cells("Avail", b2ssize(cluster.bytes_avail, False))
    t.add_cells("Data", b2ssize(cluster.data_bytes, False))

    avail_perc = cluster.bytes_avail * 100 / cluster.bytes_total
    t.add_cells("Free %", avail_perc)

    osd_count = len(cluster.osds)
    t.add_cells("Mon count", len(cluster.mons))

    report.add_block(3, "Status:", t)

    if cluster.settings is None:
        t = H.font("No live OSD found!", color="red")
    else:
        t = html2.HTMLTable(["Setting", "Value"])
        t.add_cells("Count", osd_count)
        t.add_cells("PG per OSD", cluster.num_pgs / osd_count)
        t.add_cells("Cluster net", cluster.cluster_net)
        t.add_cells("Public net", cluster.public_net)
        t.add_cells("Near full ratio", cluster.settings.mon_osd_nearfull_ratio)
        t.add_cells("Full ratio", cluster.settings.mon_osd_full_ratio)
        t.add_cells("Backfill full ratio",
                    cluster.settings.osd_backfill_full_ratio)
        t.add_cells("Filesafe full ratio",
                    cluster.settings.osd_failsafe_full_ratio)
        t.add_cells("Journal aio", cluster.settings.journal_aio)
        t.add_cells("Journal dio", cluster.settings.journal_dio)
        t.add_cells("Filestorage sync",
                    str(cluster.settings.filestore_max_sync_interval) + 's')
    report.add_block(3, "OSD:", t)

    t = html2.HTMLTable(["Setting", "Value"])
    t.add_cells("Client IO Bps", b2ssize(cluster.write_bytes_sec, False))
    t.add_cells("Client IO IOPS", b2ssize(cluster.op_per_sec, False))
    report.add_block(2, "Activity:", t)

    if len(cluster.health_summary) != 0:
        t = html2.Doc()
        for msg in cluster.health_summary:
            if msg['severity'] == "HEALTH_WARN":
                color = "orange"
            elif msg['severity'] == "HEALTH_ERR":
                color = "red"
            else:
                color = "black"

            t.font(msg['summary'].capitalize(), color=color)
            t.br

        report.add_block(2, "Status messages:", t)
Пример #2
0
    def save_to(self, output_dir):
        pt = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        static_files_dir = os.path.join(pt, "html_js_css")

        self.style_links.append(
            "http://getbootstrap.com/examples/dashboard/dashboard.css")

        css = """
        table.zebra-table tr:nth-child(even) {background-color: #E0E0FF;}
        table th {background: #ededed;}
        .right{
            position:relative;
            margin:0;
            padding:0;
            float:right;
        }
        .left{
            position:relative   ;
            margin:0;
            padding:0;
            float:left;
        }
        th {text-align: center;}
        td {text-align: right;}
        tr td:first-child {text-align: left;}
        """

        self.style.append(css)

        links = []
        for link in self.style_links + self.script_links:
            fname = link.rsplit('/', 1)[-1]
            src_path = os.path.join(static_files_dir, fname)
            dst_path = os.path.join(output_dir, fname)
            if os.path.exists(src_path):
                if not os.path.exists(dst_path):
                    shutil.copyfile(src_path, dst_path)
                link = fname
            links.append(link)

        css_links = links[:len(self.style_links)]
        js_links = links[len(self.style_links):]

        doc = html2.Doc()
        with doc.html:
            with doc.head:
                doc.title("Ceph cluster report: " + self.cluster_name)

                for url in css_links:
                    doc.link(href=url, rel="stylesheet", type="text/css")

                doc.style("\n".join(self.style), type="text/css")

                for url in js_links:
                    doc.script(type="text/javascript", src=url)

                for script in self.scripts:
                    doc.script(script, type="text/javascript")

            with doc.body(onload=";".join(self.onload)):
                with doc.div(_class="container-fluid"):
                    with doc.div(
                            _class="row row-offcanvas row-offcanvas-left"):
                        with doc.div(_class="col-md-2 sidebar-offcanvas",
                                     id="sidebar",
                                     role="navigation"):
                            with doc.div(data_spy="affix",
                                         data_offset_top="45",
                                         data_offset_bottom="90"):
                                with doc.ul(_class="nav", id="sidebar-nav"):
                                    for sid, (_, _, menu,
                                              data) in enumerate(self.divs):
                                        if menu is None or data is None or data == "":
                                            continue

                                        if menu.endswith(":"):
                                            menu = menu[:-1]
                                        doc.li.a(menu,
                                                 href="#section" + str(sid))

                        with doc.div(_class="col-md-10",
                                     data_spy="scroll",
                                     data_target="#sidebar-nav"):
                            doc("\n")
                            doc._enter("div", _class="row")
                            for sid, (w, header, _,
                                      block) in enumerate(self.divs):
                                if block is None:
                                    doc._exit()
                                    doc("\n")
                                    doc._enter("div", _class="row")
                                elif w is None:
                                    doc(block)
                                else:
                                    with doc.div(_class="col-md-" + str(w)):
                                        doc.H3.center(header,
                                                      id="section" + str(sid))
                                        doc.br

                                        if block != "":
                                            doc.center(block)
                            doc._exit()

        index = "<!doctype html>" + str(doc)
        index_path = os.path.join(output_dir, self.output_file)

        # try:
        #     import BeautifulSoup
        #     index = BeautifulSoup.BeautifulSoup(index).prettify()
        # except:
        #     pass

        open(index_path, "w").write(index)