Skip to content

Commit

Permalink
Merge pull request processone#525 from esl/uptime-metric
Browse files Browse the repository at this point in the history
Node uptime metric
  • Loading branch information
ppikula committed Sep 28, 2015
2 parents 4b9498f + 64a2cc2 commit 97fd3e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 9 additions & 1 deletion apps/ejabberd/src/mongoose_metrics.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
get_odbc_data_stats/0,
get_odbc_mam_async_stats/0,
get_dist_data_stats/0,
get_up_time/0,
remove_host_metrics/1,
remove_all_metrics/0]).

Expand Down Expand Up @@ -110,6 +111,10 @@ create_generic_hook_metric(Host, Hook) ->
increment_generic_hook_metric(Host, Hook) ->
do_increment_generic_hook_metric([Host, filter_hook(Hook)]).

-spec get_up_time() -> {value, integer()}.
get_up_time() ->
{value, erlang:round(element(1, erlang:statistics(wall_clock))/1000)}.

do_create_generic_hook_metric({_, skip}) ->
ok;
do_create_generic_hook_metric(MetricName) ->
Expand Down Expand Up @@ -358,7 +363,10 @@ get_histograms(Host) ->
eval, ?EX_EVAL_SINGLE_VALUE}},
{[global, nodeSessionCount],
{function, ejabberd_sm, get_node_sessions_number, [],
eval, ?EX_EVAL_SINGLE_VALUE}}
eval, ?EX_EVAL_SINGLE_VALUE}},
{[global, nodeUpTime],
{function, mongoose_metrics, get_up_time, [],
tagged, [value]}}
]
).

Expand Down
9 changes: 7 additions & 2 deletions test/ejabberd_tests/tests/metrics_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ groups() ->
one_iq_error,
one_presence_error
]},
{global, [], [session_counters]}
{global, [], [session_counters,
node_uptime]}
].

init_per_suite(Config) ->
Expand Down Expand Up @@ -194,7 +195,11 @@ session_counters(Config) ->
3 = fetch_global_counter_value(nodeSessionCount, Config)
end).


node_uptime(Config) ->
X = fetch_global_counter_value(nodeUpTime, Config),
timer:sleep(timer:seconds(1)),
Y = fetch_global_counter_value(nodeUpTime, Config),
true = Y > X.
%%--------------------------------------------------------------------
%% Helpers
%%--------------------------------------------------------------------
Expand Down

0 comments on commit 97fd3e7

Please sign in to comment.