Merge pull request #6405 from k32/sysmon

feat(system_monitor): Add system_monitor application
This commit is contained in:
k32 2021-12-09 10:22:40 +01:00 committed by GitHub
commit 98be2e15b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 0 deletions

View File

@ -96,6 +96,10 @@ roots() ->
sc(ref("db"), sc(ref("db"),
#{ desc => "Settings of the embedded database." #{ 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(medium) ++
emqx_schema:roots(low) ++ 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") -> fields("db") ->
[ {"backend", [ {"backend",
sc(hoconsc:enum([mnesia, rlog]), sc(hoconsc:enum([mnesia, rlog]),

View File

@ -32,6 +32,7 @@ start() ->
os:set_signal(sigterm, handle) %% default is handle os:set_signal(sigterm, handle) %% default is handle
end, end,
ok = set_backtrace_depth(), ok = set_backtrace_depth(),
start_sysmon(),
ekka:start(), ekka:start(),
ok = print_otp_version_warning(). ok = print_otp_version_warning().
@ -54,3 +55,15 @@ print_otp_version_warning() ->
?ULOG("WARNING: Running on Erlang/OTP version ~p. Recommended: 23~n", ?ULOG("WARNING: Running on Erlang/OTP version ~p. Recommended: 23~n",
[?OTP_RELEASE]). [?OTP_RELEASE]).
-endif. % OTP_RELEASE > 22 -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.

View File

@ -62,6 +62,7 @@
, {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.4.3"}}} , {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.4.3"}}}
, {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.4"}}} , {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.4"}}}
, {observer_cli, "1.7.1"} % NOTE: depends on recon 2.5.x , {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"} , {getopt, "1.0.2"}
, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}} , {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.0"}}} , {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.0"}}}

View File

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