-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcluster_process_info.erl
More file actions
25 lines (21 loc) · 917 Bytes
/
cluster_process_info.erl
File metadata and controls
25 lines (21 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
%% @copyright Geoff Cant 2012
%% @author Geoff Cant <nem@erlang.geek.nz>
%% @version {@vsn}, {@date} {@time}
%% @doc Retreive TopN pids in a cluster sorted by a process_info metric.
%% @end
f(Info).
Info = fun (P,I) ->
element(2, process_info(P,I))
end.
f(TopN).
TopN = fun (N, Metric) ->
element(1, lists:split(N, lists:reverse(lists:keysort(2, [{P, Info(P, Metric)} || P <- erlang:processes(), is_process_alive(P)]))))
end.
f(TopPorts).
TopPorts = fun (N) ->
element(1, lists:split(N, lists:reverse(lists:keysort(2, [{P, length([Port || Port <- Info(P, links), is_port(Port)])} || P <- erlang:processes(), is_process_alive(P)]))))
end.
f(CI).
CI = fun (N, Metric) ->
element(1, lists:split(N, lists:reverse(lists:keysort(2, lists:append(element(1, rpc:multicall(erlang, apply, [ fun () -> TopN(N, Metric) end, [] ])))))))
end.