| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package vernemq |
| 4 | |
| 5 | func newNodeStats() *nodeStats { |
| 6 | return &nodeStats{ |
| 7 | stats: make(map[string]int64), |
| 8 | mqtt4: make(map[string]int64), |
| 9 | mqtt5: make(map[string]int64), |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | type nodeStats struct { |
| 14 | stats map[string]int64 |
| 15 | mqtt4 map[string]int64 |
| 16 | mqtt5 map[string]int64 |
| 17 | } |
| 18 | |
| 19 | // Source code metrics: https://github.com/vernemq/vernemq/blob/master/apps/vmq_server/src/vmq_metrics.erl |
| 20 | // Not used metrics: https://docs.vernemq.com/monitoring/introduction |
| 21 | |
| 22 | const ( |
| 23 | // Sockets |
| 24 | metricSocketOpen = "socket_open" |
| 25 | metricSocketClose = "socket_close" |
| 26 | metricSocketError = "socket_error" |
| 27 | metricSocketCloseTimeout = "socket_close_timeout" |
| 28 | metricClientKeepaliveExpired = "client_keepalive_expired" // v4, v5 |
| 29 | |
| 30 | // Queues |
| 31 | metricQueueProcesses = "queue_processes" |
| 32 | metricQueueSetup = "queue_setup" |
| 33 | metricQueueTeardown = "queue_teardown" |
| 34 | metricQueueMessageIn = "queue_message_in" |
| 35 | metricQueueMessageOut = "queue_message_out" |
| 36 | metricQueueMessageDrop = "queue_message_drop" |
| 37 | metricQueueMessageExpired = "queue_message_expired" |
| 38 | metricQueueMessageUnhandled = "queue_message_unhandled" |
| 39 | metricQueueInitializedFromStorage = "queue_initialized_from_storage" |
| 40 | |
| 41 | // Subscriptions |
| 42 | metricRouterMatchesLocal = "router_matches_local" |
| 43 | metricRouterMatchesRemote = "router_matches_remote" |
| 44 | metricRouterMemory = "router_memory" |
| 45 | metricRouterSubscriptions = "router_subscriptions" |
| 46 | |
| 47 | // Erlang VM |
| 48 | metricSystemUtilization = "system_utilization" |
| 49 | metricSystemProcessCount = "system_process_count" |
| 50 | metricSystemReductions = "system_reductions" |
| 51 | metricSystemContextSwitches = "system_context_switches" |
| 52 | metricSystemIOIn = "system_io_in" |
| 53 | metricSystemIOOut = "system_io_out" |
| 54 | metricSystemRunQueue = "system_run_queue" |
| 55 | metricSystemGCCount = "system_gc_count" |
| 56 | metricSystemWordsReclaimedByGC = "system_words_reclaimed_by_gc" |
| 57 | metricVMMemoryProcesses = "vm_memory_processes" |
| 58 | metricVMMemorySystem = "vm_memory_system" |
| 59 | |
| 60 | // Bandwidth |
| 61 | metricBytesReceived = "bytes_received" |
| 62 | metricBytesSent = "bytes_sent" |
| 63 | |
| 64 | // Retain |
| 65 | metricRetainMemory = "retain_memory" |
| 66 | metricRetainMessages = "retain_messages" |
| 67 | |
| 68 | // Cluster |
| 69 | metricClusterBytesDropped = "cluster_bytes_dropped" |
| 70 | metricClusterBytesReceived = "cluster_bytes_received" |
| 71 | metricClusterBytesSent = "cluster_bytes_sent" |
| 72 | metricNetSplitDetected = "netsplit_detected" |
| 73 | metricNetSplitResolved = "netsplit_resolved" |
| 74 | |
| 75 | // Uptime |
| 76 | metricSystemWallClock = "system_wallclock" |
| 77 | ) |
| 78 | |
| 79 | // -----------------------------------------------MQTT------------------------------------------------------------------ |
| 80 | const ( |
| 81 | // AUTH |
| 82 | metricAUTHReceived = "mqtt_auth_received" // v5 has 'reason_code' label |
| 83 | metricAUTHSent = "mqtt_auth_sent" // v5 has 'reason_code' label |
| 84 | |
| 85 | // CONNECT |
| 86 | metricCONNECTReceived = "mqtt_connect_received" // v4, v5 |
| 87 | metricCONNACKSent = "mqtt_connack_sent" // v4 has 'return_code' label, v5 has 'reason_code' |
| 88 | |
| 89 | // SUBSCRIBE |
| 90 | metricSUBSCRIBEReceived = "mqtt_subscribe_received" // v4, v5 |
| 91 | metricSUBACKSent = "mqtt_suback_sent" // v4, v5 |
| 92 | metricSUBSCRIBEError = "mqtt_subscribe_error" // v4, v5 |
| 93 | metricSUBSCRIBEAuthError = "mqtt_subscribe_auth_error" // v4, v5 |
| 94 | |
| 95 | // UNSUBSCRIBE |
| 96 | metricUNSUBSCRIBEReceived = "mqtt_unsubscribe_received" // v4, v5 |
| 97 | metricUNSUBACKSent = "mqtt_unsuback_sent" // v4, v5 |
| 98 | metricUNSUBSCRIBEError = "mqtt_unsubscribe_error" // v4, v5 |
| 99 | |
| 100 | // PUBLISH |
| 101 | metricPUBSLISHReceived = "mqtt_publish_received" // v4, v5 |
| 102 | metricPUBSLIHSent = "mqtt_publish_sent" // v4, v5 |
| 103 | metricPUBLISHError = "mqtt_publish_error" // v4, v5 |
| 104 | metricPUBLISHAuthError = "mqtt_publish_auth_error" // v4, v5 |
| 105 | |
| 106 | // Publish acknowledgment (QoS 1) |
| 107 | metricPUBACKReceived = "mqtt_puback_received" // v4, v5 has 'reason_code' label |
| 108 | metricPUBACKSent = "mqtt_puback_sent" // v4, v5 has 'reason_code' label |
| 109 | metricPUBACKInvalid = "mqtt_puback_invalid_error" // v4, v5 |
| 110 | |
| 111 | // Publish received (QoS 2 delivery part 1) |
| 112 | metricPUBRECReceived = "mqtt_pubrec_received" // v4, v5 has 'reason_code' label |
| 113 | metricPUBRECSent = "mqtt_pubrec_sent" // v4, v5 has 'reason_code' label |
| 114 | metricPUBRECInvalid = "mqtt_pubrec_invalid_error" // v4 |
| 115 | |
| 116 | // Publish release (QoS 2 delivery part 2) |
| 117 | metricPUBRELReceived = "mqtt_pubrel_received" // v4, v5 has 'reason_code' label |
| 118 | metricPUBRELSent = "mqtt_pubrel_sent" // v4, v5 has 'reason_code' label |
| 119 | |
| 120 | // Publish complete (QoS 2 delivery part 3) |
| 121 | metricPUBCOMPReceived = "mqtt_pubcomp_received" // v4, v5 has 'reason_code' label |
| 122 | metricPUBCOMPSent = "mqtt_pubcomp_sent" // v4, v5 has 'reason_code' label |
| 123 | metricPUNCOMPInvalid = "mqtt_pubcomp_invalid_error" // v4, v5 |
| 124 | |
| 125 | // PING |
| 126 | metricPINGREQReceived = "mqtt_pingreq_received" // v4, v5 |
| 127 | metricPINGRESPSent = "mqtt_pingresp_sent" // v4, v5 |
| 128 | |
| 129 | // DISCONNECT |
| 130 | metricDISCONNECTReceived = "mqtt_disconnect_received" // v4, v5 has 'reason_code' label |
| 131 | metricDISCONNECTSent = "mqtt_disconnect_sent" // v5 has 'reason_code' label |
| 132 | |
| 133 | // Misc |
| 134 | metricMQTTInvalidMsgSizeError = "mqtt_invalid_msg_size_error" // v4, v5 |
| 135 | ) |
| 136 | |
| 137 | var ( |
| 138 | mqtt5AUTHReceivedReasonCodes = []string{ |
| 139 | "success", |
| 140 | "continue_authentication", |
| 141 | "reauthenticate", |
| 142 | } |
| 143 | mqtt5AUTHSentReasonCodes = mqtt5AUTHReceivedReasonCodes |
| 144 | |
| 145 | mqtt4CONNACKSentReturnCodes = []string{ |
| 146 | "success", |
| 147 | "unsupported_protocol_version", |
| 148 | "client_identifier_not_valid", |
| 149 | "server_unavailable", |
| 150 | "bad_username_or_password", |
| 151 | "not_authorized", |
| 152 | } |
| 153 | mqtt5CONNACKSentReasonCodes = []string{ |
| 154 | "success", |
| 155 | "unspecified_error", |
| 156 | "malformed_packet", |
| 157 | "protocol_error", |
| 158 | "impl_specific_error", |
| 159 | "unsupported_protocol_version", |
| 160 | "client_identifier_not_valid", |
| 161 | "bad_username_or_password", |
| 162 | "not_authorized", |
| 163 | "server_unavailable", |
| 164 | "server_busy", |
| 165 | "banned", |
| 166 | "bad_authentication_method", |
| 167 | "topic_name_invalid", |
| 168 | "packet_too_large", |
| 169 | "quota_exceeded", |
| 170 | "payload_format_invalid", |
| 171 | "retain_not_supported", |
| 172 | "qos_not_supported", |
| 173 | "use_another_server", |
| 174 | "server_moved", |
| 175 | "connection_rate_exceeded", |
| 176 | } |
| 177 | |
| 178 | mqtt5DISCONNECTReceivedReasonCodes = []string{ |
| 179 | "normal_disconnect", |
| 180 | "disconnect_with_will_msg", |
| 181 | "unspecified_error", |
| 182 | "malformed_packet", |
| 183 | "protocol_error", |
| 184 | "impl_specific_error", |
| 185 | "topic_name_invalid", |
| 186 | "receive_max_exceeded", |
| 187 | "topic_alias_invalid", |
| 188 | "packet_too_large", |
| 189 | "message_rate_too_high", |
| 190 | "quota_exceeded", |
| 191 | "administrative_action", |
| 192 | "payload_format_invalid", |
| 193 | } |
| 194 | mqtt5DISCONNECTSentReasonCodes = []string{ |
| 195 | "normal_disconnect", |
| 196 | "unspecified_error", |
| 197 | "malformed_packet", |
| 198 | "protocol_error", |
| 199 | "impl_specific_error", |
| 200 | "not_authorized", |
| 201 | "server_busy", |
| 202 | "server_shutting_down", |
| 203 | "keep_alive_timeout", |
| 204 | "session_taken_over", |
| 205 | "topic_filter_invalid", |
| 206 | "topic_name_invalid", |
| 207 | "receive_max_exceeded", |
| 208 | "topic_alias_invalid", |
| 209 | "packet_too_large", |
| 210 | "message_rate_too_high", |
| 211 | "quota_exceeded", |
| 212 | "administrative_action", |
| 213 | "payload_format_invalid", |
| 214 | "retain_not_supported", |
| 215 | "qos_not_supported", |
| 216 | "use_another_server", |
| 217 | "server_moved", |
| 218 | "shared_subs_not_supported", |
| 219 | "connection_rate_exceeded", |
| 220 | "max_connect_time", |
| 221 | "subscription_ids_not_supported", |
| 222 | "wildcard_subs_not_supported", |
| 223 | } |
| 224 | |
| 225 | mqtt5PUBACKReceivedReasonCodes = []string{ |
| 226 | "success", |
| 227 | "no_matching_subscribers", |
| 228 | "unspecified_error", |
| 229 | "impl_specific_error", |
| 230 | "not_authorized", |
| 231 | "topic_name_invalid", |
| 232 | "packet_id_in_use", |
| 233 | "quota_exceeded", |
| 234 | "payload_format_invalid", |
| 235 | } |
| 236 | mqtt5PUBACKSentReasonCodes = mqtt5PUBACKReceivedReasonCodes |
| 237 | |
| 238 | mqtt5PUBRECReceivedReasonCodes = mqtt5PUBACKReceivedReasonCodes |
| 239 | mqtt5PUBRECSentReasonCodes = mqtt5PUBACKReceivedReasonCodes |
| 240 | |
| 241 | mqtt5PUBRELReceivedReasonCodes = []string{ |
| 242 | "success", |
| 243 | "packet_id_not_found", |
| 244 | } |
| 245 | mqtt5PUBRELSentReasonCodes = mqtt5PUBRELReceivedReasonCodes |
| 246 | |
| 247 | mqtt5PUBCOMPReceivedReasonCodes = mqtt5PUBRELReceivedReasonCodes |
| 248 | mqtt5PUBCOMPSentReasonCodes = mqtt5PUBRELReceivedReasonCodes |
| 249 | ) |