Skip to content

Commit 03020ee

Browse files
committed
Switch to rebar3 and an escript.
This also contains various commits I found in other places which seemed useful. I updated the README to reflect where the escript is built. The shell script is no longer necessary so was removed.
1 parent 8e74362 commit 03020ee

File tree

8 files changed

+127
-85
lines changed

8 files changed

+127
-85
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.beam
22
deps
3+
_build
4+
.rebar3
5+
rebar.lock

README.md

+17-16
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,46 @@ A top-like Erlang node monitoring tool
33

44

55
## Introduction
6-
Entop is a tool which shows information about a remote Erlang node in a way which is similar to unix 'top'.
6+
Entop is a tool which shows information about a remote Erlang node in a way which is similar to unix 'top'.
77

8-
For entop to run it needs `cecho 0.3.0` or higher for pre-R15 or `cecho 0.4.0` or higher for R15 and above
8+
For entop to run it needs `cecho 0.5.1` or higher
99
(http://www.github.com/mazenharake/cecho).
1010

1111
## Compile
1212
To clean/compile run
1313

14-
./rebar clean
15-
./rebar compile
14+
./rebar3 clean
15+
./rebar3 escriptize
1616

17-
NOTE: If you have problems with dependencies to `cecho` then create a symlink to cecho in `deps/` (if you already have cecho somewhere) or run `./rebar get-deps` to download the latest version. Don't forget to recompile if you get the dependencies through rebar.
17+
A relocatable escript named 'entop' is now in '_build/default/bin/entop', you can copy that to your path somewhere.
1818

1919
## Usage
20-
To run entop make sure you have Erlang installed and that the cecho library (http://www.github.com/mazenharake/cecho) is available in your Erlang code path. The start script assumes that you run it inside the entop application root directory, if you don't want that then change the paths in the scripts accordingly or just make sure you have the ebin/ directory for entop in your Erlang code path. Look at the start script for more details.
20+
To run entop make sure you have Erlang installed and that the escript is in your path.
2121

22-
Usage: ./entop <TARGETNODE> [-name <NAME>|-sname <SNAME>] [-setcookie <COOKIE>]
22+
Usage: ./entop <TARGETNODE> [<COOKIE>]
2323

2424
### An example of how you run entop:
2525

26-
> ./entop [email protected] -name [email protected] -setcookie secret
26+
> ./entop [email protected] secret
2727

2828
### User Interface:
2929
entop's interface can be customized so this section only applies for the "built-in" interface.
3030

3131
#### Headers
32-
**First row** shows information about the node which is more or less static such as the node name the operating system, erl flags and erlang version it is running.
33-
**The second** row shows information on what the local time is (according to the node), how long it has been up for (Days:Hours:Minutes:Seconds) and how much latency there is to the node I.e. how long a net_adm:ping() takes.
34-
**Third row** shows information about the processes of the system; the total number of processes, the run queue (number of processes scheduled to run by the scheduler(s)), the reductions per interval (RpI) which shows how many reductions the system has made since it last called the node and how much memory the processes are using.
35-
**Fourth row** shows how much system memory, atom memory (currently used/total allocated), binary memory, code memory and ets memory.
36-
**Fifth row** is left blank and is reserved for now.
37-
**Sixth row** shows information about the rows in the list such as the interval in which the information is fetched, what the list is sorted on and how long it took to retrieve the information.
32+
**First row** shows information about the node which is more or less static such as the node name the operating system, erl flags and erlang version it is running.
33+
**Second row** shows information on what the local time is (according to the node), how long it has been up for (Days:Hours:Minutes:Seconds) and how much latency there is to the node I.e. how long a net_adm:ping() takes.
34+
**Third row** shows information about the processes of the system; the total number of processes, the run queue (number of processes scheduled to run by the scheduler(s)), the reductions per interval (RpI) which shows how many reductions the system has made since it last called the node.
35+
**Fourth row** shows how much process memory is being used and the total amount.
36+
**Fifth row** shows how much system memory, atom memory (currently used/total allocated), binary memory, code memory and ets memory.
37+
**Sixth row** is left blank and is reserved for now.
38+
**Seventh row** shows information about the rows in the list such as the interval in which the information is fetched, what the list is sorted on and how long it took to retrieve the information.
3839

3940
### Commands when running entop:
4041

41-
[1-N]:
42+
[1-N]:
4243
Sort on column number 1 through N. Starts with first column (1) and up to N
4344
where N is the last column.
44-
45+
4546
r:
4647
Toggles the sorting order from ascending to descending and vice versa.
4748

entop

-60
This file was deleted.

rebar

-111 KB
Binary file not shown.

rebar.config

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
{erl_opts, [fail_on_warning, debug_info]}.
2-
{deps_dir, "deps"}.
3-
{clean_files, ["ebin/*.beam"]}.
4-
{deps, [{cecho, ".*", {git, "https://github.com/mazenharake/cecho.git", "HEAD"}}]}.
5-
{escript_name, "rebar_tmp"}.
1+
{erl_opts, [fail_on_warning,
2+
debug_info,
3+
{platform_define, "^(R14|R15|R16B|17)", 'random_module_available'}
4+
]}.
5+
6+
{escript_emu_args, "%%! -hidden -noinput +A 20 +Bc"}.
7+
8+
{ deps, [
9+
{cecho, ".*",
10+
{git, "https://github.com/mazenharake/cecho.git", {tag, "0.5.1"}}
11+
}
12+
]
13+
}.

rebar3

769 KB
Binary file not shown.

ebin/entop.app src/entop.app.src

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{application, entop,
22
[{description, "A top-like tool for monitoring an erlang node"},
3-
{vsn, "0.0.1"},
4-
{modules, [entop, entop_collector, entop_format, entop_view, entop_net]},
5-
{applications, []},
3+
{vsn, "0.3.0"},
64
{registered, []},
7-
{env, []}]}.
5+
{applications,
6+
[kernel,
7+
stdlib,
8+
cecho
9+
]},
10+
{env,[]},
11+
{modules, [entop, entop_collector, entop_format, entop_view, entop_net]},
12+
{maintainers, []},
13+
{licenses, ["Apache 2.0"]},
14+
{links, []}
15+
]}.

