Skip to content
Browse files

Normalize naming conventions. Various bugfixes and work in progress.

  • Loading branch information...
1 parent c2b3f43 commit 4f7e35ef3d39bdfe5891cfa03c3d32d73fee5817 @freza committed Jan 18, 2012
View
3 rebar.config
@@ -1,3 +1,2 @@
-%%{erl_opts, [debug_info, warnings_as_errors, warn_obsolete_guards, warn_unused_import]}.
-{erl_opts, [debug_info, warn_obsolete_guards, warn_unused_import]}.
+{erl_opts, [debug_info, warnings_as_errors, warn_obsolete_guards, warn_unused_import]}.
{xref_checks, [undefined_function_calls]}.
View
33 src/average.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -25,16 +25,16 @@
-module(average).
--export([rec/2, del/1, read/1, read_all/0, read_all/1, read_sel/1]).
+-export([rec/2, del/1, read/1, read_all/0, match/1]).
-import(lists, [foldl/3]).
%%% Samples averaged over reporting period.
-rec({_, _, _} = Key, Val) when is_integer(Val), Val >= 0 ->
+rec({_, _, _} = Key, Val) when is_number(Val), Val >= 0 ->
case update(Key, Val) of
not_found ->
- case ets:insert_new(sysmon_avg, {Key, 1, Val}) of
+ case ets:insert_new(system_mon_avg, {Key, 1, Val}) of
false ->
update(Key, Val);
_ ->
@@ -45,40 +45,37 @@ rec({_, _, _} = Key, Val) when is_integer(Val), Val >= 0 ->
end.
del({_, _, _} = Key) ->
- ets:delete(sysmon_avg, Key).
+ ets:delete(system_mon_avg, Key).
read({Tab, Scope, Inst}) ->
- case ets:lookup(sysmon_avg, {Tab, Scope, Inst}) of
+ case ets:lookup(system_mon_avg, {Tab, Scope, Inst}) of
[Item] ->
{ok, average(Item)};
[] ->
not_found
end.
read_all() ->
- read_sel({'_', '_', '_'}).
+ match({'_', '_', '_'}).
-read_all(Tab) ->
- read_sel({Tab, '_', '_'}).
-
-read_sel(Head) ->
- ets:safe_fixtable(sysmon_avg, true),
+match(Head) ->
+ ets:safe_fixtable(system_mon_avg, true),
try
- read_sel(ets:select(sysmon_avg, [{{Head, '_', '_'}, [], ['$_']}], 100), [])
+ match(ets:select(system_mon_avg, [{{Head, '_', '_'}, [], ['$_']}], 100), [])
after
- ets:safe_fixtable(sysmon_avg, false)
+ ets:safe_fixtable(system_mon_avg, false)
end.
%%%
-read_sel({Items, Cont}, Acc) ->
- read_sel(ets:select(Cont), foldl(fun ({K, _, _} = X, A) -> [{K, average(X)} | A] end, Acc, Items));
-read_sel('$end_of_table', Acc) ->
+match({Items, Cont}, Acc) ->
+ match(ets:select(Cont), foldl(fun ({K, _, _} = X, A) -> [{K, average(X)} | A] end, Acc, Items));
+match('$end_of_table', Acc) ->
Acc.
update(Key, Val) ->
try
- ets:update_counter(sysmon_avg, Key, [{2, 1}, {3, Val}]),
+ ets:update_counter(system_mon_avg, Key, [{2, 1}, {3, Val}]),
ok
catch
error : badarg ->
View
29 src/counter.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -25,48 +25,45 @@
-module(counter).
--export([inc/1, inc/2, set/2, del/1, read/1, read_all/0, read_all/1, read_sel/1]).
+-export([inc/1, inc/2, set/2, del/1, read/1, read_all/0, match/1]).
%%% Event counters are integer values not decreasing in time.
inc(Key) ->
inc(Key, 1).
inc({_, _, _} = Key, Inc) when is_integer(Inc), Inc >= 0 ->
- try ets:update_counter(sysmon_cnt, Key, Inc) catch
+ try ets:update_counter(system_mon_cnt, Key, Inc) catch
error : badarg ->
- case ets:insert_new(sysmon_cnt, {Key, Inc}) of
+ case ets:insert_new(system_mon_cnt, {Key, Inc}) of
false ->
- ets:update_counter(sysmon_cnt, Key, Inc);
+ ets:update_counter(system_mon_cnt, Key, Inc);
_ ->
Inc
end
end.
set({_, _, _} = Key, Val) when is_integer(Val), Val >= 0 ->
- ets:insert(sysmon_cnt, {Key, Val}).
+ ets:insert(system_mon_cnt, {Key, Val}).
del({_, _, _} = Key) ->
- ets:delete(sysmon_cnt, Key).
+ ets:delete(system_mon_cnt, Key).
read({_, _, _} = Key) ->
- case ets:lookup(sysmon_cnt, Key) of
+ case ets:lookup(system_mon_cnt, Key) of
[Item] ->
{ok, Item};
[] ->
not_found
end.
read_all() ->
- read_sel({'_', '_'}).
+ match({'_', '_'}).
-read_all(Tab) ->
- read_sel({Tab, '_', '_'}).
-
-read_sel(Head) ->
- ets:safe_fixtable(sysmon_avg, true),
+match(Head) ->
+ ets:safe_fixtable(system_mon_cnt, true),
try
- ets:select(sysmon_cnt, [{{Head, '_'}, [], ['$_']}])
+ ets:select(system_mon_cnt, [{{Head, '_'}, [], ['$_']}])
after
- ets:safe_fixtable(sysmon_avg, false)
+ ets:safe_fixtable(system_mon_cnt, false)
end.
View
39 src/density.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -25,16 +25,16 @@
-module(density).
--export([rec/2, del/1, read/1, read_all/0, read_all/1, read_sel/1]).
+-export([rec/2, del/1, read/1, read_all/0, match/1]).
-import(lists, [foldl/3]).
--import(sysmon_lib, [logarithm/2, strip_key/1]).
+-import(system_mon_lib, [logarithm/2, strip_key/1]).
--include("sysmon_db.hrl").
+-include("system_mon_db.hrl").
%%% Histograms are predefined event bins stored in single ETS row. Otherwise similar to event counters.
-rec({Tab, _, Inst} = Key, Val) when is_integer(Val), Val >= 0 ->
+rec({Tab, _, Inst} = Key, Val) when is_number(Val) ->
case ets:lookup(density_conf, {Tab, Inst}) of
[Conf] ->
update(Key, value_to_index(Val, Conf), Conf);
@@ -43,50 +43,49 @@ rec({Tab, _, Inst} = Key, Val) when is_integer(Val), Val >= 0 ->
end.
del({_, _, _} = Key) ->
- ets:delete(sysmon_hst, Key).
+ ets:delete(system_mon_hst, Key).
read({_, _, _} = Key) ->
- case ets:lookup(sysmon_hst, Key) of
+ case ets:lookup(system_mon_hst, Key) of
[Item] ->
{ok, strip_key(Item)};
[] ->
not_found
end.
read_all() ->
- read_sel({'_', '_', '_'}).
+ match({'_', '_', '_'}).
-read_all(Tab) ->
- read_sel({Tab, '_', '_'}).
-
-read_sel(Head) ->
- ets:safe_fixtable(sysmon_avg, true),
+match(Head) ->
+ ets:safe_fixtable(system_mon_hst, true),
try
- read_sel(ets:select(sysmon_avg, [{{Head, '_', '_'}, [], ['$_']}], 100), [])
+ %% XXX how to make select work when rows have arbitrary arities???
+ %% XXX it's ordered_set, we probably need first/next...
+ match(ets:select(system_mon_hst, [{{Head, '_', '_'}, [], ['$_']}], 100), [])
after
- ets:safe_fixtable(sysmon_avg, false)
+ ets:safe_fixtable(system_mon_hst, false)
end.
%%%
-read_sel({Items, Cont}, Acc) ->
- read_sel(ets:select(Cont), foldl(fun (X, A) -> [{element(1, X), strip_key(X)} | A] end, Acc, Items));
-read_sel('$end_of_table', Acc) ->
+match({Items, Cont}, Acc) ->
+ match(ets:select(Cont), foldl(fun (X, A) -> [{element(1, X), strip_key(X)} | A] end, Acc, Items));
+match('$end_of_table', Acc) ->
Acc.
update(Key, Idx, #density_conf{cnt = Bins}) ->
case update(Key, Idx) of
not_found ->
%% Make space for implicit bins: underflow/overflow samples.
- ets:insert_new(sysmon_hst, list_to_tuple([Key | lists:duplicate(Bins + 2, 0)])),
+ ets:insert_new(system_mon_hst, list_to_tuple([Key | lists:duplicate(Bins + 2, 0)])),
update(Key, Idx);
_ ->
ok
end.
update(Key, Idx) ->
try
- ets:update_counter(sysmon_hst, Key, {Idx, 1}),
+ ets:update_counter(system_mon_hst, Key, {Idx, 1}),
ok
catch
error : badarg ->
View
14 src/system_mon.app.src
@@ -1,7 +1,15 @@
{application, system_mon,
- [{description, "Lightweight system monitoring library."},
+ [{description, "Lightweight System Monitoring Application."},
{vsn, "0.0.1"},
- {registered, [sysmon_log, sysmon_sup, sysmon_dif_sup]},
+ {registered, [system_mon_log, system_mon_sup, system_mon_dif_sup]},
{mod, {sysmon_app, []}},
- {applications, [kernel, stdlib, mnesia]}
+ {applications, [kernel, stdlib, mnesia]},
+ {audit_log,
+ [{counter_log, [{with_node, true}, {suffix, "csv"}]},
+ {average_log, [{with_node, true}, {suffix, "csv"}]},
+ {density_log, [{with_node, true}, {suffix, "csv"}]}
+ ]},
+ {system_mon,
+ [{density,
+ [{{system_mon, '_', duration}, [{scale, log}, {base, 10}, {min_exp, -6}, {max_exp, 2}, {count, 8}]}]}]}
]}.
View
82 src/sysmon.erl → src/system_mon.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,18 +23,17 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon).
+-module(system_mon).
--export([add_counter/3, add_average/3, add_linear/3, add_logarithmic/3]).
--export([del_counter/2, del_average/2, del_histogram/2]).
+-export([add_density/2]).
-export([create_db/0, create_db/1]).
-export([behaviour_info/1]).
--import(sysmon_lib, [get_value/2, get_value/3]).
+-import(system_mon_lib, [get_value/2, get_value/3]).
--include("sysmon_db.hrl").
+-include("system_mon_db.hrl").
-%%% Interface for sysmon_feed callbacks.
+%%% Interface for system_mon_dif callbacks.
behaviour_info(callbacks) ->
[{start_feed, 1}, %% Mod:start_feed(Args) -> {ok, Impl}
@@ -47,11 +46,22 @@ behaviour_info(_) ->
%%% Management interface.
-add_counter(Tab, Inst, Opts) ->
- xxx.
+add_density({Tab, '_', Inst}, Opts) ->
+ case get_value(scale, Opts) of
+ lin ->
+ add_linear(Tab, Inst, Opts);
+ log ->
+ add_logarithmic(Tab, Inst, Opts)
+ end.
-add_average(Tab, Inst, Opts) ->
- xxx.
+create_db() ->
+ create_db([{disc_copies, [node()]}, {local_content, true}]).
+
+create_db(Opts) ->
+ mnesia:create_table(density_conf, [{attributes, record_info(fields, density_conf)},
+ {type, set} | Opts]).
+
+%%% Implementation.
%% Linear histogram: [{mult, Num}, {min_y, Num}, {max_y, Num}, {count, N}].
add_linear(Tab, Inst, Os) ->
@@ -69,20 +79,36 @@ add_logarithmic(Tab, Inst, Os) ->
Cnt = get_value(count, Os),
mnesia:dirty_write(#density_conf{key = {Tab, Inst}, scale = log, slope = Log, min = Min, max = Max, cnt = Cnt}).
-del_counter(Tab, Inst) ->
- xxx.
-
-del_average(Tab, Inst) ->
- xxx.
-
-del_histogram(Tab, Inst) ->
- xxx.
-
-%%% System interface. Normally not needed, but allow creating configuration table manually.
-
-create_db() ->
- create_db([{disc_copies, [node()]}, {local_content, true}]).
-
-create_db(Opts) ->
- mnesia:create_table(density_conf, [{attributes, record_info(fields, density_conf)},
- {type, set} | Opts]).
+%% XXXtodo Want a safe way to ensure all stats config from *.app is loaded.
+%%
+%% Ensure all stats mentioned in *.app files of loaded applications are provisioned in Mnesia.
+%% scan_all_stats() ->
+%% [scan_app_stats(App) || {App, _, _} <- application:loaded_applications()],
+%% ok.
+%%
+%% scan_app_stats(App) ->
+%% [edit_hst(Name, Opts) || {Name, Opts} <- get_value(density, get_key(App, system_mon, []), [])],
+%% ok.
+%%
+%% get_key(App, Key, Def) ->
+%% case application:get_key(App, Key) of
+%% {ok, Val} ->
+%% Val;
+%% undefined ->
+%% Def
+%% end.
+%%
+%% edit_hst(Tab, Inst, Scale, Slope, Min, Max, Cnt, Do_force) ->
+%% case mnesia:dirty_read(density_conf, {Tab, Inst}) of
+%% [#density_conf{}] when Do_force == false ->
+%% %% Just ensuring existence.
+%% ok;
+%% [#density_conf{scale = Scale, slope = Slope, min = Min, max = Max, cnt = Cnt}] ->
+%% %% No change.
+%% ok;
+%% [#density_conf{}] when Do_force == true ->
+%% %% XXX remove
+%% %% XXX destroy existing instances.
+%% mnesia:write(#density_conf{});
+%% [] ->
+%%
View
10 src/sysmon_app.erl → src/system_mon_app.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon_app).
+-module(system_mon_app).
-behaviour(application).
-export([start/2, stop/1]).
@@ -34,7 +34,9 @@
start(_, _) ->
setup_db(),
- sysmon_sup:start_link().
+ audit_log:rediscover_logs(system_mon),
+ system_mon:rediscover_stats(system_mon),
+ system_mon_sup:start_link().
stop(_) ->
ok.
@@ -52,6 +54,6 @@ setup_db() ->
end
catch
exit : {aborted, {no_exists, _, _}} ->
- {atomic, ok} = sysmon:create_db()
+ {atomic, ok} = system_mon:create_db()
end,
ok = mnesia:wait_for_tables([density_conf], 10000).
View
6 src/sysmon_db.hrl → src/system_mon_db.hrl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,8 +23,8 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--ifndef(SYSMON_DB_HRL).
--define(SYSMON_DB_HRL, included).
+-ifndef(SYSTEM_MON_DB_HRL).
+-define(SYSTEM_MON_DB_HRL, included).
-record(density_conf, {
key, %% What are we defining? :: {Tab, Inst}.
View
46 src/sysmon_dif.erl → src/system_mon_dif.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,26 +23,28 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon_dif).
+-module(system_mon_dif).
-behaviour(gen_server).
--export([start_link/2, start_feed/2, abort_feed/1]).
+-export([start_link/2, start_feed/2, abort_feed/1, set_owner/2]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
--import(sysmon_lib, [strip_key/1]).
+-import(system_mon_lib, [strip_key/1]).
%%%
start_link(Feed, Mod) ->
- %%% XXX pass owner pid, monitor, allow transfer, terminate when it exits.
- gen_server:start_link({local, Feed}, ?MODULE, [Mod], []).
+ gen_server:start_link({local, Feed}, ?MODULE, [Mod, self()], []).
start_feed(Feed, Args) ->
gen_server:call(Feed, {start_feed, Args}).
abort_feed(Feed) ->
gen_server:call(Feed, abort_feed).
+set_owner(Feed, Pid) ->
+ gen_server:call(Feed, {set_owner, Pid}).
+
%%%
worker_crash(Pid) ->
@@ -60,25 +62,27 @@ worker_done(Pid) ->
workers, %% Active workers. :: ordsets(pid())
mod, %% Callback module. :: atom()
impl, %% Callback state. :: term() | nil
- status %% Activity status. :: normal | failed | aborted
+ status, %% Activity status. :: normal | failed | aborted
+ owner %% Owner process. :: pid()
}).
-init([Mod]) ->
+init([Mod, Owner]) ->
+ link(Owner),
%% Shadow tables storing previous values.
Aux_cnt = ets:new(anon, [ordered_set, public]),
Aux_avg = ets:new(anon, [ordered_set, public]),
Aux_hst = ets:new(anon, [ordered_set, public]),
{ok, #state{cnt = Aux_cnt, avg = Aux_avg, hst = Aux_hst, workers = [],
- mod = Mod, impl = nil, status = nil}}.
+ mod = Mod, impl = nil, status = nil, owner = Owner}}.
handle_call({start_feed, Args}, _, #state{cnt = Cnt, avg = Avg, hst = Hst, workers = Workers, mod = Mod} = State) ->
case Workers of
[] ->
{ok, Impl} = Mod:start_feed(Args),
Parent = self(),
- Cnt_pid = proc_lib:spawn_link(fun () -> worker(Parent, sysmon_cnt, Cnt, counter, Mod, Impl) end),
- Avg_pid = proc_lib:spawn_link(fun () -> worker(Parent, sysmon_avg, Avg, average, Mod, Impl) end),
- Hst_pid = proc_lib:spawn_link(fun () -> worker(Parent, sysmon_hst, Hst, density, Mod, Impl) end),
+ Cnt_pid = proc_lib:spawn_link(fun () -> worker(Parent, system_mon_cnt, Cnt, counter, Mod, Impl) end),
+ Avg_pid = proc_lib:spawn_link(fun () -> worker(Parent, system_mon_avg, Avg, average, Mod, Impl) end),
+ Hst_pid = proc_lib:spawn_link(fun () -> worker(Parent, system_mon_hst, Hst, density, Mod, Impl) end),
Workers2 = ordsets:from_list([Cnt_pid, Avg_pid, Hst_pid]),
{reply, ok, State#state{workers = Workers2, impl = Impl, status = normal}};
_ ->
@@ -103,6 +107,15 @@ handle_call({worker_done, Pid}, _, #state{workers = Workers, mod = Mod, impl = I
handle_call(worker_crash, _, #state{workers = Workers} = State) ->
[(catch Worker ! worker_stop) || Worker <- Workers],
{reply, ok, State#state{status = failed}};
+handle_call({set_owner, New}, _, #state{owner = Old} = State) ->
+ %% NB ordered so that we're always linked to someone.
+ if New /= Old ->
+ link(New),
+ unlink(Old);
+ true ->
+ ok
+ end,
+ {reply, ok, State#state{owner = New}};
handle_call(_, _, State) ->
{reply, {error, bad_request}, State}.
@@ -122,13 +135,10 @@ terminate(_, _) ->
worker(Parent, Cur_tab, Aux_tab, Kind, Mod, Impl) ->
try
- %% XXX would be interesting to record latency histogram, maybe process size too
- %%
- %% A = now(),
+ Begin_ts = now(),
table_diff(Cur_tab, ets:first(Cur_tab), Aux_tab, ets:first(Aux_tab), Kind, Mod, Impl),
- %% B = now(),
- %% io:format("~s ==> Feed ~s took ~wms.~n", [audit_log_lib:printable_date(),
- %% Cur_tab, timer:now_diff(B, A) div 1000]),
+ Finish_ts = now(),
+ density:rec({system_mon, {Kind, Mod}, duration}, timer:now_diff(Finish_ts, Begin_ts) / 1000000),
worker_done(Parent)
catch
throw : {callback_crash, Exn, Rsn, Stack} ->
View
6 src/sysmon_dif_sup.erl → src/system_mon_dif_sup.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon_dif_sup).
+-module(system_mon_dif_sup).
-vsn(' $Id: audit_log_disk_sup.erl 20123 2011-07-08 17:19:04Z jachym $ ').
-behaviour(supervisor).
@@ -50,4 +50,4 @@ init([]) ->
%%% Implementation.
child(Name, Mod) ->
- {Name, {sysmon_dif, start_link, [Name, Mod]}, transient, 60000, worker, [sysmon_dif]}.
+ {Name, {system_mon_dif, start_link, [Name, Mod]}, transient, 60000, worker, [system_mon_dif]}.
View
4 src/sysmon_lib.erl → src/system_mon_lib.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon_lib).
+-module(system_mon_lib).
-export([get_env/3, get_value/2, get_value/3, logarithm/2, strip_key/1]).
View
28 src/sysmon_log.erl → src/system_mon_log.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,15 +23,15 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon_log).
+-module(system_mon_log).
-behaviour(gen_server).
--behaviour(sysmon).
+-behaviour(system_mon).
-export([start_link/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-export([start_feed/1, handle_create/4, handle_update/5, handle_delete/3, stop_feed/2]).
--import(sysmon_lib, [get_env/3]).
+-import(system_mon_lib, [get_env/3]).
%%%
@@ -47,7 +47,7 @@ start_link() ->
init([]) ->
%% NB initial value of Last_ts doesn't matter as all will go to handle_create/4 anyway.
- {ok, _} = sysmon_dif_sup:add_worker(sysmon_log, ?MODULE),
+ {ok, _} = system_mon_dif_sup:add_worker(system_mon_log, ?MODULE),
Name_tab = ets:new(anon, [set, public, {read_concurrency, true}]),
Timer = schedule_update(),
{ok, #state{name_tab = Name_tab, update_tmr = Timer}}.
@@ -59,9 +59,9 @@ handle_cast(_, State) ->
{noreply, State}.
handle_info({timeout, Ref, update}, #state{update_tmr = Ref, name_tab = Name_tab} = State) ->
- %% NB sysmon won't run multiple instances of the feed at once as an overload protection measure.
+ %% NB system_mon_dif won't run multiple instances of the feed at once as an overload protection measure.
Log_ts = audit_log_lib:printable_date(calendar:local_time()),
- sysmon_dif:start_feed(sysmon_log, [Name_tab, Log_ts]),
+ system_mon_dif:start_feed(system_mon_log, [Name_tab, Log_ts]),
{noreply, State#state{update_tmr = schedule_update()}};
handle_info(_, State) ->
{noreply, State}.
@@ -76,7 +76,7 @@ terminate(_, _) ->
schedule_update() ->
%% Align nicely to next multiple of log period, since midnight.
- Period = get_env(sysmon, log_period, 900),
+ Period = get_env(system_mon, log_period, 900),
{_, {H, M, S}} = calendar:local_time(),
Secs = H*3600 + M*60 + S,
Next = ((Secs + Period) div Period) * Period,
@@ -94,26 +94,26 @@ start_feed([Name_tab, Log_ts]) ->
handle_create(counter, Key, [Cur_val], #feed{name_tab = Name_tab, log_ts = Log_ts}) ->
Row = [Log_ts, $,, insert_name(Name_tab, Key), $,, integer_to_list(Cur_val), $\n],
- audit_log:audit_msg(sysmon_cnt, Row);
+ audit_log:audit_msg(counter_log, Row);
handle_create(average, Key, [Cur_cnt, Cur_sum], #feed{name_tab = Name_tab, log_ts = Log_ts}) ->
Row = [Log_ts, $,, insert_name(Name_tab, Key), $,, integer_to_list(round(Cur_sum / Cur_cnt)), $\n],
- audit_log:audit_msg(sysmon_avg, Row);
+ audit_log:audit_msg(average_log, Row);
handle_create(density, Key, Cur_vals, #feed{name_tab = Name_tab, log_ts = Log_ts}) ->
Row = [Log_ts, $,, insert_name(Name_tab, Key), [[$,, integer_to_list(N)] || N <- Cur_vals], $\n],
- audit_log:audit_msg(sysmon_hst, Row).
+ audit_log:audit_msg(density_log, Row).
handle_update(counter, Key, [Cur_val], [Old_val], #feed{name_tab = Name_tab, log_ts = Log_ts}) ->
Row = [Log_ts, $,, lookup_name(Name_tab, Key), $,, integer_to_list(Cur_val - Old_val), $\n],
- audit_log:audit_msg(sysmon_cnt, Row);
+ audit_log:audit_msg(counter_log, Row);
handle_update(average, Key, [Cur_cnt, Cur_sum], [Old_cnt, Old_sum], #feed{name_tab = Name_tab, log_ts = Log_ts}) ->
Cnt = integer_to_list(Cur_cnt - Old_cnt),
Sum = integer_to_list(Cur_sum - Old_sum),
Row = [Log_ts, $,, lookup_name(Name_tab, Key), $,, Cnt, $,, Sum, $\n],
- audit_log:audit_msg(sysmon_avg, Row);
+ audit_log:audit_msg(average_log, Row);
handle_update(density, Key, Cur_vals, Old_vals, #feed{name_tab = Name_tab, log_ts = Log_ts}) ->
Avg = lists:zipwith(fun (Cur, Old) -> [$,, integer_to_list(Cur - Old)] end, Cur_vals, Old_vals),
Row = [Log_ts, $,, lookup_name(Name_tab, Key), Avg, $\n],
- audit_log:audit_msg(sysmon_hst, Row).
+ audit_log:audit_msg(density_log, Row).
handle_delete(_, Key, #feed{name_tab = Name_tab}) ->
case ets:update_counter(Name_tab, Key, [{2, -1}]) of
View
18 src/sysmon_sup.erl → src/system_mon_sup.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,7 +23,7 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon_sup).
+-module(system_mon_sup).
-behaviour(supervisor).
-export([start_link/0]).
@@ -37,16 +37,14 @@ start_link() ->
%%%
init([]) ->
- %% XXX start collector agent (+ transport socket (SCTP)) and systat polling process.
- %% XXX random feature: would be good to support (discrete) scatter plots too!
- ets:new(sysmon_cnt, [ordered_set, named_table, public]),
- ets:new(sysmon_avg, [ordered_set, named_table, public]),
- ets:new(sysmon_hst, [ordered_set, named_table, public]),
+ ets:new(system_mon_cnt, [ordered_set, named_table, public]),
+ ets:new(system_mon_avg, [ordered_set, named_table, public]),
+ ets:new(system_mon_hst, [ordered_set, named_table, public]),
{ok, {{one_for_one, 1, 10}, children()}}.
%%%
children() ->
- [{sysmon_feed_sup, {sysmon_feed_sup, start_link, []}, permanent, 60000, supervisor, [sysmon_feed_sup]},
- {sysmon_sys, {sysmon_sys, start_link, []}, permanent, 60000, worker, [sysmon_sys]},
- {sysmon_log, {sysmon_log, start_link, []}, permanent, 60000, worker, [sysmon_log]}].
+ [{system_mon_dif_sup, {system_mon_dif_sup, start_link, []}, permanent, 60000, supervisor, [system_mon_dif_sup]},
+ {system_mon_sys, {system_mon_sys, start_link, []}, permanent, 60000, worker, [system_mon_sys]},
+ {system_mon_log, {system_mon_log, start_link, []}, permanent, 60000, worker, [system_mon_log]}].
View
18 src/sysmon_sys.erl → src/system_mon_sys.erl
@@ -1,4 +1,4 @@
-%%% Copyright (c) 2011 Jachym Holecek <freza@circlewave.net>
+%%% Copyright (c) 2011-2012 Jachym Holecek <freza@circlewave.net>
%%% All rights reserved.
%%%
%%% Redistribution and use in source and binary forms, with or without
@@ -23,15 +23,15 @@
%%% OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
%%% SUCH DAMAGE.
--module(sysmon_sys).
+-module(system_mon_sys).
-vsn(' $Id$ ').
-url(' $URL$ ').
-behaviour(gen_server).
-export([start_link/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
--import(sysmon_lib, [get_env/3, get_value/3]).
+-import(system_mon_lib, [get_env/3, get_value/3]).
-import(lists, [foldl/3, usort/1]).
%%%
@@ -87,8 +87,10 @@ terminate(_, _) ->
%%% Synthesis of application metrics: processes.
pid_worker(Parent, Apps, Leaders) ->
- %% XXX would be interesting to record latency histogram, maybe process size too
+ Begin_ts = now(),
[pid_write(Pid_stats) || Pid_stats <- pid_stats(Apps, Leaders)],
+ Finish_ts = now(),
+ density:rec({system_mon, pid_synth, duration}, timer:now_diff(Finish_ts, Begin_ts) / 1000000),
done(Parent).
pid_write({App, {Count, Memory, Mqueue}}) ->
@@ -130,8 +132,10 @@ pid_info(Pid) ->
%%% Synthesis of application metrics: ETS tables.
tid_worker(Parent, Apps, Leaders) ->
- %% XXX would be interesting to record latency histogram, maybe process size too
+ Begin_ts = now(),
[tid_write(Tid_stats) || Tid_stats <- tid_stats(Apps, Leaders)],
+ Finish_ts = now(),
+ density:rec({system_mon, tid_synth, duration}, timer:now_diff(Finish_ts, Begin_ts) / 1000000),
done(Parent).
tid_write({App, {Count, Items, Memory}}) ->
@@ -198,7 +202,7 @@ erts_cnt() ->
counter:set({erts, system, port_rx}, Ior),
counter:set({erts, system, port_tx}, Iow),
counter:set({erts, system, gc_count}, Gc_cnt),
- counter:set({erts, system, gc_freed}, Gc_freed),
+ counter:set({erts, system, gc_freed}, words_to_bytes(Gc_freed)),
counter:set({erts, system, reductions}, Reds),
counter:set({erts, system, proc_sched}, Context_sw).
@@ -250,7 +254,7 @@ host_load() ->
%%% Implementation.
schedule_update() ->
- erlang:start_timer(get_env(sysmon, systat_period, 300) * 1000, self(), update).
+ erlang:start_timer(get_env(system_mon, sys_period, 300) * 1000, self(), update).
mnesia_info(Key) ->
try mnesia:system_info(Key) catch

0 comments on commit 4f7e35e

Please sign in to comment.
Something went wrong with that request. Please try again.