Adding port-counting functions
TCP, UDP, SCTP, Files, and global count. Nice to find leaks.
diff --git a/src/recon.app.src b/src/recon.app.src
index 037dff1..3bb38c0 100644
--- a/src/recon.app.src
+++ b/src/recon.app.src
@@ -1,6 +1,6 @@
{application, recon,
[{description, "Diagnostic tools for production use"},
- {vsn, "0.1.1"},
+ {vsn, "0.1.2"},
{modules, [recon]},
{registered, []},
{applications, [kernel, stdlib]}]}.
diff --git a/src/recon.erl b/src/recon.erl
index 8f9122d..63cfa93 100644
--- a/src/recon.erl
+++ b/src/recon.erl
@@ -1,6 +1,7 @@
-module(recon).
-export([info/1,info/3,reductions/2]).
-export([remote_load/1, remote_load/2]).
+-export([tcp/0, udp/0, sctp/0, files/0, port_types/0]).
%%%%%%%%%%%%%%%%%%
%%% PUBLIC API %%%
@@ -50,7 +51,21 @@
remote_load(Node, Mod) ->
remote_load([Node], Mod).
+tcp() -> recon_lib:port_list(name, "tcp_inet").
+udp() -> recon_lib:port_list(name, "udp_inet").
+
+sctp() -> recon_lib:port_list(name, "sctp_inet").
+
+files() -> recon_lib:port_list(name, "efile").
+
+port_types() ->
+ lists:usort(
+ %% sorts by biggest count, smallest type
+ fun({KA,VA}, {KB,VB}) -> {VA,KB} > {VB,KA} end,
+ recon_lib:count([Name || {_, Name} <- recon_lib:port_list(name)])
+ ).
+
%%%%%%%%%%%%%%%
%%% PRIVATE %%%
%%%%%%%%%%%%%%%
diff --git a/src/recon_lib.erl b/src/recon_lib.erl
index ad42ef0..05b6492 100644
--- a/src/recon_lib.erl
+++ b/src/recon_lib.erl
@@ -1,5 +1,6 @@
-module(recon_lib).
--export([sliding_window/2, sample/2, count/1]).
+-export([sliding_window/2, sample/2, count/1,
+ port_list/1, port_list/2]).
-type diff() :: [{Key::term(), Diff::number(), Other::term()}].
@@ -37,3 +38,11 @@
),
dict:to_list(Dict).
+port_list(Attr) ->
+ [{Port,Val} || Port <- erlang:ports(),
+ {_, Val} <- [erlang:port_info(Port, Attr)]].
+
+port_list(Attr, Val) ->
+ [Port || Port <- erlang:ports(),
+ {Attr, Val} =:= erlang:port_info(Port, Attr)].
+