From 2242cd068c899d66e3b8614ae12b2d190479c7b5 Mon Sep 17 00:00:00 2001 From: Pawel Pikula Date: Thu, 6 Aug 2015 12:36:10 +0200 Subject: [PATCH 1/7] move reporters configuration to app.config file The idea here is to allow using all available exomoter options - we can do this by specifing them in the app.config file. User can start as many reporterts as it want and mim just iterates over active reporters and adds subscripions for them --- apps/ejabberd/src/ejabberd_app.erl | 15 ++++++++++++++- rel/files/app.config | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/apps/ejabberd/src/ejabberd_app.erl b/apps/ejabberd/src/ejabberd_app.erl index 9deb3100ed1..2dbce74c191 100644 --- a/apps/ejabberd/src/ejabberd_app.erl +++ b/apps/ejabberd/src/ejabberd_app.erl @@ -246,4 +246,17 @@ init_metrics() -> lists:foreach( fun(Host) -> mongoose_metrics:init_predefined_host_metrics(Host) - end, ?MYHOSTS). \ No newline at end of file + end, ?MYHOSTS), + Reporters = exometer_report:list_reporters(), + lists:foreach( + fun({Name, _Reporter}) -> + Interval = application:get_env(exometer, mongooseim_interval, 5000), + start_subscriptions(Name, Interval) + end, Reporters). + +start_subscriptions(Reporter, Interval) -> + mongoose_metrics:start_global_metrics_subscriptions(Reporter, Interval), + lists:foreach( + fun(Host) -> + mongoose_metrics:start_host_metrics_subscriptions(Reporter, Host, Interval) + end, ?MYHOSTS). diff --git a/rel/files/app.config b/rel/files/app.config index 33fec097cdc..580d3791eb3 100644 --- a/rel/files/app.config +++ b/rel/files/app.config @@ -6,6 +6,20 @@ {lager_file_backend, [{file, "log/ejabberd.log"}, {level, info}, {size, 2097152}, {date, "$D0"}, {count, 5}]} ]} ]} +%{exometer, [ +% {mongooseim_interval, 6000}, +% {report, [ +% {reporters, [ +% {exometer_report_graphite, [ +% {prefix, "mongooseim"}, +% {connect_timeout, 5000}, +% {host, "127.0.0.1"}, +% {port, 2003}, +% {api_key, ""} +% ]} +% ]} +% ]} +% ]} ]. %% vim: filetype=erlang From f9a5b479d1905d3e41ffd862e3a27d58356edd5f Mon Sep 17 00:00:00 2001 From: Pawel Pikula Date: Thu, 6 Aug 2015 14:45:19 +0200 Subject: [PATCH 2/7] remove unnecessary functions --- apps/ejabberd/src/ejabberd_app.erl | 2 +- apps/ejabberd/src/mongoose_metrics.erl | 63 +++++--------------------- 2 files changed, 12 insertions(+), 53 deletions(-) diff --git a/apps/ejabberd/src/ejabberd_app.erl b/apps/ejabberd/src/ejabberd_app.erl index 2dbce74c191..a2271041f92 100644 --- a/apps/ejabberd/src/ejabberd_app.erl +++ b/apps/ejabberd/src/ejabberd_app.erl @@ -249,7 +249,7 @@ init_metrics() -> end, ?MYHOSTS), Reporters = exometer_report:list_reporters(), lists:foreach( - fun({Name, _Reporter}) -> + fun({Name, _ReporterPid}) -> Interval = application:get_env(exometer, mongooseim_interval, 5000), start_subscriptions(Name, Interval) end, Reporters). diff --git a/apps/ejabberd/src/mongoose_metrics.erl b/apps/ejabberd/src/mongoose_metrics.erl index 5a19541233e..ce7ea8f4a99 100644 --- a/apps/ejabberd/src/mongoose_metrics.erl +++ b/apps/ejabberd/src/mongoose_metrics.erl @@ -19,8 +19,6 @@ %% API -export([update/2, - start_graphite_reporter/1, - start_graphite_reporter/2, start_host_metrics_subscriptions/3, start_vm_metrics_subscriptions/2, start_global_metrics_subscriptions/2, @@ -47,33 +45,20 @@ update(Name, Change) when is_tuple(Name)-> update(Name, Change) -> exometer:update(Name, Change). -start_graphite_reporter(GraphiteHost) -> - start_graphite_reporter(GraphiteHost, []). -start_graphite_reporter(GraphiteHost, Opts) -> - GraphiteOpts = [{prefix, "exometer." ++ atom_to_list(node())}, - {host, GraphiteHost}] - ++ merge_opts(Opts), - case exometer_report:add_reporter(exometer_report_graphite, GraphiteOpts) of - ok -> - {ok, exometer_report_graphite}; - Error -> - Error - end. - start_host_metrics_subscriptions(Reporter, Host, Interval) -> - do_start_metrics_subscriptions(check_reporter(Reporter), Interval, [Host]). + do_start_metrics_subscriptions(Reporter, Interval, [Host]). start_vm_metrics_subscriptions(Reporter, Interval) -> - do_start_vm_metrics_subscriptions(check_reporter(Reporter), Interval). + do_start_vm_metrics_subscriptions(Reporter, Interval). start_global_metrics_subscriptions(Reporter, Interval) -> - do_start_global_metrics_subscriptions(check_reporter(Reporter), Interval). + do_start_global_metrics_subscriptions(Reporter, Interval). start_data_metrics_subscriptions(Reporter, Interval) -> - do_start_metrics_subscriptions(check_reporter(Reporter), Interval, [data]). + do_start_metrics_subscriptions(Reporter, Interval, [data]). start_backend_metrics_subscriptions(Reporter, Interval) -> - do_start_metrics_subscriptions(check_reporter(Reporter), Interval, [backends]). + do_start_metrics_subscriptions(Reporter, Interval, [backends]). get_host_metric_names(Host) -> [MetricName || {[_Host, MetricName | _], _, _} <- exometer:find_entries([Host])]. @@ -401,34 +386,17 @@ get_vm_stats() -> get_counters(Host, Counters) -> [{Host, Counter} || Counter <- Counters]. -check_reporter(Reporter) -> - Reporters = exometer_report:list_reporters(), - case lists:keyfind(Reporter, 1, Reporters) of - {Reporter, _} -> - {ok, Reporter}; - _ -> - {error, {no_such_reporter}} - end. - - -do_start_vm_metrics_subscriptions({ok, Reporter}, Interval) -> +do_start_vm_metrics_subscriptions(Reporter, Interval) -> [exometer_report:subscribe(Reporter, Metric, DataPoints, Interval) - || {Metric, _, DataPoints} <- get_vm_stats()]; -do_start_vm_metrics_subscriptions(Error, _) -> - Error. + || {Metric, _, DataPoints} <- get_vm_stats()]. -do_start_global_metrics_subscriptions({ok, Reporter}, Interval) -> +do_start_global_metrics_subscriptions(Reporter, Interval) -> [exometer_report:subscribe(Reporter, Metric, default, Interval) - || {Metric, _} <- ?GLOBAL_COUNTERS]; -do_start_global_metrics_subscriptions(Error, _) -> - Error. + || {Metric, _} <- ?GLOBAL_COUNTERS]. -do_start_metrics_subscriptions({ok, Reporter}, Interval, MetricPrefix) -> +do_start_metrics_subscriptions(Reporter, Interval, MetricPrefix) -> [subscribe_metric(Reporter, Metric, Interval) - || Metric <- exometer:find_entries(MetricPrefix)]; -do_start_metrics_subscriptions(Error, _, _) -> - Error. - + || Metric <- exometer:find_entries(MetricPrefix)]. subscribe_metric(Reporter, {Name, counter, _}, Interval) -> exometer_report:subscribe(Reporter, Name, [value], Interval); @@ -437,12 +405,3 @@ subscribe_metric(Reporter, {Name, histogram, _}, Interval) -> subscribe_metric(Reporter, {Name, _, _}, Interval) -> exometer_report:subscribe(Reporter, Name, default, Interval). -merge_opts(Opts) -> - Defaults = [{connect_timeout, 5000}, - {port, 2003}, - {api_key, ""}], - - MergeFun = fun(_, _, V2) -> V2 end, - orddict:to_list(orddict:merge(MergeFun, - orddict:from_list(Defaults), - orddict:from_list(Opts))). \ No newline at end of file From 0f481e3fa2318aa6b2f013aca279b552d797f404 Mon Sep 17 00:00:00 2001 From: Pawel Pikula Date: Thu, 6 Aug 2015 14:56:42 +0200 Subject: [PATCH 3/7] move metrics initialization to mongoose_metrics --- apps/ejabberd/src/ejabberd_app.erl | 22 +--------------------- apps/ejabberd/src/mongoose_metrics.erl | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/apps/ejabberd/src/ejabberd_app.erl b/apps/ejabberd/src/ejabberd_app.erl index a2271041f92..11b579d7041 100644 --- a/apps/ejabberd/src/ejabberd_app.erl +++ b/apps/ejabberd/src/ejabberd_app.erl @@ -58,7 +58,7 @@ start(normal, _Args) -> maybe_start_alarms(), connect_nodes(), {ok, _} = Sup = ejabberd_sup:start_link(), - init_metrics(), + mongoose_metrics:init(), ejabberd_system_monitor:add_handler(), ejabberd_rdbms:start(), ejabberd_auth:start(), @@ -240,23 +240,3 @@ load_drivers([Driver | Rest]) -> [erl_ddll:format_error(Reason)]), exit({driver_loading_failed, Driver, Reason}) end. - -init_metrics() -> - mongoose_metrics:create_global_metrics(), - lists:foreach( - fun(Host) -> - mongoose_metrics:init_predefined_host_metrics(Host) - end, ?MYHOSTS), - Reporters = exometer_report:list_reporters(), - lists:foreach( - fun({Name, _ReporterPid}) -> - Interval = application:get_env(exometer, mongooseim_interval, 5000), - start_subscriptions(Name, Interval) - end, Reporters). - -start_subscriptions(Reporter, Interval) -> - mongoose_metrics:start_global_metrics_subscriptions(Reporter, Interval), - lists:foreach( - fun(Host) -> - mongoose_metrics:start_host_metrics_subscriptions(Reporter, Host, Interval) - end, ?MYHOSTS). diff --git a/apps/ejabberd/src/mongoose_metrics.erl b/apps/ejabberd/src/mongoose_metrics.erl index ce7ea8f4a99..906e400965a 100644 --- a/apps/ejabberd/src/mongoose_metrics.erl +++ b/apps/ejabberd/src/mongoose_metrics.erl @@ -18,7 +18,8 @@ -include("ejabberd.hrl"). %% API --export([update/2, +-export([init/0, + update/2, start_host_metrics_subscriptions/3, start_vm_metrics_subscriptions/2, start_global_metrics_subscriptions/2, @@ -39,6 +40,20 @@ remove_host_metrics/1, remove_all_metrics/0]). +-spec init() -> ok. +init() -> + create_global_metrics(), + lists:foreach( + fun(Host) -> + mongoose_metrics:init_predefined_host_metrics(Host) + end, ?MYHOSTS), + Reporters = exometer_report:list_reporters(), + lists:foreach( + fun({Name, _ReporterPid}) -> + Interval = application:get_env(exometer, mongooseim_interval, 5000), + subscribe_to_all(Name, Interval) + end, Reporters). + -spec update({term(), term()}, term()) -> no_return(). update(Name, Change) when is_tuple(Name)-> update(tuple_to_list(Name), Change); @@ -405,3 +420,9 @@ subscribe_metric(Reporter, {Name, histogram, _}, Interval) -> subscribe_metric(Reporter, {Name, _, _}, Interval) -> exometer_report:subscribe(Reporter, Name, default, Interval). +subscribe_to_all(Reporter, Interval) -> + start_global_metrics_subscriptions(Reporter, Interval), + lists:foreach( + fun(Host) -> + start_host_metrics_subscriptions(Reporter, Host, Interval) + end, ?MYHOSTS). From 44ac2a2fecf69069c28b537c5392ef33c8fe0886 Mon Sep 17 00:00:00 2001 From: Pawel Pikula Date: Fri, 7 Aug 2015 10:29:11 +0200 Subject: [PATCH 4/7] set default reporting rate to 60s --- apps/ejabberd/src/mongoose_metrics.erl | 2 +- rel/files/app.config | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/ejabberd/src/mongoose_metrics.erl b/apps/ejabberd/src/mongoose_metrics.erl index 906e400965a..84db8a9ddc4 100644 --- a/apps/ejabberd/src/mongoose_metrics.erl +++ b/apps/ejabberd/src/mongoose_metrics.erl @@ -50,7 +50,7 @@ init() -> Reporters = exometer_report:list_reporters(), lists:foreach( fun({Name, _ReporterPid}) -> - Interval = application:get_env(exometer, mongooseim_interval, 5000), + Interval = application:get_env(exometer, mongooseim_report_interval, 60000), subscribe_to_all(Name, Interval) end, Reporters). diff --git a/rel/files/app.config b/rel/files/app.config index 580d3791eb3..402a576c4f8 100644 --- a/rel/files/app.config +++ b/rel/files/app.config @@ -7,7 +7,7 @@ ]} ]} %{exometer, [ -% {mongooseim_interval, 6000}, +% {mongooseim_report_interval, 60000}, %% 60 seconds % {report, [ % {reporters, [ % {exometer_report_graphite, [ From 77552bcfca6e125f1593b41c1fca2b69161c5e49 Mon Sep 17 00:00:00 2001 From: Pawel Pikula Date: Fri, 7 Aug 2015 11:06:12 +0200 Subject: [PATCH 5/7] [skip ci] remove references to mod_rest and folsom --- doc/README.md | 2 +- doc/advanced-configuration/Listener-modules.md | 2 +- doc/modules/mod_metrics.md | 12 ------------ .../Logging-&-monitoring.md | 6 ++---- mkdocs.yml | 1 - 5 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 doc/modules/mod_metrics.md diff --git a/doc/README.md b/doc/README.md index db0f73e94cc..43c2c162e62 100644 --- a/doc/README.md +++ b/doc/README.md @@ -18,6 +18,6 @@ * [Reloading configuration on a running system](operation-and-maintenance/Reloading-configuration-on-a-running-system.md) * For developers * [Hooks and handlers](developers-guide/Hooks-and-handlers.md) - * [Folsom Metrics](developers-guide/REST-interface-to-metrics.md) + * [REST Interface to Metrics](developers-guide/REST-interface-to-metrics.md) * [mod_amp developer's guide](developers-guide/mod_amp_developers_guide.md) diff --git a/doc/advanced-configuration/Listener-modules.md b/doc/advanced-configuration/Listener-modules.md index 1a16572019a..f6566384956 100644 --- a/doc/advanced-configuration/Listener-modules.md +++ b/doc/advanced-configuration/Listener-modules.md @@ -39,7 +39,7 @@ Currently it is not possible to use different ports e.g. for BOSH and Websockets * `modules` (list of tuples: `{Host, Path, Modules}`) - List of enabled HTTP-based modules. `"_"` equals any host. * `mod_bosh` - BOSH connections handler. Default declaration: `{"_", "/http-bind", mod_bosh}` * `mod_websockets` - Websocket connections, both [old](http://xmpp.org/extensions/xep-0206.html) and [new](http://datatracker.ietf.org/doc/draft-ietf-xmpp-websocket/?include_text=1) type. Default declaration: `{"_", "/ws-xmpp", mod_websockets}` - * `mod_metrics` - REST API for accessing internal MongooseIM metrics. Please refer to [REST interface to metrics](../developers-guide/REST-interface-to-metrics.md) for more information. Default declaration: `{"localhost", "/metrics", mod_metrics}`. + * `mongoose_api` - REST API for accessing internal MongooseIM metrics. Please refer to [REST interface to metrics](../developers-guide/REST-interface-to-metrics.md) for more information. Default declaration: `{"localhost", "/api", mongoose_api, [{handlers, [mongoose_api_metrics]}]}`. ## ejabberd_s2s_in diff --git a/doc/modules/mod_metrics.md b/doc/modules/mod_metrics.md deleted file mode 100644 index dbd6cebd0cc..00000000000 --- a/doc/modules/mod_metrics.md +++ /dev/null @@ -1,12 +0,0 @@ -### Module Description -Adding this module will enable gathering various XMPP-related statistics. The complete list can be fetched with HTTP GET request to metrics URL (see [`listen` section of `ejabberd.cfg`](wiki/Listener-modules)). They are also listed in `[MongooseIM root]/apps/ejabberd/src/mod_metrics.erl`, line 50. - -Please also check [metrics wiki page](REST-interface-to-folsom-metrics) for more information. - -### Options - -none - -### Example configuration - -` {mod_metrics, []} ` \ No newline at end of file diff --git a/doc/operation-and-maintenance/Logging-&-monitoring.md b/doc/operation-and-maintenance/Logging-&-monitoring.md index cb50a2f7afa..6c46cec1deb 100644 --- a/doc/operation-and-maintenance/Logging-&-monitoring.md +++ b/doc/operation-and-maintenance/Logging-&-monitoring.md @@ -33,14 +33,12 @@ To monitor MongooseIM during load testing we recommend the following open source - Graphite (http://graphite.wikidot.com/) is used for data presentation - collectd (http://collectd.org/) is a daemon running on monitored nodes capturing data related to CPU and Memory usage, IO etc. -### mod_metrics +### mod_api_metrics It provides REST interface for Mongoose's metrics, so it can be easily integrated with other services. -You can read more about it here: - -https://github.com/esl/MongooseIM/wiki/REST-interface-to-folsom-metrics +You can read more about it here: [REST interface to metrics](/developers-guide/REST-interface-to-metrics) ### Wombat OAM diff --git a/mkdocs.yml b/mkdocs.yml index dc2cada8d9b..f9b4361d1cb 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -25,7 +25,6 @@ pages: - 'mod_disco': 'modules/mod_disco.md' - 'mod_last': 'modules/mod_last.md' - 'mod_mam': 'modules/mod_mam.md' - - 'mod_metrics': 'modules/mod_metrics.md' - 'mod_muc': 'modules/mod_muc.md' - 'mod_muc_log': 'modules/mod_muc_log.md' - 'mod_offline': 'modules/mod_offline.md' From 1dbc9d3e58d457ad144dc5b25f713775d26faad8 Mon Sep 17 00:00:00 2001 From: Pawel Pikula Date: Fri, 7 Aug 2015 11:41:20 +0200 Subject: [PATCH 6/7] [skip ci] add docs about exometer reporters --- .../Logging-&-monitoring.md | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/doc/operation-and-maintenance/Logging-&-monitoring.md b/doc/operation-and-maintenance/Logging-&-monitoring.md index 6c46cec1deb..63024bc67c0 100644 --- a/doc/operation-and-maintenance/Logging-&-monitoring.md +++ b/doc/operation-and-maintenance/Logging-&-monitoring.md @@ -2,10 +2,10 @@ Logs --- It is a good idea to store logs in one centralized place when working in a clustered environment. -MongooseIM uses Lager - the logging framework. Its backend can be easy replaced. +MongooseIM uses Lager - the logging framework. Its backend can be easily replaced. Some of the recommended backends are: -- https://github.com/basho/lager_syslog to use syslog and +- https://github.com/basho/lager_syslog to use syslog and - https://github.com/mhald/lager_logstash_backend for logstash (http://logstash.net/). To change the backend you have to edit `rel/files/app.config`. Before that you need @@ -43,5 +43,49 @@ You can read more about it here: [REST interface to metrics](/developers-guide/R ### Wombat OAM WombatOAM is an operations and maintenance framework for Erlang based systems. Its Web Dashboard displays this data in an aggregated manner and provides interfaces to feed the data to other OAM tools such as Graphite, Nagios or Zabbix. + For more information see: -https://www.erlang-solutions.com/products/wombat \ No newline at end of file +https://www.erlang-solutions.com/products/wombat + +### Built-in Exometer reporters + +MongooseIM uses the Exometer libary for collecting the metrics. Exometer has many +build-in reporters that can send metrics to external services like: + +* graphite +* amqp +* statsd +* snmp +* opentsdb + +It is possible to enable them in Moongoose via the `app.config` file. The file sits next +to the `ejabberd.cfg` file and both files are located in the `rel/files` and `_REL_DIR_/etc` directories. +For more details, please visit the Exometer's project page: [ExometerProject](https://github.com/Feuerlabs/exometer). + +**Note that we are using the 1.1 version.** + +Below you can find sample configuration, it setups graphite reporter which connects +to graphite running on localhost. + +You can see an additional option not listed in the Exometer docs - `mongooseim_report_interval`. +That option sets metrics resolution - in other words: how often Exometer gathers and sends metrics +throught reporters. By default that is 60 seconds. + +```erl +... +{exometer, [ + {mongooseim_report_interval, 60000}, %% 60 seconds + {report, [ + {reporters, [ + {exometer_report_graphite, [ + {prefix, "mongooseim"}, + {connect_timeout, 5000}, + {host, "127.0.0.1"}, + {port, 2003}, + {api_key, ""} + ]} + ]} + ]} + ]} +... +``` From c58779a39abc764f3eef54e383ba78352b0b1377 Mon Sep 17 00:00:00 2001 From: Pawel Pikula Date: Fri, 7 Aug 2015 14:37:38 +0200 Subject: [PATCH 7/7] [skip ci] fix typo throught -> through --- doc/operation-and-maintenance/Logging-&-monitoring.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/operation-and-maintenance/Logging-&-monitoring.md b/doc/operation-and-maintenance/Logging-&-monitoring.md index 63024bc67c0..dbce87e664a 100644 --- a/doc/operation-and-maintenance/Logging-&-monitoring.md +++ b/doc/operation-and-maintenance/Logging-&-monitoring.md @@ -69,7 +69,7 @@ to graphite running on localhost. You can see an additional option not listed in the Exometer docs - `mongooseim_report_interval`. That option sets metrics resolution - in other words: how often Exometer gathers and sends metrics -throught reporters. By default that is 60 seconds. +through reporters. By default that is 60 seconds. ```erl ...