Exemplo n.º 1
0
def ajax_set_snapin_site():
    html.set_output_format("json")
    ident = html.request.var("ident")
    if ident not in snapin_registry:
        raise MKUserError(None, _("Invalid ident"))

    site = html.request.var("site")
    site_choices = dict([("", _("All sites"))] + config.site_choices())

    if site not in site_choices:
        raise MKUserError(None, _("Invalid site"))

    snapin_sites = config.user.load_file("sidebar_sites", {}, lock=True)
    snapin_sites[ident] = site
    config.user.save_file("sidebar_sites", snapin_sites)
Exemplo n.º 2
0
    def show(self):
        only_sites = snapin_site_choice("performance", config.site_choices())

        def write_line(left, right, show_more):
            html.open_tr(class_="show_more_mode" if show_more else "basic")
            html.td(left, class_="left")
            html.td(html.render_strong(right), class_="right")
            html.close_tr()

        html.open_table(class_=["content_center", "performance"])

        try:
            sites.live().set_only_sites(only_sites)
            data = sites.live().query(
                "GET status\nColumns: service_checks_rate host_checks_rate "
                "external_commands_rate connections_rate forks_rate "
                "log_messages_rate cached_log_messages\n")
        finally:
            sites.live().set_only_sites(None)

        for what, show_more, col, format_str in \
            [("Service checks",         False, 0, "%.2f/s"),
             ("Host checks",            False, 1, "%.2f/s"),
             ("External commands",      True, 2, "%.2f/s"),
             ("Livestatus-conn.",       True, 3, "%.2f/s"),
             ("Process creations",      True, 4, "%.2f/s"),
             ("New log messages",       True, 5, "%.2f/s"),
             ("Cached log messages",    True, 6, "%d")]:
            write_line(what + ":",
                       format_str % sum(row[col] for row in data),
                       show_more=show_more)

        if only_sites is None and len(config.allsites()) == 1:
            try:
                data = sites.live().query(
                    "GET status\nColumns: external_command_buffer_slots "
                    "external_command_buffer_max\n")
            finally:
                sites.live().set_only_sites(None)
            size = sum([row[0] for row in data])
            maxx = sum([row[1] for row in data])
            write_line(_('Com. buf. max/total'),
                       "%d / %d" % (maxx, size),
                       show_more=True)

        html.close_table()