Просмотр исходного кода

Merge pull request #6405 from k32/sysmon

feat(system_monitor): Add system_monitor application
k32 4 лет назад
Родитель
Сommit
98be2e15b1
4 измененных файлов с 77 добавлено и 0 удалено
  1. 62 0
      apps/emqx_conf/src/emqx_conf_schema.erl
  2. 13 0
      apps/emqx_machine/src/emqx_machine.erl
  3. 1 0
      rebar.config
  4. 1 0
      rebar.config.erl

+ 62 - 0
apps/emqx_conf/src/emqx_conf_schema.erl

@@ -96,6 +96,10 @@ roots() ->
        sc(ref("db"),
           #{ desc => "Settings of the embedded database."
            })}
+    , {"system_monitor",
+       sc(ref("system_monitor"),
+          #{ desc => "Erlang process and application monitoring."
+           })}
     ] ++
     emqx_schema:roots(medium) ++
     emqx_schema:roots(low) ++
@@ -316,6 +320,64 @@ a crash dump
         )}
     ];
 
+fields("system_monitor") ->
+    [ {"top_num_items",
+       sc(non_neg_integer(),
+         #{ mapping => "system_monitor.top_num_items"
+          , default => 10
+          , desc => "The number of top processes per monitoring group"
+          })
+      }
+    , {"top_sample_interval",
+       sc(emqx_schema:duration(),
+         #{ mapping => "system_monitor.top_sample_interval"
+          , default => "2s"
+          , desc => "Specifies how often process top should be collected"
+          })
+      }
+    , {"top_max_procs",
+       sc(non_neg_integer(),
+         #{ mapping => "system_monitor.top_max_procs"
+          , default => 200000
+          , desc => "Stop collecting data when the number of processes exceeds this value"
+          })
+      }
+    , {"db_hostname",
+       sc(string(),
+         #{ mapping => "system_monitor.db_hostname"
+          , desc => "Hostname of the postgres database that collects the data points"
+          })
+      }
+    , {"db_port",
+       sc(integer(),
+         #{ mapping => "system_monitor.db_port"
+          , default => 5432
+          , desc => "Port of the postgres database that collects the data points"
+          })
+      }
+    , {"db_username",
+       sc(string(),
+         #{ mapping => "system_monitor.db_username"
+          , default => "system_monitor"
+          , desc    => "EMQX user name in the postgres database"
+          })
+      }
+    , {"db_password",
+       sc(binary(),
+         #{ mapping => "system_monitor.db_password"
+          , default => "system_monitor_password"
+          , desc    => "EMQX user password in the postgres database"
+          })
+      }
+    , {"db_name",
+       sc(string(),
+         #{ mapping => "system_monitor.db_name"
+          , default => "postgres"
+          , desc    => "Postgres database name"
+          })
+      }
+    ];
+
 fields("db") ->
     [ {"backend",
        sc(hoconsc:enum([mnesia, rlog]),

+ 13 - 0
apps/emqx_machine/src/emqx_machine.erl

@@ -32,6 +32,7 @@ start() ->
             os:set_signal(sigterm, handle) %% default is handle
     end,
     ok = set_backtrace_depth(),
+    start_sysmon(),
     ekka:start(),
     ok = print_otp_version_warning().
 
@@ -54,3 +55,15 @@ print_otp_version_warning() ->
     ?ULOG("WARNING: Running on Erlang/OTP version ~p. Recommended: 23~n",
           [?OTP_RELEASE]).
 -endif. % OTP_RELEASE > 22
+
+start_sysmon() ->
+    case application:get_env(system_monitor, db_hostname) of
+        undefined ->
+            %% If there is no sink for the events, there is no reason
+            %% to run system_monitor_top, ignore it:
+            ok;
+        _ ->
+            application:set_env(system_monitor, callback_mod, system_monitor_pg),
+            _ = application:ensure_all_started(system_monitor, temporary),
+            ok
+    end.

+ 1 - 0
rebar.config

@@ -62,6 +62,7 @@
     , {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.4.3"}}}
     , {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.4"}}}
     , {observer_cli, "1.7.1"} % NOTE: depends on recon 2.5.x
+    , {system_monitor, {git, "https://github.com/klarna-incubator/system_monitor", {tag, "2.2.0"}}}
     , {getopt, "1.0.2"}
     , {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
     , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.0"}}}

+ 1 - 0
rebar.config.erl

@@ -287,6 +287,7 @@ relx_apps(ReleaseType, Edition) ->
     , {emqx_plugin_libs, load}
     , {esasl, load}
     , observer_cli
+    , system_monitor
     , emqx_http_lib
     , emqx_resource
     , emqx_connector