From 4e055a949569b1c14b19a02db5d2ea80212fbc00 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Fri, 25 Sep 2015 15:39:19 +0200 Subject: [PATCH 1/2] add node uptime metric --- apps/ejabberd/src/mongoose_metrics.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/ejabberd/src/mongoose_metrics.erl b/apps/ejabberd/src/mongoose_metrics.erl index 63c5c09df28..ae4df3c2270 100644 --- a/apps/ejabberd/src/mongoose_metrics.erl +++ b/apps/ejabberd/src/mongoose_metrics.erl @@ -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]). @@ -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) -> @@ -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]}} ] ). From 64a2cc26c27431fe221c5840f0b0d0ed90ab75e4 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 28 Sep 2015 10:01:44 +0200 Subject: [PATCH 2/2] test nodeUpTime metric via HTTP API --- test/ejabberd_tests/tests/metrics_api_SUITE.erl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/ejabberd_tests/tests/metrics_api_SUITE.erl b/test/ejabberd_tests/tests/metrics_api_SUITE.erl index e31afe3c55b..15711f0fb57 100644 --- a/test/ejabberd_tests/tests/metrics_api_SUITE.erl +++ b/test/ejabberd_tests/tests/metrics_api_SUITE.erl @@ -38,7 +38,8 @@ groups() -> one_iq_error, one_presence_error ]}, - {global, [], [session_counters]} + {global, [], [session_counters, + node_uptime]} ]. init_per_suite(Config) -> @@ -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 %%--------------------------------------------------------------------