-beam_stats_to_bins(#beam_stats
- { node_id = NodeID
- , memory = Memory
- }
-) ->
- NodeIDBin = node_id_to_bin(NodeID),
- Msgs1 = memory_to_msgs(Memory),
- Msgs2 = [statsd_msg_add_name_prefix(M, NodeIDBin) || M <- Msgs1],
- [statsd_msg_to_bin(M) || M <- Msgs2].
-
--spec memory_to_msgs([{atom(), non_neg_integer()}]) ->
- [statsd_msg()].
-memory_to_msgs(Memory) ->
- [memory_component_to_statsd_msg(MC) || MC <- Memory].
-
--spec memory_component_to_statsd_msg({atom(), non_neg_integer()}) ->
- statsd_msg().
-memory_component_to_statsd_msg({MemType, MemSize}) when MemSize >= 0 ->
- #statsd_msg
- { name = atom_to_binary(MemType, latin1)
- , value = MemSize
- , type = gauge
- }.
-
--spec statsd_msg_add_name_prefix(statsd_msg(), binary()) ->
- statsd_msg().
-statsd_msg_add_name_prefix(#statsd_msg{name=Name1}=Msg, <<NodeID/binary>>) ->
- Prefix = <<?PATH_PREFIX, ".", NodeID/binary, ".">>,
- Name2 = <<Prefix/binary, Name1/binary>>,
- Msg#statsd_msg{name=Name2}.
-
--spec statsd_msg_to_bin(statsd_msg()) ->
- binary().
-statsd_msg_to_bin(
- #statsd_msg
- { name = <<Name/binary>>
- , value = Value
- , type = Type = gauge
- }
-) when Value >= 0 ->
- TypeBin = metric_type_to_bin(Type),
- ValueBin = integer_to_binary(Value),
- << Name/binary
- , ":"
- , ValueBin/binary
- , "|"
- , TypeBin/binary
- , "\n"
- >>.
-
--spec metric_type_to_bin(metric_type()) ->
- binary().
-metric_type_to_bin(gauge) ->
- <<"g">>.
-
--spec node_id_to_bin(node()) ->
- binary().
-node_id_to_bin(NodeID) ->
- NodeIDBin = atom_to_binary(NodeID, utf8),
- re:replace(NodeIDBin, "[\@\.]", "_", [global, {return, binary}]).
+beam_stats_to_bins(#beam_stats{node_id=NodeID}=BeamStats, StaticNodeNameOpt) ->
+ NodeIDBinDefault = beam_stats_msg_graphite:node_id_to_bin(NodeID),
+ NodeIDBin = hope_option:get(StaticNodeNameOpt, NodeIDBinDefault),
+ MsgsGraphite = beam_stats_msg_graphite:of_beam_stats(BeamStats, NodeIDBin),
+ MsgsStatsD =
+ lists:map(fun beam_stats_msg_statsd_gauge:of_msg_graphite/1, MsgsGraphite),
+ lists:map(fun beam_stats_msg_statsd_gauge:to_bin/1, MsgsStatsD).