|
|
@@ -112,7 +112,6 @@
|
|
|
-define(ACTIVE_N, 100).
|
|
|
-define(INFO_KEYS, [socktype, peername, sockname, sockstate]).
|
|
|
-define(SOCK_STATS, [recv_oct, recv_cnt, send_oct, send_cnt]).
|
|
|
--define(CONN_STATS, [recv_pkt, recv_msg, send_pkt, send_msg]).
|
|
|
|
|
|
-define(ENABLED(X), (X =/= undefined)).
|
|
|
-define(LIMITER_BYTES_IN, bytes_in).
|
|
|
@@ -163,10 +162,9 @@ stats(WsPid) when is_pid(WsPid) ->
|
|
|
call(WsPid, stats);
|
|
|
stats(#state{channel = Channel}) ->
|
|
|
SockStats = emqx_pd:get_counters(?SOCK_STATS),
|
|
|
- ConnStats = emqx_pd:get_counters(?CONN_STATS),
|
|
|
ChanStats = emqx_channel:stats(Channel),
|
|
|
ProcStats = emqx_misc:proc_stats(),
|
|
|
- lists:append([SockStats, ConnStats, ChanStats, ProcStats]).
|
|
|
+ lists:append([SockStats, ChanStats, ProcStats]).
|
|
|
|
|
|
%% kick|discard|takeover
|
|
|
-spec(call(pid(), Req :: term()) -> Reply :: term()).
|
|
|
@@ -725,6 +723,7 @@ serialize_and_inc_stats_fun(#state{serialize = Serialize}) ->
|
|
|
packet => emqx_packet:format(Packet)}),
|
|
|
ok = emqx_metrics:inc('delivery.dropped.too_large'),
|
|
|
ok = emqx_metrics:inc('delivery.dropped'),
|
|
|
+ ok = inc_outgoing_stats({error, message_too_large}),
|
|
|
<<>>;
|
|
|
Data -> ?TRACE("WS-MQTT", "mqtt_packet_sent", #{packet => Packet}),
|
|
|
ok = inc_outgoing_stats(Packet),
|
|
|
@@ -762,19 +761,28 @@ inc_recv_stats(Cnt, Oct) ->
|
|
|
|
|
|
inc_incoming_stats(Packet = ?PACKET(Type)) ->
|
|
|
_ = emqx_pd:inc_counter(recv_pkt, 1),
|
|
|
- if Type == ?PUBLISH ->
|
|
|
- inc_counter(recv_msg, 1),
|
|
|
- inc_counter(incoming_pubs, 1);
|
|
|
- true -> ok
|
|
|
+ case Type of
|
|
|
+ ?PUBLISH ->
|
|
|
+ inc_counter(recv_msg, 1),
|
|
|
+ inc_qos_stats(recv_msg, Packet),
|
|
|
+ inc_counter(incoming_pubs, 1);
|
|
|
+ _ ->
|
|
|
+ ok
|
|
|
end,
|
|
|
emqx_metrics:inc_recv(Packet).
|
|
|
|
|
|
+inc_outgoing_stats({error, message_too_large}) ->
|
|
|
+ inc_counter('send_msg.dropped', 1),
|
|
|
+ inc_counter('send_msg.dropped.too_large', 1);
|
|
|
inc_outgoing_stats(Packet = ?PACKET(Type)) ->
|
|
|
- _ = emqx_pd:inc_counter(send_pkt, 1),
|
|
|
- if Type == ?PUBLISH ->
|
|
|
- inc_counter(send_msg, 1),
|
|
|
- inc_counter(outgoing_pubs, 1);
|
|
|
- true -> ok
|
|
|
+ inc_counter(send_pkt, 1),
|
|
|
+ case Type of
|
|
|
+ ?PUBLISH ->
|
|
|
+ inc_counter(send_msg, 1),
|
|
|
+ inc_counter(outgoing_pubs, 1),
|
|
|
+ inc_qos_stats(send_msg, Packet);
|
|
|
+ _ ->
|
|
|
+ ok
|
|
|
end,
|
|
|
emqx_metrics:inc_sent(Packet).
|
|
|
|
|
|
@@ -787,6 +795,25 @@ inc_sent_stats(Cnt, Oct) ->
|
|
|
inc_counter(Name, Value) ->
|
|
|
_ = emqx_pd:inc_counter(Name, Value),
|
|
|
ok.
|
|
|
+
|
|
|
+inc_qos_stats(Type, Packet) ->
|
|
|
+ case inc_qos_stats_key(Type, emqx_packet:qos(Packet)) of
|
|
|
+ undefined ->
|
|
|
+ ignore;
|
|
|
+ Key ->
|
|
|
+ inc_counter(Key, 1)
|
|
|
+ end.
|
|
|
+
|
|
|
+inc_qos_stats_key(send_msg, ?QOS_0) -> 'send_msg.qos0';
|
|
|
+inc_qos_stats_key(send_msg, ?QOS_1) -> 'send_msg.qos1';
|
|
|
+inc_qos_stats_key(send_msg, ?QOS_2) -> 'send_msg.qos2';
|
|
|
+
|
|
|
+inc_qos_stats_key(recv_msg, ?QOS_0) -> 'recv_msg.qos0';
|
|
|
+inc_qos_stats_key(recv_msg, ?QOS_1) -> 'recv_msg.qos1';
|
|
|
+inc_qos_stats_key(recv_msg, ?QOS_2) -> 'recv_msg.qos2';
|
|
|
+%% for bad qos
|
|
|
+inc_qos_stats_key(_, _) -> undefined.
|
|
|
+
|
|
|
%%--------------------------------------------------------------------
|
|
|
%% Helper functions
|
|
|
%%--------------------------------------------------------------------
|