Index: web/ejabberd_web_admin.erl =================================================================== --- web/ejabberd_web_admin.erl (revisiĆ³n: 487) +++ web/ejabberd_web_admin.erl (copia de trabajo) @@ -905,7 +905,10 @@ path = ["stats"], q = Query, lang = Lang} = Request) -> - Res = get_stats(Host, Lang), + Res = case whereis(ejabberd_mod_statsdx) of + undefined -> get_stats(Host, Lang); + _ -> get_statsdx(Host, Lang) + end, make_xhtml([?XCT("h1", "ejabberd stats")] ++ Res, Host, Lang); process_admin(Host, @@ -1397,6 +1400,164 @@ ])]. +get_statsdx(global, Lang) -> + [ + ?XC("h3", "Accounts"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "registeredusers") + ]) + ]), + ?XC("h3", "Roster"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "totalrosteritems"), + do_stat(global, Lang, "meanitemsinroster") + ]) + ]), + ?XC("h3", "Users"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "authusers"), + do_stat(global, Lang, "onlineusers"), + do_stat(global, Lang, "offlinemsg"), + do_stat(global, Lang, "vcards") + ]) + ]), + ?XC("h3", "MUC"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "totalmucrooms"), + do_stat(global, Lang, "permmucrooms"), + do_stat(global, Lang, "regmucrooms") + ]) + ]), + ?XC("h3", "Pub/Sub"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "regpubsubnodes") + ]) + ]), + ?XC("h3", "IRC"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "ircconns") + ]) + ]), + ?XC("h3", "Ratios"), + ?XAE("table", [], + [?XE("tbody", [ + ]) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("client")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "client", server) + ) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("os")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "os", server) + ) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("client") ++ "/" ++ get_stat_n("os")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "client_os", server) + ) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("languages")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "languages", server) + ) + ]) + ]; + +get_statsdx(Host, Lang) -> + [ + ?XC("h2", Host), + ?XC("h3", "Accounts"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "registeredusers", Host) + ]) + ]), + ?XC("h3", "Roster"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "totalrosteritems", Host), + do_stat(global, Lang, "meanitemsinroster", Host) + ]) + ]), + ?XC("h3", "Users"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "authusers", Host), + do_stat(global, Lang, "onlineusers", Host), + do_stat(global, Lang, "offlinemsg", Host), + do_stat(global, Lang, "vcards", Host) + ]) + ]), + ?XC("h3", "Connections"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "s2sconnections", Host) + ]) + ]), + ?XC("h3", "MUC"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "totalmucrooms", Host), + do_stat(global, Lang, "permmucrooms", Host), + do_stat(global, Lang, "regmucrooms", Host) + ]) + ]), + ?XC("h3", "IRC"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "ircconns", Host) + ]) + ]), + %?XC("h3", "Pub/Sub"), + %?XAE("table", [], + % [?XE("tbody", [ + % do_stat(global, Lang, "regpubsubnodes", Host) + % ]) + %]), + ?XC("h3", "Ratios"), + ?XAE("table", [], + [?XE("tbody", [ + ]) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("client")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "client", Host) + ) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("os")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "os", Host) + ) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("client") ++ "/" ++ get_stat_n("os")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "client_os", Host) + ) + ]), + ?XC("h3", "Sessions: " ++ get_stat_n("languages")), + ?XAE("table", [], + [?XE("tbody", + do_stat_table(global, Lang, "languages", Host) + ) + ]) + ]. + + list_online_users(Host, _Lang) -> Users = [{S, U} || {U, S, R} <- ejabberd_sm:get_vh_session_list(Host)], SUsers = lists:usort(Users), @@ -2013,6 +2174,12 @@ ]; get_node(global, Node, ["stats"], Query, Lang) -> + Res = case whereis(ejabberd_mod_statsdx) of + undefined -> get_node(global, Node, ["statslight"], Query, Lang); + _ -> get_node(global, Node, ["statsdx"], Query, Lang) + end; + +get_node(global, Node, ["statslight"], Query, Lang) -> UpTime = rpc:call(Node, erlang, statistics, [wall_clock]), UpTimeS = io_lib:format("~.3f", [element(1, UpTime)/1000]), CPUTime = rpc:call(Node, erlang, statistics, [runtime]), @@ -2055,10 +2222,125 @@ ]) ])]; +get_node(global, Node, ["statsdx"], Query, Lang) -> + TransactionsCommited = + rpc:call(Node, mnesia, system_info, [transaction_commits]), + TransactionsAborted = + rpc:call(Node, mnesia, system_info, [transaction_failures]), + TransactionsRestarted = + rpc:call(Node, mnesia, system_info, [transaction_restarts]), + TransactionsLogged = + rpc:call(Node, mnesia, system_info, [transaction_log_writes]), + + [?XC("h1", io_lib:format(?T("~p statistics"), [Node])), + ?XC("h3", "Connections"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(global, Lang, "authusers"), + do_stat(Node, Lang, "httppollusers"), + do_stat(Node, Lang, "s2sconnections"), + do_stat(Node, Lang, "s2sservers") + ]) + ]), + ?XC("h3", "Erlang"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(Node, Lang, "operatingsystem"), + do_stat(Node, Lang, "erlangmachine"), + do_stat(Node, Lang, "erlangmachinetarget"), + do_stat(Node, Lang, "maxprocallowed"), + do_stat(Node, Lang, "procqueue"), + do_stat(Node, Lang, "totalerlproc") + ]) + ]), + ?XC("h3", "Times"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(Node, Lang, "uptime"), + do_stat(Node, Lang, "uptimehuman"), + do_stat(Node, Lang, "lastrestart"), + do_stat(Node, Lang, "cputime") + ]) + ]), + ?XC("h3", "CPU"), + ?XAE("table", [], + [?XE("tbody", [ + do_stat(Node, Lang, "cpu_avg1"), + do_stat(Node, Lang, "cpu_avg5"), + do_stat(Node, Lang, "cpu_avg15"), + do_stat(Node, Lang, "cpu_nprocs")%, + %do_stat(Node, Lang, "cpu_util_user"), + %do_stat(Node, Lang, "cpu_nice_user"), + %do_stat(Node, Lang, "cpu_kernel"), + %do_stat(Node, Lang, "cpu_idle"), + %do_stat(Node, Lang, "cpu_wait") + ]) + ]), + %?XC("h3", "RAM"), + %?XAE("table", [], + % [?XE("tbody", [ + %do_stat(Node, Lang, "memsup_system"), + %do_stat(Node, Lang, "memsup_free"), + %do_stat(Node, Lang, "reductions") + % ]) + % ]), + ?XC("h3", "Database"), + ?XAE("table", [], + [?XE("tbody", [ + ?XE("tr", [?XCT("td", "Transactions commited"), + ?XAC("td", [{"class", "alignright"}], + integer_to_list(TransactionsCommited))]), + ?XE("tr", [?XCT("td", "Transactions aborted"), + ?XAC("td", [{"class", "alignright"}], + integer_to_list(TransactionsAborted))]), + ?XE("tr", [?XCT("td", "Transactions restarted"), + ?XAC("td", [{"class", "alignright"}], + integer_to_list(TransactionsRestarted))]), + ?XE("tr", [?XCT("td", "Transactions logged"), + ?XAC("td", [{"class", "alignright"}], + integer_to_list(TransactionsLogged))]) + ]) + ])]; + get_node(Host, Node, NPath, Query, Lang) -> [?XCT("h1", "Not found")]. +do_table_element(Lang, L, N) -> + ?XE("tr", [ + ?XCT("td", L), + ?XAC("td", [{"class", "alignright"}], + N) + ]). +do_stat_table(global, Lang, Stat, Host) -> + Os = mod_statsdx:get(global, [Stat, Host]), + lists:map( + fun({L, N}) -> + do_table_element(Lang, L, io_lib:format("~p", [N])) + end, + Os + ). + +do_stat(Node, Lang, Stat) -> + ?XE("tr", [ + ?XCT("td", get_stat_n(Stat)), + ?XAC("td", [{"class", "alignright"}], + get_stat_v(Node, [Stat]))]). + +do_stat(Node, Lang, Stat, Host) -> + %[Res] = get_stat_v(Node, [Stat, Host]), + %do_table_element(Lang, get_stat_n(Stat), Res). + do_table_element(Lang, get_stat_n(Stat), get_stat_v(Node, [Stat, Host])). + +% Get a stat name +get_stat_n(Stat) -> + mod_statsdx:get(foo, [Stat, title]). +% Get a stat value +get_stat_v(Node, Stat) -> get_stat_v2(mod_statsdx:get(Node, Stat)). +get_stat_v2(Value) when is_list(Value) -> Value; +get_stat_v2(Value) when is_float(Value) -> io_lib:format("~.4f", [Value]); +get_stat_v2(Value) -> io_lib:format("~p", [Value]). + node_parse_query(Node, Query) -> case lists:keysearch("restart", 1, Query) of {value, _} ->