--- /dev/null
+-record(beam_stats_msg_statsd_gauge,
+ { name :: binary()
+ , value :: non_neg_integer()
+ }).
-export(
[ of_beam_stats/1
, to_bin/1
+ , path_to_bin/1
]).
-define(T, #?MODULE).
, timestamp = Timestamp
}
) ->
- PathBin = bin_join(Path, <<".">>),
+ PathBin = path_to_bin(Path),
ValueBin = integer_to_binary(Value),
TimestampInt = timestamp_to_integer(Timestamp),
TimestampBin = integer_to_binary(TimestampInt),
<<PathBin/binary, " ", ValueBin/binary, " ", TimestampBin/binary>>.
+-spec path_to_bin([binary()]) ->
+ binary().
+path_to_bin(Path) ->
+ bin_join(Path, <<".">>).
+
%% ============================================================================
%% Helpers
%% ============================================================================
--- /dev/null
+-module(beam_stats_msg_statsd_gauge).
+
+-include("include/beam_stats_msg_graphite.hrl").
+-include("include/beam_stats_msg_statsd_gauge.hrl").
+
+-export_type(
+ [ t/0
+ ]).
+
+-export(
+ [ of_msg_graphite/1
+ , to_bin/1
+ ]).
+
+-define(T, #?MODULE).
+
+-type t() ::
+ ?T{}.
+
+of_msg_graphite(
+ #beam_stats_msg_graphite
+ { path = Path
+ , value = Value
+ , timestamp = _Timestamp
+ }
+) ->
+ PathBin = beam_stats_msg_graphite:path_to_bin(Path),
+ cons(PathBin, Value).
+
+-spec cons(binary(), non_neg_integer()) ->
+ t().
+cons(<<Name/binary>>, Value) ->
+ ?T
+ { name = Name
+ , value = Value
+ }.
+
+-spec to_bin(t()) ->
+ binary().
+to_bin(
+ ?T
+ { name = <<Name/binary>>
+ , value = Value
+ }
+) when Value >= 0 ->
+ ValueBin = integer_to_binary(Value),
+ << Name/binary, ":", ValueBin/binary, "|g\n">>.