]> granicus.if.org Git - ejabberd/commitdiff
Ignore offline sessions in statistics
authorHolger Weiss <holger@zedat.fu-berlin.de>
Tue, 11 Oct 2016 20:20:22 +0000 (22:20 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Tue, 11 Oct 2016 20:20:22 +0000 (22:20 +0200)
Offline sessions should not be counted when reporting the number of
connected resources.

Apart from that, this number is now also reported when using a
non-default session management backend.

src/ejabberd_web_admin.erl
src/mod_stats.erl

index 184f9775b23c3bf608d395219cb7f8d356ae2f93..fb57fa56003b352d276a98611415951326584689 100644 (file)
@@ -1552,7 +1552,7 @@ su_to_list({Server, User}) ->
 %%%% get_stats
 
 get_stats(global, Lang) ->
-    OnlineUsers = mnesia:table_info(session, size),
+    OnlineUsers = ejabberd_sm:connected_users_number(),
     RegisteredUsers = lists:foldl(fun (Host, Total) ->
                                          ejabberd_auth:get_vh_registered_users_number(Host)
                                            + Total
@@ -2178,7 +2178,7 @@ get_node(global, Node, [<<"stats">>], _Query, Lang) ->
     CPUTime = ejabberd_cluster:call(Node, erlang, statistics, [runtime]),
     CPUTimeS = list_to_binary(io_lib:format("~.3f",
                                             [element(1, CPUTime) / 1000])),
-    OnlineUsers = mnesia:table_info(session, size),
+    OnlineUsers = ejabberd_sm:connected_users_number(),
     TransactionsCommitted = ejabberd_cluster:call(Node, mnesia,
                                     system_info, [transaction_commits]),
     TransactionsAborted = ejabberd_cluster:call(Node, mnesia,
index 99059839a085ae7cfd850de326f6388fb4f8b8f6..66bbb5b5bb42be5972906dbd8f1e5b4c8edae776 100644 (file)
@@ -161,13 +161,8 @@ get_local_stat(Server, [], Name)
     end;
 get_local_stat(_Server, [], Name)
     when Name == <<"users/all-hosts/online">> ->
-    case catch mnesia:table_info(session, size) of
-      {'EXIT', _Reason} ->
-         ?STATERR(<<"500">>, <<"Internal Server Error">>);
-      Users ->
-         ?STATVAL((iolist_to_binary(integer_to_list(Users))),
-                  <<"users">>)
-    end;
+    Users = ejabberd_sm:connected_users_number(),
+    ?STATVAL((iolist_to_binary(integer_to_list(Users))), <<"users">>);
 get_local_stat(_Server, [], Name)
     when Name == <<"users/all-hosts/total">> ->
     NumUsers = lists:foldl(fun (Host, Total) ->