feat: implement beam_stats_msg_statsd_gauge abstraction
authorSiraaj Khandkar <siraaj@khandkar.net>
Thu, 24 Sep 2015 00:10:35 +0000 (20:10 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Thu, 24 Sep 2015 01:50:31 +0000 (21:50 -0400)
include/beam_stats_msg_statsd_gauge.hrl [new file with mode: 0644]
src/beam_stats_msg_graphite.erl
src/beam_stats_msg_statsd_gauge.erl [new file with mode: 0644]

diff --git a/include/beam_stats_msg_statsd_gauge.hrl b/include/beam_stats_msg_statsd_gauge.hrl
new file mode 100644 (file)
index 0000000..445c8a7
--- /dev/null
@@ -0,0 +1,4 @@
+-record(beam_stats_msg_statsd_gauge,
+    { name  :: binary()
+    , value :: non_neg_integer()
+    }).
index 5b4e6e2..62028b1 100644 (file)
@@ -14,6 +14,7 @@
 -export(
     [ of_beam_stats/1
     , to_bin/1
+    , path_to_bin/1
     ]).
 
 -define(T, #?MODULE).
@@ -69,12 +70,17 @@ to_bin(
     , 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
 %% ============================================================================
diff --git a/src/beam_stats_msg_statsd_gauge.erl b/src/beam_stats_msg_statsd_gauge.erl
new file mode 100644 (file)
index 0000000..07e5d02
--- /dev/null
@@ -0,0 +1,47 @@
+-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">>.
This page took 0.034221 seconds and 4 git commands to generate.