dd01455894022b87d2e5e9b6020243c9761bcaeb
[beam_stats.git] / test / beam_stats_consumer_statsd_SUITE.erl
1 -module(beam_stats_consumer_statsd_SUITE).
2
3 -include_lib("beam_stats/include/beam_stats.hrl").
4 -include_lib("beam_stats/include/beam_stats_ets_table.hrl").
5
6 -export(
7 [ all/0
8 , groups/0
9 ]).
10
11 %% Test cases
12 -export(
13 [ t_send/1
14 ]).
15
16 -define(GROUP, beam_stats_consumer_statsd).
17
18 %% ============================================================================
19 %% Common Test callbacks
20 %% ============================================================================
21
22 all() ->
23 [{group, ?GROUP}].
24
25 groups() ->
26 Tests =
27 [ t_send
28 ],
29 Properties = [],
30 [{?GROUP, Properties, Tests}].
31
32 %% =============================================================================
33 %% Test cases
34 %% =============================================================================
35
36 t_send(_Cfg) ->
37 ETSTableStatsFoo =
38 #beam_stats_ets_table
39 { id = foo
40 , name = foo
41 , size = 5
42 , memory = 25
43 },
44 ETSTableStatsBar =
45 #beam_stats_ets_table
46 { id = 37
47 , name = bar
48 , size = 8
49 , memory = 38
50 },
51 % TODO: Indent #beam_stats as #beam_stats_ets_table
52 BEAMStats = #beam_stats
53 { timestamp = {1, 2, 3}
54 , node_id = 'node_foo@host_bar'
55 , memory = [{mem_type_foo, 1}]
56 , io_bytes_in = 3
57 , io_bytes_out = 7
58 , context_switches = 5
59 , reductions = 9
60 , run_queue = 17
61 , ets = [ETSTableStatsFoo, ETSTableStatsBar]
62 },
63 ServerPort = 8125,
64 {ok, ServerSocket} = gen_udp:open(ServerPort, [binary, {active, false}]),
65 BEAMStatsQ = queue:in(BEAMStats, queue:new()),
66 Options = [{dst_port, ServerPort}],
67 {_, State1} = beam_stats_consumer_statsd:init(Options),
68 State2 = beam_stats_consumer_statsd:consume(BEAMStatsQ, State1),
69 {} = beam_stats_consumer_statsd:terminate(State2),
70 ResultOfReceive = gen_udp:recv(ServerSocket, 0),
71 ok = gen_udp:close(ServerSocket),
72 {ok, {_, _, Data}} = ResultOfReceive,
73 ct:log("Packet: ~n~s~n", [Data]),
74 << "beam_stats.node_foo_host_bar.io.bytes_in:3|g\n"
75 , "beam_stats.node_foo_host_bar.io.bytes_out:7|g\n"
76 , "beam_stats.node_foo_host_bar.context_switches:5|g\n"
77 , "beam_stats.node_foo_host_bar.reductions:9|g\n"
78 , "beam_stats.node_foo_host_bar.run_queue:17|g\n"
79 , "beam_stats.node_foo_host_bar.memory.mem_type_foo:1|g\n"
80 , "beam_stats.node_foo_host_bar.ets_table.size.foo.foo:5|g\n"
81 , "beam_stats.node_foo_host_bar.ets_table.memory.foo.foo:25|g\n"
82 , "beam_stats.node_foo_host_bar.ets_table.size.bar.37:8|g\n"
83 , "beam_stats.node_foo_host_bar.ets_table.memory.bar.37:38|g\n"
84 >> = Data.
This page took 0.047475 seconds and 3 git commands to generate.