Dynamically add log files to monitor
This commit is contained in:
parent
2f74f322ef
commit
3ea2c5c55e
|
@ -1,6 +1,8 @@
|
|||
-module(coordinator).
|
||||
-behaviour(supervisor).
|
||||
-compile(export_all).
|
||||
|
||||
-export([start_link/0]).
|
||||
-export([init/1]).
|
||||
|
||||
start_link() ->
|
||||
supervisor:start_link(?MODULE, []).
|
||||
|
@ -12,14 +14,13 @@ init([]) ->
|
|||
start => {mailer, start_link, []},
|
||||
restart => permanent,
|
||||
shutdown => 5000
|
||||
}] ++ monitors_child_specs(),
|
||||
},
|
||||
#{
|
||||
id => logfiles_sup,
|
||||
start => {logfiles_sup, start_link, []},
|
||||
restart => permanent,
|
||||
type => supervisor,
|
||||
shutdown => 5000
|
||||
}
|
||||
],
|
||||
{ok, {SupFlags, ChildSpecs}}.
|
||||
|
||||
monitors_child_specs() ->
|
||||
{ok, Files} = application:get_env(log_monitor, logfiles),
|
||||
[#{
|
||||
id => list_to_atom(File),
|
||||
start => {monitor, start_link, [File]},
|
||||
restart => temporary,
|
||||
shutdown => 5000
|
||||
} || File <- Files].
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
-module(gatherer).
|
||||
-behaviour(gen_server).
|
||||
-compile(export_all).
|
||||
|
||||
-export([start_link/1, init/1, terminate/2]).
|
||||
-export([handle_info/2, handle_cast/2, handle_call/3]).
|
||||
-export([code_change/3]).
|
||||
|
||||
start_link(File) ->
|
||||
gen_server:start_link(?MODULE, [File], []).
|
||||
|
|
25
apps/log_monitor/src/logfiles_sup.erl
Normal file
25
apps/log_monitor/src/logfiles_sup.erl
Normal file
|
@ -0,0 +1,25 @@
|
|||
-module(logfiles_sup).
|
||||
-behaviour(supervisor).
|
||||
|
||||
-export([start_link/0]).
|
||||
-export([init/1]).
|
||||
|
||||
start_link() ->
|
||||
supervisor:start_link({local, logfiles_sup}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
SupFlags = #{
|
||||
strategy => simple_one_for_one,
|
||||
intensity => 0,
|
||||
period => 1
|
||||
},
|
||||
ChildSpecs = [#{
|
||||
id => monitor,
|
||||
start => {monitor, start_link, []},
|
||||
restart => temporary,
|
||||
shutdown => 5000
|
||||
}],
|
||||
{ok, {SupFlags, ChildSpecs}}.
|
||||
|
||||
%% Start monitor with:
|
||||
%% supervisor:start_child(logfiles_sup, "/tmp/lines.log")
|
|
@ -1,6 +1,9 @@
|
|||
-module(mailer).
|
||||
-behaviour(gen_server).
|
||||
-compile(export_all).
|
||||
|
||||
-export([start_link/0, init/1, terminate/2]).
|
||||
-export([handle_info/2, handle_cast/2, handle_call/3]).
|
||||
-export([code_change/3]).
|
||||
|
||||
start_link() ->
|
||||
gen_server:start_link(?MODULE, [], []).
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
-module(monitor).
|
||||
-behaviour(supervisor).
|
||||
-compile(export_all).
|
||||
|
||||
-export([start_link/1]).
|
||||
-export([init/1]).
|
||||
|
||||
start_link(File) ->
|
||||
supervisor:start_link(?MODULE, [File]).
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
-module(watcher).
|
||||
-behaviour(gen_server).
|
||||
-compile(export_all).
|
||||
|
||||
-export([start_link/2, init/1, terminate/2]).
|
||||
-export([handle_info/2, handle_cast/2, handle_call/3]).
|
||||
-export([code_change/3]).
|
||||
|
||||
start_link(SupPid, File) ->
|
||||
gen_server:start_link(?MODULE, [SupPid, File], []).
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
[
|
||||
{ log_monitor,
|
||||
[
|
||||
{logfiles, ["/tmp/lines.log", "/tmp/lines2.log"]},
|
||||
{email_config,
|
||||
[
|
||||
{sender, "me@example.com"},
|
||||
|
|
Loading…
Reference in New Issue
Block a user