src/entop.erl

+82
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,91 @@
2020
-include("entop.hrl").
2121
-include_lib("cecho/include/cecho.hrl").
2222

23+
%% escript bits
24+
-export([main/1]).
25+
2326
%% Application API
2427
-export([start/1]).
2528

29+
-ifdef(random_module_available).
30+
rand_seed() ->
31+
random:seed(os:timestamp()).
32+
rand_uniform(N) ->
33+
random:uniform(N).
34+
-else.
35+
rand_seed() ->
36+
ok.
37+
rand_uniform(N) ->
38+
rand:uniform(N).
39+
-endif.
40+
41+
main([]) ->
42+
io:format("Usage: ./entop <TARGETNODE> [<COOKIE>]~n", []),
43+
halt(1);
44+
main([Node]) ->
45+
main([Node,undefined]);
46+
main([NodeIn,CookieIn]) ->
47+
% node and cookie should both be atoms
48+
Node = normalize_to_atom(NodeIn),
49+
Cookie = normalize_to_atom(CookieIn),
50+
case name_type(Node) of
51+
{ error, improper_node_name } ->
52+
io:format("Nodename ~p is malformed, use form 'node@host'~n", [Node]),
53+
halt(101);
54+
{ok, NameType} ->
55+
case net_kernel:start(NameType) of
56+
{ok, _} ->
57+
case maybe_set_cookie(Node,Cookie) of
58+
ok ->
59+
case net_kernel:connect(Node) of
60+
true ->
61+
ViewPid = entop_view:start(#state{ node = Node,
62+
connected = true }),
63+
control(ViewPid);
64+
false ->
65+
io:format("Unable to connect to '~p', check nodename, cookie and network~n",[Node]),
66+
halt(101)
67+
end;
68+
CE ->
69+
io:format("Cookie ~p is malformed, got error ~p~n", [Cookie,CE]),
70+
halt(101)
71+
end;
72+
NetError ->
73+
io:format("Couldn't start network with ~p, got error ~p~n",
74+
[NameType, NetError]),
75+
halt(101)
76+
end
77+
end.
78+
79+
normalize_to_atom(L) when is_list(L) ->
80+
list_to_atom(L);
81+
normalize_to_atom(A) when is_atom(A) ->
82+
A.
83+
84+
maybe_set_cookie(_, undefined) -> ok;
85+
maybe_set_cookie(Node, Cookie) ->
86+
case erlang:set_cookie(Node,Cookie) of
87+
true -> ok;
88+
E -> E
89+
end.
90+
91+
name_type (Node) when is_atom(Node) ->
92+
name_type(atom_to_list(Node));
93+
name_type (Node) when is_list(Node) ->
94+
case string:tokens(Node,"@") of
95+
[_] -> {error, improper_node_name};
96+
[N,H] ->
97+
T =
98+
case lists:member($.,H) of
99+
true -> longnames;
100+
false -> shortnames
101+
end,
102+
rand_seed(),
103+
R = rand_uniform(1000000),
104+
EntopName = list_to_atom("entop-" ++ integer_to_list(R) ++ "-" ++ N),
105+
{ok,[EntopName,T]}
106+
end.
107+
26108
%% =============================================================================
27109
%% Application API
28110
%% =============================================================================

0 commit comments

Comments
 (0)