|
| 1 | +%% This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +%% License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +%% file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | +%% |
| 5 | +%% Copyright (c) 2007-2021 VMware, Inc. or its affiliates. All rights reserved. |
| 6 | +%% |
| 7 | + |
| 8 | +-module(rabbit_global_counters). |
| 9 | +-on_load(init/0). |
| 10 | + |
| 11 | +-export([ |
| 12 | + init/0, |
| 13 | + overview/0, |
| 14 | + messages_received/2, |
| 15 | + messages_routed/2%, |
| 16 | + % messages_delivered_consume_ack/3, |
| 17 | + % messages_delivered_consume_autoack/3, |
| 18 | + % messages_delivered_get_ack/3, |
| 19 | + % messages_delivered_get_autoack/3, |
| 20 | + % messages_redelivered/3, |
| 21 | + % basic_get_empty/3, |
| 22 | + % messages_unroutable_dropped/3, |
| 23 | + % messages_unroutable_returned/3, |
| 24 | + % messages_confirmed/3 |
| 25 | + ]). |
| 26 | + |
| 27 | + |
| 28 | +-define(MESSAGES_RECEIVED, 1). |
| 29 | +-define(MESSAGES_ROUTED, 2). |
| 30 | +% -define(MESSAGES_DELIVERED_CONSUME_ACK, 3). |
| 31 | +% -define(MESSAGES_DELIVERED_CONSUME_AUTOACK, 4). |
| 32 | +% -define(MESSAGES_DELIVERED_GET_ACK, 5). |
| 33 | +% -define(MESSAGES_DELIVERED_GET_AUTOACK, 6). |
| 34 | +% -define(MESSAGES_REDELIVERED, 7). |
| 35 | +% -define(BASIC_GET_EMPTY, 8). |
| 36 | +% -define(MESSAGES_UNROUTABLE_DROPPED, 9). |
| 37 | +% -define(MESSAGES_UNROUTABLE_RETURNED, 10). |
| 38 | +% -define(MESSAGES_CONFIRMED, 11). |
| 39 | + |
| 40 | +-define(COUNTERS, |
| 41 | + [ |
| 42 | + { |
| 43 | + messages_received_total, ?MESSAGES_RECEIVED, counter, |
| 44 | + "Total number of messages received from publishers" |
| 45 | + }, |
| 46 | + { |
| 47 | + messages_routed_total, ?MESSAGES_ROUTED, counter, |
| 48 | + "Total number of messages routed to queues or streams" |
| 49 | + }%, |
| 50 | + % { |
| 51 | + % messages_delivered_consume_ack_total, ?MESSAGES_DELIVERED_CONSUME_ACK, counter, |
| 52 | + % "Total number of messages consumed using basic.consume with manual acknowledgment" |
| 53 | + % }, |
| 54 | + % { |
| 55 | + % messages_delivered_consume_autoack_total, ?MESSAGES_DELIVERED_CONSUME_AUTOACK, counter, |
| 56 | + % "Total number of messages consumed using basic.consume with automatic acknowledgment" |
| 57 | + % }, |
| 58 | + % { |
| 59 | + % messages_delivered_get_ack_total, ?MESSAGES_DELIVERED_GET_ACK, counter, |
| 60 | + % "Total number of messages consumed using basic.get with manual acknowledgment" |
| 61 | + % }, |
| 62 | + % { |
| 63 | + % messages_delivered_get_autoack_total, ?MESSAGES_DELIVERED_GET_AUTOACK, counter, |
| 64 | + % "Total number of messages consumed using basic.get with automatic acknowledgment" |
| 65 | + % }, |
| 66 | + % { |
| 67 | + % messages_redelivered_total, ?MESSAGES_REDELIVERED, counter, |
| 68 | + % "Total number of messages redelivered to consumers" |
| 69 | + % }, |
| 70 | + % { |
| 71 | + % basic_get_empty_total, ?BASIC_GET_EMPTY, counter, |
| 72 | + % "Total number of times basic.get operations fetched no message" |
| 73 | + % }, |
| 74 | + % { |
| 75 | + % messages_unroutable_dropped_total, ?MESSAGES_UNROUTABLE_DROPPED, counter, |
| 76 | + % "Total number of messages published as non-mandatory into an exchange and dropped as unroutable" |
| 77 | + % }, |
| 78 | + % { |
| 79 | + % messages_unroutable_returned_total, ?MESSAGES_UNROUTABLE_RETURNED, counter, |
| 80 | + % "Total number of messages published as mandatory into an exchange and returned to the publisher as unroutable" |
| 81 | + % }, |
| 82 | + % { |
| 83 | + % messages_confirmed_total, ?MESSAGES_CONFIRMED, counter, |
| 84 | + % "Total number of messages confirmed to publishers" |
| 85 | + % } |
| 86 | + ]). |
| 87 | + |
| 88 | +init() -> |
| 89 | + _ = seshat_counters:new_group(global), |
| 90 | + CategoryCounters = seshat_counters:new(global, all, ?COUNTERS), |
| 91 | + persistent_term:put({?MODULE, all}, CategoryCounters), |
| 92 | + ok. |
| 93 | + |
| 94 | +overview() -> |
| 95 | + seshat_counters:overview(global). |
| 96 | + |
| 97 | +messages_received(Category, Num) -> |
| 98 | + counters:add(fetch(Category), ?MESSAGES_RECEIVED, Num). |
| 99 | + |
| 100 | +% formerly known as queue_messages_published_total |
| 101 | +messages_routed(Category, Num) -> |
| 102 | + counters:add(fetch(Category), ?MESSAGES_ROUTED, Num). |
| 103 | + |
| 104 | +% messages_delivered_consume_ack(Group, Object, Num) -> |
| 105 | +% counters:add(fetch(Group, Object), ?MESSAGES_DELIVERED_CONSUME_ACK, Num). |
| 106 | + |
| 107 | +% messages_delivered_consume_autoack(Group, Object, Num) -> |
| 108 | +% counters:add(fetch(Group, Object), ?MESSAGES_DELIVERED_CONSUME_AUTOACK, Num). |
| 109 | + |
| 110 | +% messages_delivered_get_ack(Group, Object, Num) -> |
| 111 | +% counters:add(fetch(Group, Object), ?MESSAGES_DELIVERED_GET_ACK, Num). |
| 112 | + |
| 113 | +% messages_delivered_get_autoack(Group, Object, Num) -> |
| 114 | +% counters:add(fetch(Group, Object), ?MESSAGES_DELIVERED_GET_AUTOACK, Num). |
| 115 | + |
| 116 | +% % not implemented yet |
| 117 | +% messages_redelivered(Group, Object, Num) -> |
| 118 | +% counters:add(fetch(Group, Object), ?MESSAGES_REDELIVERED, Num). |
| 119 | + |
| 120 | +% basic_get_empty(Group, Object, Num) -> |
| 121 | +% counters:add(fetch(Group, Object), ?BASIC_GET_EMPTY, Num). |
| 122 | + |
| 123 | +% % implemented in rabbit_core_metrics (it doesn't reach a queue) |
| 124 | +% messages_unroutable_returned(Group, Object, Num) -> |
| 125 | +% counters:add(fetch(Group, Object), ?MESSAGES_UNROUTABLE_RETURNED, Num). |
| 126 | + |
| 127 | +% % implemented in rabbit_core_metrics (it doesn't reach a queue) |
| 128 | +% messages_unroutable_dropped(Group, Object, Num) -> |
| 129 | +% counters:add(fetch(Group, Object), ?MESSAGES_UNROUTABLE_DROPPED, Num). |
| 130 | + |
| 131 | +% messages_confirmed(Group, Object, Num) -> |
| 132 | +% counters:add(fetch(Group, Object), ?MESSAGES_CONFIRMED, Num). |
| 133 | + |
| 134 | +fetch(Category) -> |
| 135 | + persistent_term:get({?MODULE, Category}). |
| 136 | + |
| 137 | +% TODO |
| 138 | +% channel_messages_redelivered_total "Total number of messages redelivered to consumers" |
| 139 | +% |
| 140 | +% connection_incoming_bytes_total "Total number of bytes received on a connection" |
| 141 | +% connection_outgoing_bytes_total "Total number of bytes sent on a connection" |
| 142 | +% connection_process_reductions_total "Total number of connection process reductions" |
| 143 | +% connection_incoming_packets_total "Total number of packets received on a connection" |
| 144 | +% connection_outgoing_packets_total "Total number of packets sent on a connection" |
| 145 | +% |
| 146 | +% io_read_ops_total "Total number of I/O read operations" |
| 147 | +% io_read_bytes_total "Total number of I/O bytes read" |
| 148 | +% io_write_ops_total "Total number of I/O write operations" |
| 149 | +% io_write_bytes_total "Total number of I/O bytes written" |
| 150 | +% io_sync_ops_total "Total number of I/O sync operations" |
| 151 | +% io_seek_ops_total "Total number of I/O seek operations" |
| 152 | +% io_open_attempt_ops_total "Total number of file open attempts" |
| 153 | +% io_reopen_ops_total "Total number of times files have been reopened" |
| 154 | +% |
| 155 | +% schema_db_ram_tx_total "Total number of Schema DB memory transactions" |
| 156 | +% schema_db_disk_tx_total "Total number of Schema DB disk transactions" |
| 157 | +% msg_store_read_total "Total number of Message Store read operations" |
| 158 | +% msg_store_write_total "Total number of Message Store write operations" |
| 159 | +% queue_index_read_ops_total "Total number of Queue Index read operations" |
| 160 | +% queue_index_write_ops_total "Total number of Queue Index write operations" |
| 161 | +% queue_index_journal_write_ops_total "Total number of Queue Index Journal write operations" |
| 162 | +% io_read_time_seconds_total "Total I/O read time" |
| 163 | +% io_write_time_seconds_total "Total I/O write time" |
| 164 | +% io_sync_time_seconds_total "Total I/O sync time" |
| 165 | +% io_seek_time_seconds_total "Total I/O seek time" |
| 166 | +% io_open_attempt_time_seconds_total "Total file open attempts time" |
| 167 | +% raft_term_total "Current Raft term number" |
| 168 | +% queue_disk_reads_total "Total number of times queue read messages from disk" |
| 169 | +% queue_disk_writes_total "Total number of times queue wrote messages to disk" |
| 170 | + |
| 171 | +% DONE |
| 172 | +% channel_messages_published_total "Total number of messages published into an exchange on a channel" |
| 173 | +% channel_messages_confirmed_total "Total number of messages published into an exchange and confirmed on the channel" |
| 174 | +% channel_messages_unroutable_returned_total "Total number of messages published as mandatory into an exchange and returned to the publisher as unroutable" |
| 175 | +% channel_messages_unroutable_dropped_total "Total number of messages published as non-mandatory into an exchange and dropped as unroutable" |
| 176 | +% channel_get_empty_total "Total number of times basic.get operations fetched no message" |
| 177 | +% channel_get_ack_total "Total number of messages fetched with basic.get in manual acknowledgement mode" |
| 178 | +% channel_get_total "Total number of messages fetched with basic.get in automatic acknowledgement mode" |
| 179 | +% channel_messages_delivered_ack_total "Total number of messages delivered to consumers in manual acknowledgement mode" |
| 180 | +% channel_messages_delivered_total "Total number of messages delivered to consumers in automatic acknowledgement mode" |
| 181 | +% queue_messages_published_total "Total number of messages published to queues" |
| 182 | + |
| 183 | +% IGNORED (IS THIS USEFUL?) |
| 184 | +% channel_process_reductions_total "Total number of channel process reductions" |
| 185 | +% queue_process_reductions_total "Total number of queue process reductions" |
| 186 | + |
| 187 | +% NOT NECESSARY (DON'T GO TO ZERO) |
| 188 | +% erlang_gc_runs_total "Total number of Erlang garbage collector runs" |
| 189 | +% erlang_gc_reclaimed_bytes_total "Total number of bytes of memory reclaimed by Erlang garbage collector" |
| 190 | +% erlang_scheduler_context_switches_total "Total number of Erlang scheduler context switches" |
| 191 | +% connections_opened_total "Total number of connections opened" |
| 192 | +% connections_closed_total "Total number of connections closed or terminated" |
| 193 | +% channels_opened_total "Total number of channels opened" |
| 194 | +% channels_closed_total "Total number of channels closed" |
| 195 | +% queues_declared_total "Total number of queues declared" |
| 196 | +% queues_created_total "Total number of queues created" |
| 197 | +% queues_deleted_total "Total number of queues deleted" |
| 198 | +% auth_attempts_total "Total number of authorization attempts" |
| 199 | +% auth_attempts_succeeded_total "Total number of successful authentication attempts" |
| 200 | +% auth_attempts_failed_total "Total number of failed authentication attempts" |
| 201 | +% auth_attempts_detailed_total "Total number of authorization attempts with source info" |
| 202 | +% auth_attempts_detailed_succeeded_total "Total number of successful authorization attempts with source info" |
| 203 | +% auth_attempts_detailed_failed_total "Total number of failed authorization attempts with source info" |
0 commit comments