|
183 | 183 |
|
184 | 184 | -define(INFO_KEYS, ?CREATION_EVENT_KEYS ++ ?STATISTICS_KEYS -- [pid]).
|
185 | 185 |
|
186 |
| --define(INCR_STATS(Incs, Measure, State), |
| 186 | +-define(INCR_STATS(Type, Key, Inc, Measure, State), |
187 | 187 | case rabbit_event:stats_level(State, #ch.stats_timer) of
|
188 |
| - fine -> incr_stats(Incs, Measure); |
189 |
| - _ -> ok |
| 188 | + fine -> |
| 189 | + rabbit_core_metrics:channel_stats(Type, Measure, {self(), Key}, Inc), |
| 190 | + %% Keys in the process dictionary are used to clean up the core metrics |
| 191 | + put({Type, Key}, none); |
| 192 | + _ -> |
| 193 | + ok |
| 194 | + end). |
| 195 | + |
| 196 | +-define(INCR_STATS(Type, Key, Inc, Measure), |
| 197 | + begin |
| 198 | + rabbit_core_metrics:channel_stats(Type, Measure, {self(), Key}, Inc), |
| 199 | + %% Keys in the process dictionary are used to clean up the core metrics |
| 200 | + put({Type, Key}, none) |
190 | 201 | end).
|
191 | 202 |
|
192 | 203 | %%----------------------------------------------------------------------------
|
@@ -1611,7 +1622,7 @@ basic_return(#basic_message{exchange_name = ExchangeName,
|
1611 | 1622 | content = Content},
|
1612 | 1623 | State = #ch{protocol = Protocol, writer_pid = WriterPid},
|
1613 | 1624 | Reason) ->
|
1614 |
| - ?INCR_STATS([{exchange_stats, ExchangeName, 1}], return_unroutable, State), |
| 1625 | + ?INCR_STATS(exchange_stats, ExchangeName, 1, return_unroutable, State), |
1615 | 1626 | {_Close, ReplyCode, ReplyText} = Protocol:lookup_amqp_exception(Reason),
|
1616 | 1627 | ok = rabbit_writer:send_command(
|
1617 | 1628 | WriterPid,
|
@@ -1648,14 +1659,14 @@ record_sent(ConsumerTag, AckRequired,
|
1648 | 1659 | user = #user{username = Username},
|
1649 | 1660 | conn_name = ConnName,
|
1650 | 1661 | channel = ChannelNum}) ->
|
1651 |
| - ?INCR_STATS([{queue_stats, QName, 1}], case {ConsumerTag, AckRequired} of |
1652 |
| - {none, true} -> get; |
1653 |
| - {none, false} -> get_no_ack; |
1654 |
| - {_ , true} -> deliver; |
1655 |
| - {_ , false} -> deliver_no_ack |
1656 |
| - end, State), |
| 1662 | + ?INCR_STATS(queue_stats, QName, 1, case {ConsumerTag, AckRequired} of |
| 1663 | + {none, true} -> get; |
| 1664 | + {none, false} -> get_no_ack; |
| 1665 | + {_ , true} -> deliver; |
| 1666 | + {_ , false} -> deliver_no_ack |
| 1667 | + end, State), |
1657 | 1668 | case Redelivered of
|
1658 |
| - true -> ?INCR_STATS([{queue_stats, QName, 1}], redeliver, State); |
| 1669 | + true -> ?INCR_STATS(queue_stats, QName, 1, redeliver, State); |
1659 | 1670 | false -> ok
|
1660 | 1671 | end,
|
1661 | 1672 | rabbit_trace:tap_out(Msg, ConnName, ChannelNum, Username, TraceState),
|
@@ -1700,11 +1711,11 @@ ack(Acked, State = #ch{queue_names = QNames}) ->
|
1700 | 1711 | foreach_per_queue(
|
1701 | 1712 | fun (QPid, MsgIds) ->
|
1702 | 1713 | ok = rabbit_amqqueue:ack(QPid, MsgIds, self()),
|
1703 |
| - ?INCR_STATS(case maps:find(QPid, QNames) of |
1704 |
| - {ok, QName} -> Count = length(MsgIds), |
1705 |
| - [{queue_stats, QName, Count}]; |
1706 |
| - error -> [] |
1707 |
| - end, ack, State) |
| 1714 | + case maps:find(QPid, QNames) of |
| 1715 | + {ok, QName} -> Count = length(MsgIds), |
| 1716 | + ?INCR_STATS(queue_stats, QName, Count, ack, State); |
| 1717 | + error -> ok |
| 1718 | + end |
1708 | 1719 | end, Acked),
|
1709 | 1720 | ok = notify_limiter(State#ch.limiter, Acked).
|
1710 | 1721 |
|
@@ -1769,7 +1780,7 @@ deliver_to_queues({#delivery{message = #basic_message{exchange_name = XName},
|
1769 | 1780 | confirm = false,
|
1770 | 1781 | mandatory = false},
|
1771 | 1782 | []}, State) -> %% optimisation
|
1772 |
| - ?INCR_STATS([{exchange_stats, XName, 1}], publish, State), |
| 1783 | + ?INCR_STATS(exchange_stats, XName, 1, publish, State), |
1773 | 1784 | State;
|
1774 | 1785 | deliver_to_queues({Delivery = #delivery{message = Message = #basic_message{
|
1775 | 1786 | exchange_name = XName},
|
@@ -1806,11 +1817,15 @@ deliver_to_queues({Delivery = #delivery{message = Message = #basic_message{
|
1806 | 1817 | Message, State1),
|
1807 | 1818 | State3 = process_routing_confirm( Confirm, DeliveredQPids, MsgSeqNo,
|
1808 | 1819 | XName, State2),
|
1809 |
| - ?INCR_STATS([{exchange_stats, XName, 1} | |
1810 |
| - [{queue_exchange_stats, {QName, XName}, 1} || |
1811 |
| - QPid <- DeliveredQPids, |
1812 |
| - {ok, QName} <- [maps:find(QPid, QNames1)]]], |
1813 |
| - publish, State3), |
| 1820 | + case rabbit_event:stats_level(State3, #ch.stats_timer) of |
| 1821 | + fine -> |
| 1822 | + ?INCR_STATS(exchange_stats, XName, 1, publish), |
| 1823 | + [?INCR_STATS(queue_exchange_stats, {QName, XName}, 1, publish) || |
| 1824 | + QPid <- DeliveredQPids, |
| 1825 | + {ok, QName} <- [maps:find(QPid, QNames1)]]; |
| 1826 | + _ -> |
| 1827 | + ok |
| 1828 | + end, |
1814 | 1829 | State3.
|
1815 | 1830 |
|
1816 | 1831 | process_routing_mandatory(false, _, _MsgSeqNo, _Msg, State) ->
|
@@ -1853,7 +1868,7 @@ send_confirms(State = #ch{tx = none, confirmed = C}) ->
|
1853 | 1868 | ok -> MsgSeqNos =
|
1854 | 1869 | lists:foldl(
|
1855 | 1870 | fun ({MsgSeqNo, XName}, MSNs) ->
|
1856 |
| - ?INCR_STATS([{exchange_stats, XName, 1}], |
| 1871 | + ?INCR_STATS(exchange_stats, XName, 1, |
1857 | 1872 | confirm, State),
|
1858 | 1873 | [MsgSeqNo | MSNs]
|
1859 | 1874 | end, [], lists:append(C)),
|
@@ -1953,17 +1968,14 @@ i(Item, _) ->
|
1953 | 1968 | name(#ch{conn_name = ConnName, channel = Channel}) ->
|
1954 | 1969 | list_to_binary(rabbit_misc:format("~s (~p)", [ConnName, Channel])).
|
1955 | 1970 |
|
1956 |
| -incr_stats(Incs, Measure) -> |
1957 |
| - [begin |
1958 |
| - rabbit_core_metrics:channel_stats(Type, Measure, {self(), Key}, Inc), |
1959 |
| - %% Keys in the process dictionary are used to clean up the core metrics |
1960 |
| - put({Type, Key}, none) |
1961 |
| - end || {Type, Key, Inc} <- Incs]. |
1962 |
| - |
1963 | 1971 | emit_stats(State) -> emit_stats(State, []).
|
1964 | 1972 |
|
1965 | 1973 | emit_stats(State, Extra) ->
|
1966 | 1974 | [{reductions, Red} | Coarse0] = infos(?STATISTICS_KEYS, State),
|
| 1975 | + %% First metric must be `idle_since` (if available), as expected by |
| 1976 | + %% `rabbit_mgmt_format:format_channel_stats`. This is a performance |
| 1977 | + %% optimisation that avoids traversing the whole list when only |
| 1978 | + %% one element has to be formatted. |
1967 | 1979 | rabbit_core_metrics:channel_stats(self(), Extra ++ Coarse0),
|
1968 | 1980 | rabbit_core_metrics:channel_stats(reductions, self(), Red).
|
1969 | 1981 |
|
|
0 commit comments