home
/
code
/
beam_stats.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: re-use graphite_msg cons/3
[beam_stats.git]
/
src
/
beam_stats_consumer_graphite.erl
diff --git
a/src/beam_stats_consumer_graphite.erl
b/src/beam_stats_consumer_graphite.erl
index
be4f1f9
..
6e0d5dd
100644
(file)
--- a/
src/beam_stats_consumer_graphite.erl
+++ b/
src/beam_stats_consumer_graphite.erl
@@
-1,6
+1,7
@@
-module(beam_stats_consumer_graphite).
-include("include/beam_stats.hrl").
-module(beam_stats_consumer_graphite).
-include("include/beam_stats.hrl").
+-include("beam_stats_logging.hrl").
-behaviour(beam_stats_consumer).
-behaviour(beam_stats_consumer).
@@
-67,7
+68,7
@@
terminate(#state{sock=SockOpt}) ->
-spec try_to_send(state(), binary()) ->
state().
try_to_send(#state{sock=none}=State, _) ->
-spec try_to_send(state(), binary()) ->
state().
try_to_send(#state{sock=none}=State, _) ->
-
io:format("error: socket closed~n
"),
+
?log_error("Sending failed. No socket in state.
"),
% TODO: Maybe schedule retry?
State;
try_to_send(#state{sock={some, Sock}}=State, Payload) ->
% TODO: Maybe schedule retry?
State;
try_to_send(#state{sock={some, Sock}}=State, Payload) ->
@@
-75,7
+76,7
@@
try_to_send(#state{sock={some, Sock}}=State, Payload) ->
of ok ->
State
; {error, _}=Error ->
of ok ->
State
; {error, _}=Error ->
-
io:format("error: gen_tcp:send/2 failed: ~p~n", [
Error]),
+
?log_error("gen_tcp:send(~p, ~p) -> ~p", [Sock, Payload,
Error]),
% TODO: Maybe schedule retry?
ok = gen_tcp:close(Sock),
State#state{sock=none}
% TODO: Maybe schedule retry?
ok = gen_tcp:close(Sock),
State#state{sock=none}
@@
-93,11
+94,15
@@
try_to_connect_if_no_socket(
, timeout = Timeout
}=State
) ->
, timeout = Timeout
}=State
) ->
- case gen_tcp:connect(Host, Port, [binary, {active, false}], Timeout)
+ Options = [binary, {active, false}],
+ case gen_tcp:connect(Host, Port, Options, Timeout)
of {ok, Sock} ->
State#state{sock = {some, Sock}}
; {error, _}=Error ->
of {ok, Sock} ->
State#state{sock = {some, Sock}}
; {error, _}=Error ->
- io:format("error: gen_tcp:connect/4 failed: ~p~n", [Error]),
+ ?log_error(
+ "gen_tcp:connect(~p, ~p, ~p, ~p) -> ~p",
+ [Host, Port, Options, Timeout, Error]
+ ),
State#state{sock = none}
end.
State#state{sock = none}
end.
@@
-118,9
+123,9
@@
beam_stats_to_bin(#beam_stats
TimestampInt = timestamp_to_integer(Timestamp),
TimestampBin = integer_to_binary(TimestampInt),
<<NodeIDBin/binary>> = node_id_to_bin(NodeID),
TimestampInt = timestamp_to_integer(Timestamp),
TimestampBin = integer_to_binary(TimestampInt),
<<NodeIDBin/binary>> = node_id_to_bin(NodeID),
-
PairToBin = make_pair_to_bin(NodeIDBin, TimestampBin
),
+
MemoryPairToBin = make_pair_to_bin(NodeIDBin, TimestampBin, <<"memory">>
),
MemoryBinPairs = lists:map(fun atom_int_to_bin_bin/1, Memory),
MemoryBinPairs = lists:map(fun atom_int_to_bin_bin/1, Memory),
- MemoryBins = lists:map(PairToBin, MemoryBinPairs),
+ MemoryBins = lists:map(
Memory
PairToBin, MemoryBinPairs),
AllBins =
[ MemoryBins
],
AllBins =
[ MemoryBins
],
@@
-131,14
+136,16
@@
beam_stats_to_bin(#beam_stats
timestamp_to_integer({Megaseconds, Seconds, _}) ->
Megaseconds * 1000000 + Seconds.
timestamp_to_integer({Megaseconds, Seconds, _}) ->
Megaseconds * 1000000 + Seconds.
--spec make_pair_to_bin(binary(), binary()) ->
+-spec make_pair_to_bin(binary(), binary()
, binary()
) ->
fun(({binary(), binary()}) -> binary()).
fun(({binary(), binary()}) -> binary()).
-make_pair_to_bin(<<NodeID/binary>>, <<TimestampBin/binary>>) ->
+make_pair_to_bin(<<NodeID/binary>>, <<TimestampBin/binary>>
, <<Type/binary>>
) ->
fun ({<<K/binary>>, <<V/binary>>}) ->
<< ?GRAPHITE_PATH_PREFIX
, "."
, NodeID/binary
, "."
fun ({<<K/binary>>, <<V/binary>>}) ->
<< ?GRAPHITE_PATH_PREFIX
, "."
, NodeID/binary
, "."
+ , Type/binary
+ , "."
, K/binary
, " "
, V/binary
, K/binary
, " "
, V/binary
This page took
0.035547 seconds
and
4
git commands to generate.