Skip to content

Commit

Permalink
use otp unix domain sockets
Browse files Browse the repository at this point in the history
* Remove afunix
  • Loading branch information
rozap committed Aug 7, 2017
1 parent 6e91b57 commit e1f9e33
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
%% -*- erlang -*-
{deps,
[
{exometer_core, ".*", {git, "git://github.com/Feuerlabs/exometer_core.git", "09c2a93"}},
{afunix, ".*", {git, "git://github.com/tonyrog/afunix.git", "180eed9"}}
{exometer_core, ".*", {git, "git://github.com/Feuerlabs/exometer_core.git", "09c2a93"}}
]}.

{erl_opts,
Expand Down
2 changes: 1 addition & 1 deletion src/exometer_collectd.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{vsn, git},
{registered, []},
{applications, [kernel, stdlib,
lager, afunix, exometer_core]},
lager, exometer_core]},
{included_applications, []},
{env, []}
]}.
13 changes: 7 additions & 6 deletions src/exometer_report_collectd.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
-define(UNIX_EPOCH, 62167219200).

exometer_init(Opts) ->
?log(info, "exometer_report_collectd(~p): Starting~n", [Opts]),
?log(info, "Exometer(~p): Starting~n", [Opts]),
SockPath = get_opt(path, Opts, ?DEFAULT_PATH),
ConnectTimeout = get_opt(connect_timeout, Opts, ?CONNECT_TIMEOUT),
ReconnectInterval =
Expand Down Expand Up @@ -119,6 +119,7 @@ exometer_init(Opts) ->
},
case connect_collectd(SockPath, ConnectTimeout) of
{ok, Sock} ->
?log(info, "Exometer collectd connection succeeded"),
{ok, St0#st{socket = Sock}};
{error, _} = Error ->
?log(warning, "Exometer collectd connection failed; ~p. Retry in ~p~n",
Expand Down Expand Up @@ -247,7 +248,7 @@ report_exometer_(Metric, DataPoint, Extra, Value,
type_map = TypeMap} = St) ->
case get_type(TypeMap, Extra, ets_key(Metric, DataPoint)) of
error ->
?log(warning,
?log(warning,
"Could not resolve ~p to a collectd type."
"Update exometer_report_collectd -> type_map in app.config. "
"Value lost~n", [ets_key(Metric, DataPoint)]),
Expand All @@ -262,9 +263,9 @@ report_exometer_(Metric, DataPoint, Extra, Value,

send_request(Sock, Request, Metric, DataPoint, Extra, Value,
#st{read_timeout = TOut} = St) ->
try afunix:send(Sock, Request) of
try gen_tcp:send(Sock, Request) of
ok ->
case afunix:recv(Sock, 0, TOut) of
case gen_tcp:recv(Sock, 0, TOut) of
{ok, Bin} ->
%% Parse the reply
case parse_reply(Request, Bin, St) of
Expand Down Expand Up @@ -351,7 +352,7 @@ connect_collectd(St) ->
end.

connect_collectd(SocketPath, ConnectTimeout) ->
afunix:connect(SocketPath, [{active, false}, {mode, binary}], ConnectTimeout).
gen_tcp:connect({local, SocketPath}, 0, [{active, false}, {mode, binary}, local], ConnectTimeout).

unix_time() ->
datetime_to_unix_time(erlang:universaltime()).
Expand Down Expand Up @@ -422,7 +423,7 @@ get_type(TypeMap, Extra, Name) ->

maybe_reconnect_after(Socket) ->
%% Close socket if open
if Socket =/= undefined -> afunix:close(Socket);
if Socket =/= undefined -> gen_tcp:close(Socket);
true -> true
end,
prepare_reconnect().
Expand Down

0 comments on commit e1f9e33

Please sign in to comment.