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