2014-01-29 00:18:47 +00:00
|
|
|
#!/usr/bin/env escript -f
|
2013-06-11 17:53:17 +00:00
|
|
|
|
|
|
|
-mode(compile).
|
|
|
|
|
2014-01-29 00:18:47 +00:00
|
|
|
read_file(File, Owner) ->
|
|
|
|
%%io:format("File: ~p~n", [File]),
|
|
|
|
Out =
|
|
|
|
case file:consult(File) of
|
|
|
|
{ok, F} -> F;
|
|
|
|
Else ->
|
|
|
|
io:format("Failure in ~p: ~p~n",
|
|
|
|
[File,Else]),
|
|
|
|
[]
|
|
|
|
end,
|
|
|
|
Owner ! Out.
|
|
|
|
|
2013-06-11 17:53:17 +00:00
|
|
|
main(_) ->
|
2014-01-29 00:18:47 +00:00
|
|
|
Start = now(),
|
|
|
|
Timer = fun(Slogan) ->
|
|
|
|
T = trunc(timer:now_diff(now(), Start)/1000),
|
|
|
|
io:format("~p ~p ~n", [Slogan, T])
|
|
|
|
end,
|
|
|
|
|
2013-06-11 17:53:17 +00:00
|
|
|
{ok, Files0} = file:list_dir("."),
|
2014-01-29 00:18:47 +00:00
|
|
|
Files = [File || File <- Files0,
|
2014-04-16 00:33:06 +00:00
|
|
|
lists:prefix("cstats-1", File)],
|
|
|
|
if Files =:= [] ->
|
2014-04-18 22:52:27 +00:00
|
|
|
error(no_files_found);
|
2014-04-16 00:33:06 +00:00
|
|
|
true -> ok
|
|
|
|
end,
|
|
|
|
|
2014-01-29 00:18:47 +00:00
|
|
|
%% io:format("Files: ~p ~p~n", [file:get_cwd(), Files]),
|
|
|
|
Main = self(),
|
|
|
|
[spawn(fun() -> read_file(Fn, Main) end)|| Fn <- Files],
|
|
|
|
Data00 = [receive L -> L end || _ <- Files],
|
2013-06-11 17:53:17 +00:00
|
|
|
|
2014-01-29 00:18:47 +00:00
|
|
|
Data0 = lists:filter(fun(L) -> length(L) /= 0 end, Data00),
|
|
|
|
|
|
|
|
Timer(consult_files),
|
|
|
|
|
|
|
|
Data1 = normalize_len(Data0),
|
|
|
|
|
|
|
|
Timer(normalize_lens),
|
2014-04-16 00:33:06 +00:00
|
|
|
%% lens(Data1),
|
2013-06-11 17:53:17 +00:00
|
|
|
|
2014-01-29 00:18:47 +00:00
|
|
|
Data = lists:map(fun winnow/1, Data1),
|
|
|
|
Timer(winnow),
|
2014-04-16 00:33:06 +00:00
|
|
|
%% lens(Data),
|
2013-06-11 17:53:17 +00:00
|
|
|
{Names, Avg} = avg_lists(Data),
|
2014-01-29 00:18:47 +00:00
|
|
|
Timer(average),
|
2013-06-11 17:53:17 +00:00
|
|
|
%%io:format("~p ~p~n", [Names, length(Avg)]),
|
2014-01-29 00:18:47 +00:00
|
|
|
|
2013-06-11 17:53:17 +00:00
|
|
|
{ok, Fd} = file:open("rstats-digest", [write]),
|
2014-04-16 00:33:06 +00:00
|
|
|
[file:write(Fd, io_lib:format("~s ", [atom_to_list(Name)]))
|
2013-06-11 17:53:17 +00:00
|
|
|
|| Name <- Names],
|
|
|
|
file:write(Fd, io_lib:format("~n", [])),
|
2014-01-29 00:18:47 +00:00
|
|
|
|
|
|
|
[begin
|
2013-06-11 17:53:17 +00:00
|
|
|
%%io:format("~p~n", [Item]),
|
|
|
|
[file:write(Fd, io_lib:format("~p ", [Val]))
|
|
|
|
|| Val <- Item],
|
|
|
|
file:write(Fd, io_lib:format("~n", []))
|
|
|
|
end
|
|
|
|
|| Item <- Avg],
|
|
|
|
file:close(Fd).
|
|
|
|
|
2014-04-16 00:33:06 +00:00
|
|
|
%% lens(L) ->
|
|
|
|
%% [io:format("~p ", [length(Ln)])
|
|
|
|
%% || Ln <- L],
|
|
|
|
%% io:format("~n").
|
2014-01-29 00:18:47 +00:00
|
|
|
|
|
|
|
normalize_len(L) ->
|
|
|
|
Lengths = lists:map(fun erlang:length/1, L),
|
|
|
|
Longest = lists:max(Lengths),
|
|
|
|
Shortest = lists:min(Lengths),
|
|
|
|
case (Longest - Shortest) < 4 of
|
|
|
|
true ->
|
|
|
|
trim_long(Shortest, lists:zip(Lengths, L), []);
|
|
|
|
false ->
|
|
|
|
discard_short(L)
|
|
|
|
end.
|
2013-06-11 17:53:17 +00:00
|
|
|
|
2014-01-29 00:18:47 +00:00
|
|
|
trim_long(_, [], Acc) ->
|
|
|
|
Acc;
|
|
|
|
trim_long(Len, [{L, List}|T], Acc) ->
|
|
|
|
io:format("~p ~p ", [Len, L]),
|
|
|
|
case L > Len of
|
|
|
|
true ->
|
|
|
|
io:format("trunc ~n"),
|
|
|
|
{List1, _} = lists:split(Len, List),
|
|
|
|
trim_long(Len, T, [List1| Acc]);
|
|
|
|
false ->
|
|
|
|
io:format("~n"),
|
|
|
|
trim_long(Len, T, [List| Acc])
|
2013-06-11 17:53:17 +00:00
|
|
|
end.
|
|
|
|
|
|
|
|
discard_short(L) ->
|
|
|
|
Longest = lists:max(lists:map(fun erlang:length/1, L)),
|
2014-01-29 00:18:47 +00:00
|
|
|
io:format("longest ~p ~n", [Longest]),
|
|
|
|
lists:filter(fun(X) ->
|
|
|
|
Len = length(X),
|
|
|
|
io:format("len ~p ~n", [Len]),
|
|
|
|
Len =:= Longest
|
|
|
|
end, L).
|
2013-06-11 17:53:17 +00:00
|
|
|
|
|
|
|
avg_lists(LoL) ->
|
|
|
|
avg_lists(LoL, []).
|
|
|
|
|
|
|
|
avg_lists(LoL, Acc) ->
|
2014-04-16 00:33:06 +00:00
|
|
|
HaTs = lists:map(fun([H|T]) -> {H, T}
|
2014-04-18 22:52:27 +00:00
|
|
|
end, LoL),
|
2014-01-29 00:18:47 +00:00
|
|
|
{Heads, Tails} = lists:unzip(HaTs),
|
2013-06-11 17:53:17 +00:00
|
|
|
[First|_] = Heads,
|
|
|
|
Names = [N || {N, _V} <- First],
|
|
|
|
Avgs = avg_items(Heads, Names),
|
|
|
|
Acc1 = [Avgs|Acc],
|
2014-01-29 00:18:47 +00:00
|
|
|
case lists:any(fun(X) -> X =:= [] end, Tails) of
|
2013-06-11 17:53:17 +00:00
|
|
|
true -> {Names, lists:reverse(Acc1)};
|
|
|
|
false -> avg_lists(Tails, Acc1)
|
|
|
|
end.
|
|
|
|
|
|
|
|
avg_items(L, Names) ->
|
|
|
|
%%io:format("~p~n", [length(L)]),
|
|
|
|
Dicts = lists:map(fun orddict:from_list/1, L),
|
|
|
|
[begin
|
2014-04-18 22:52:27 +00:00
|
|
|
Vals = lists:map(fun(D) ->
|
|
|
|
try orddict:fetch(Name, D)
|
|
|
|
catch _:_ -> 0
|
|
|
|
end
|
|
|
|
end,
|
2013-06-11 17:53:17 +00:00
|
|
|
Dicts),
|
|
|
|
case Name of
|
|
|
|
%% vnode gets and puts are a per-minute rolling window
|
2014-06-06 23:59:33 +00:00
|
|
|
index_fsm_create ->
|
|
|
|
(lists:sum(Vals)/length(Vals)) / 60;
|
|
|
|
index_fsm_create_error ->
|
|
|
|
(lists:sum(Vals)/length(Vals)) / 60;
|
2014-01-29 00:18:47 +00:00
|
|
|
vnode_gets ->
|
2013-06-11 17:53:17 +00:00
|
|
|
(lists:sum(Vals)/length(Vals)) / 60;
|
|
|
|
vnode_puts ->
|
|
|
|
(lists:sum(Vals)/length(Vals)) / 60;
|
2014-04-28 15:39:57 +00:00
|
|
|
node_gets ->
|
|
|
|
(lists:sum(Vals)/length(Vals)) / 60;
|
|
|
|
node_puts ->
|
|
|
|
(lists:sum(Vals)/length(Vals)) / 60;
|
2013-06-11 17:53:17 +00:00
|
|
|
_ ->
|
|
|
|
lists:sum(Vals)/length(Vals)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|| Name <- Names].
|
|
|
|
|
|
|
|
|
2014-04-18 18:39:24 +00:00
|
|
|
%% get rid of timestamps and slim down the stats glob
|
2013-06-11 17:53:17 +00:00
|
|
|
winnow(Data0) ->
|
2014-01-29 00:18:47 +00:00
|
|
|
[strip_stats(Glob)
|
2014-04-16 00:33:06 +00:00
|
|
|
|| Glob <- Data0,
|
2014-04-18 22:52:27 +00:00
|
|
|
is_list(Glob)].
|
2013-06-11 17:53:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
strip_stats(Glob) ->
|
2014-04-16 00:33:06 +00:00
|
|
|
Filter = [
|
2014-07-17 15:23:12 +00:00
|
|
|
index_fsm_create,
|
|
|
|
index_fsm_create_error,
|
|
|
|
node_gets,
|
|
|
|
node_puts,
|
|
|
|
vnode_gets,
|
|
|
|
vnode_puts,
|
|
|
|
node_get_fsm_time_median,
|
|
|
|
node_get_fsm_time_95,
|
|
|
|
node_get_fsm_time_99,
|
|
|
|
node_put_fsm_time_median,
|
|
|
|
node_put_fsm_time_95,
|
|
|
|
node_put_fsm_time_99,
|
|
|
|
message_queue_max,
|
|
|
|
cpu_utilization,
|
|
|
|
cpu_iowait,
|
|
|
|
memory_utilization,
|
|
|
|
memory_page_dirty,
|
|
|
|
memory_page_writeback,
|
|
|
|
dropped_vnode_requests_total,
|
|
|
|
node_get_fsm_objsize_median,
|
|
|
|
node_get_fsm_objsize_95,
|
|
|
|
node_get_fsm_objsize_99,
|
|
|
|
disk_utilization,
|
|
|
|
node_get_fsm_map_time_median,
|
|
|
|
node_get_fsm_map_time_95,
|
|
|
|
node_get_fsm_map_time_99,
|
|
|
|
node_put_fsm_map_time_median,
|
|
|
|
node_put_fsm_map_time_95,
|
2014-07-28 19:19:28 +00:00
|
|
|
node_put_fsm_map_time_99,
|
2014-07-17 15:23:12 +00:00
|
|
|
consistent_get_time_median,
|
|
|
|
consistent_get_time_95,
|
|
|
|
consistent_get_time_99,
|
|
|
|
consistent_put_time_median,
|
|
|
|
consistent_put_time_95,
|
|
|
|
consistent_put_time_99
|
2014-04-28 15:39:57 +00:00
|
|
|
],
|
2014-04-16 00:33:06 +00:00
|
|
|
[begin
|
2014-04-18 22:52:27 +00:00
|
|
|
{Name, Val}
|
2014-04-16 00:33:06 +00:00
|
|
|
end
|
|
|
|
|| {Name, Val} <- Glob,
|
|
|
|
lists:member(Name, Filter)].
|