Skip to content

Commit

Permalink
clean up, fix some bugs, add directory-grabbing
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmcc committed Oct 4, 2012
1 parent b69abb4 commit f515580
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
54 changes: 37 additions & 17 deletions src/riaknostic_export.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ get_cmd_list() ->
[
{"swappiness", "sysctl vm.swappiness"}
] ++ Stats;
{unix, darwin} -> []; % unsupported for production
{unix, darwin} ->
[
]; % unsupported for production
{unix, freebsd} ->
[
{"iostat", "iostat 1 5"}
] ++ Stats;
{unix, sunos} ->
[
{"iostat", "iostat 1 5"}
];
_ -> [] %maybe explicitly error here?
end,
Expand All @@ -71,15 +71,9 @@ get_file_list() ->
List = [
"/etc/hosts", % might want to omit
"/etc/hostname",
"/etc/riak/app.config",
"/etc/riak/vm.args",
"/etc/riak/",
"/etc/fstab",
"/var/log/riak/console.log",
"/var/log/riak/error.log",
"/var/log/riak/erlang.log",
"/var/log/riak/run_erl.log",
"/var/log/riak/erl_crash.dump",
"/var/log/riak/crash.log"
"/var/log/riak/"
],
PerOS = case os:type() of
{unix, linux} ->
Expand All @@ -89,27 +83,50 @@ get_file_list() ->
{unix, darwin} -> []; % unsupported for production
{unix, freebsd} ->
[
"/etc/fstab"
];
{unix, sunos} ->
[
"/etc/fstab"
];
_ -> [] %maybe explicitly error here?
end,
List ++ PerOS.

run_commands(CmdList) ->
[{Name, riaknostic_util:run_command(Cmd)} ||
[{Name, run_command(Cmd)} ||
{Name, Cmd} <- CmdList].

run_command(Cmd) ->
try
riaknostic_util:run_command(Cmd)
catch
Error:Reason ->
io:format("when running ~s got ~s:~s~n ~w~n",
[Cmd, Error, Reason, erlang:get_stacktrace()]),
"got error\n"
end.


copy_to_dir([], _Dir) ->
ok;
copy_to_dir(FileList, Dir) ->
[FileName|Tail] = FileList,
{ok, _} = file:copy(FileName,
Dir ++ filename:basename(FileName)),
copy_to_dir(Tail, Dir).
case lists:last(FileName) of
$/ ->
%%add files in this dir to tail
{ok, Files} = file:list_dir(FileName),
copy_to_dir([FileName ++ File || File <- Files] ++ Tail,
Dir);
_ ->
Res = file:copy(FileName,
Dir ++ filename:basename(FileName)),
case Res of
{ok, _} -> ok;
{error, Reason} ->
io:format("Couldn't copy ~s. Error: ~s",
[FileName, Reason])
end,
copy_to_dir(Tail, Dir)
end.

write_to_file([], _Dir) ->
ok;
Expand All @@ -125,6 +142,9 @@ package_files(Dir) ->
FileList = ["export/" ++ File || File <- NameList],
PrefLen = string:len(Dir) - string:len("export/"),
Prefix = string:sub_string(Dir, 1, PrefLen),
{ok, Cwd} = file:get_cwd(),
io:format("Writing export file: ~s~n",
[Cwd ++ "/export.zip"]),
zip:zip("export.zip", FileList, [{cwd, Prefix}]).

prep_tmp_dir() ->
Expand Down
14 changes: 11 additions & 3 deletions src/riaknostic_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ short_name(Mod) when is_atom(Mod) ->
run_command(Command) ->
lager:debug("Running shell command: ~s", [Command]),
Port = erlang:open_port({spawn,Command},[exit_status, stderr_to_stdout]),
do_read(Port, []).

do_read(Port, Acc) ->
receive
{Port, {data, StdOut}} ->
lager:debug("Shell command output: ~n~s~n",[StdOut]),
port_close(Port),
StdOut
do_read(Port, Acc ++ StdOut);
{Port, {exit_status, _}} ->
%%port_close(Port),
Acc;
Other ->
io:format("~w", [Other]),
do_read(Port, Acc)
end.

%% @doc Converts a binary containing a text representation of a float
%% into a float type.
-spec binary_to_float(binary()) -> float().
Expand Down

0 comments on commit f515580

Please sign in to comment.