mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-24 17:44:08 +08:00
Extend metrics to all packets.
Not published in $SYS, may be made available for plugins.
This commit is contained in:
@@ -23,6 +23,7 @@ Contributors:
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
# include "mosquitto_broker_internal.h"
|
||||
# include "sys_tree.h"
|
||||
#endif
|
||||
|
||||
#include "logging_mosq.h"
|
||||
@@ -200,6 +201,7 @@ int send__connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session
|
||||
# ifdef WITH_BRIDGE
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Bridge %s sending CONNECT", SAFE_PRINT(clientid));
|
||||
# endif
|
||||
metrics__int_inc(mosq_counter_mqtt_connect_sent, 1);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending CONNECT", SAFE_PRINT(clientid));
|
||||
#endif
|
||||
|
||||
@@ -78,6 +78,9 @@ int send__disconnect(struct mosquitto *mosq, uint8_t reason_code, const mosquitt
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
metrics__int_inc(mosq_counter_mqtt_disconnect_sent, 1);
|
||||
#endif
|
||||
return packet__queue(mosq, packet);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ int send__pingreq(struct mosquitto *mosq)
|
||||
rc = send__simple_command(mosq, CMD_PINGREQ);
|
||||
if(rc == MOSQ_ERR_SUCCESS){
|
||||
mosq->ping_t = mosquitto_time();
|
||||
#ifdef WITH_BROKER
|
||||
metrics__int_inc(mosq_counter_mqtt_pingreq_sent, 1);
|
||||
#endif
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
@@ -59,6 +62,7 @@ int send__pingresp(struct mosquitto *mosq)
|
||||
{
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PINGRESP to %s", SAFE_PRINT(mosq->id));
|
||||
metrics__int_inc(mosq_counter_mqtt_pingresp_sent, 1);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PINGRESP", SAFE_PRINT(mosq->id));
|
||||
#endif
|
||||
@@ -69,6 +73,7 @@ int send__puback(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code, cons
|
||||
{
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBACK to %s (m%d, rc%d)", SAFE_PRINT(mosq->id), mid, reason_code);
|
||||
metrics__int_inc(mosq_counter_mqtt_puback_sent, 1);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBACK (m%d, rc%d)", SAFE_PRINT(mosq->id), mid, reason_code);
|
||||
#endif
|
||||
@@ -81,6 +86,7 @@ int send__pubcomp(struct mosquitto *mosq, uint16_t mid, const mosquitto_property
|
||||
{
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBCOMP to %s (m%d)", SAFE_PRINT(mosq->id), mid);
|
||||
metrics__int_inc(mosq_counter_mqtt_pubcomp_sent, 1);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBCOMP (m%d)", SAFE_PRINT(mosq->id), mid);
|
||||
#endif
|
||||
@@ -94,6 +100,7 @@ int send__pubrec(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code, cons
|
||||
{
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBREC to %s (m%d, rc%d)", SAFE_PRINT(mosq->id), mid, reason_code);
|
||||
metrics__int_inc(mosq_counter_mqtt_pubrec_sent, 1);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBREC (m%d, rc%d)", SAFE_PRINT(mosq->id), mid, reason_code);
|
||||
#endif
|
||||
@@ -108,6 +115,7 @@ int send__pubrel(struct mosquitto *mosq, uint16_t mid, const mosquitto_property
|
||||
{
|
||||
#ifdef WITH_BROKER
|
||||
log__printf(NULL, MOSQ_LOG_DEBUG, "Sending PUBREL to %s (m%d)", SAFE_PRINT(mosq->id), mid);
|
||||
metrics__int_inc(mosq_counter_mqtt_pubrel_sent, 1);
|
||||
#else
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending PUBREL (m%d)", SAFE_PRINT(mosq->id), mid);
|
||||
#endif
|
||||
|
||||
@@ -23,6 +23,7 @@ Contributors:
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
# include "mosquitto_broker_internal.h"
|
||||
# include "sys_tree.h"
|
||||
#endif
|
||||
|
||||
#include "mosquitto.h"
|
||||
@@ -91,5 +92,8 @@ int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, char *con
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
metrics__int_inc(mosq_counter_mqtt_subscribe_sent, 1);
|
||||
#endif
|
||||
return packet__queue(mosq, packet);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ Contributors:
|
||||
|
||||
#ifdef WITH_BROKER
|
||||
# include "mosquitto_broker_internal.h"
|
||||
# include "sys_tree.h"
|
||||
#endif
|
||||
|
||||
#include "mosquitto.h"
|
||||
@@ -86,6 +87,7 @@ int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, char *c
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Bridge %s sending UNSUBSCRIBE (Mid: %d, Topic: %s)", SAFE_PRINT(mosq->id), local_mid, topic[i]);
|
||||
}
|
||||
# endif
|
||||
metrics__int_inc(mosq_counter_mqtt_unsubscribe_sent, 1);
|
||||
#else
|
||||
for(i=0; i<topic_count; i++){
|
||||
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending UNSUBSCRIBE (Mid: %d, Topic: %s)", SAFE_PRINT(mosq->id), local_mid, topic[i]);
|
||||
|
||||
@@ -40,15 +40,19 @@ int handle__packet(struct mosquitto *context)
|
||||
|
||||
switch((context->in_packet.command)&0xF0){
|
||||
case CMD_PINGREQ:
|
||||
metrics__int_inc(mosq_counter_mqtt_pingreq_received, 1);
|
||||
rc = handle__pingreq(context);
|
||||
break;
|
||||
case CMD_PINGRESP:
|
||||
metrics__int_inc(mosq_counter_mqtt_pingresp_received, 1);
|
||||
rc = handle__pingresp(context);
|
||||
break;
|
||||
case CMD_PUBACK:
|
||||
metrics__int_inc(mosq_counter_mqtt_puback_received, 1);
|
||||
rc = handle__pubackcomp(context, "PUBACK");
|
||||
break;
|
||||
case CMD_PUBCOMP:
|
||||
metrics__int_inc(mosq_counter_mqtt_pubcomp_received, 1);
|
||||
rc = handle__pubackcomp(context, "PUBCOMP");
|
||||
break;
|
||||
case CMD_PUBLISH:
|
||||
@@ -56,35 +60,44 @@ int handle__packet(struct mosquitto *context)
|
||||
rc = handle__publish(context);
|
||||
break;
|
||||
case CMD_PUBREC:
|
||||
metrics__int_inc(mosq_counter_mqtt_pubrec_received, 1);
|
||||
rc = handle__pubrec(context);
|
||||
break;
|
||||
case CMD_PUBREL:
|
||||
metrics__int_inc(mosq_counter_mqtt_pubrel_received, 1);
|
||||
rc = handle__pubrel(context);
|
||||
break;
|
||||
case CMD_CONNECT:
|
||||
metrics__int_inc(mosq_counter_mqtt_connect_received, 1);
|
||||
return handle__connect(context);
|
||||
case CMD_DISCONNECT:
|
||||
metrics__int_inc(mosq_counter_mqtt_disconnect_received, 1);
|
||||
rc = handle__disconnect(context);
|
||||
break;
|
||||
case CMD_SUBSCRIBE:
|
||||
metrics__int_inc(mosq_counter_mqtt_subscribe_received, 1);
|
||||
rc = handle__subscribe(context);
|
||||
break;
|
||||
case CMD_UNSUBSCRIBE:
|
||||
metrics__int_inc(mosq_counter_mqtt_unsubscribe_received, 1);
|
||||
rc = handle__unsubscribe(context);
|
||||
break;
|
||||
#ifdef WITH_BRIDGE
|
||||
case CMD_CONNACK:
|
||||
metrics__int_inc(mosq_counter_mqtt_connack_received, 1);
|
||||
rc = handle__connack(context);
|
||||
break;
|
||||
case CMD_SUBACK:
|
||||
metrics__int_inc(mosq_counter_mqtt_suback_received, 1);
|
||||
rc = handle__suback(context);
|
||||
break;
|
||||
case CMD_UNSUBACK:
|
||||
metrics__int_inc(mosq_counter_mqtt_unsuback_received, 1);
|
||||
rc = handle__unsuback(context);
|
||||
break;
|
||||
#endif
|
||||
case CMD_AUTH:
|
||||
metrics__int_inc(mosq_counter_mqtt_auth_received, 1);
|
||||
rc = handle__auth(context);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -60,6 +60,7 @@ int send__auth(struct mosquitto *context, uint8_t reason_code, const void *auth_
|
||||
property__write_all(packet, properties, true);
|
||||
mosquitto_property_free_all(&properties);
|
||||
|
||||
metrics__int_inc(mosq_counter_mqtt_auth_sent, 1);
|
||||
return packet__queue(context, packet);
|
||||
error:
|
||||
mosquitto_property_free_all(&properties);
|
||||
|
||||
@@ -96,6 +96,7 @@ int send__connack(struct mosquitto *context, uint8_t ack, uint8_t reason_code, c
|
||||
}
|
||||
mosquitto_property_free_all(&connack_props);
|
||||
|
||||
metrics__int_inc(mosq_counter_mqtt_connack_sent, 1);
|
||||
return packet__queue(context, packet);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,5 +55,6 @@ int send__suback(struct mosquitto *context, uint16_t mid, uint32_t payloadlen, c
|
||||
packet__write_bytes(packet, payload, payloadlen);
|
||||
}
|
||||
|
||||
metrics__int_inc(mosq_counter_mqtt_suback_sent, 1);
|
||||
return packet__queue(context, packet);
|
||||
}
|
||||
|
||||
@@ -54,5 +54,6 @@ int send__unsuback(struct mosquitto *mosq, uint16_t mid, int reason_code_count,
|
||||
packet__write_bytes(packet, reason_codes, (uint32_t)reason_code_count);
|
||||
}
|
||||
|
||||
metrics__int_inc(mosq_counter_mqtt_unsuback_sent, 1);
|
||||
return packet__queue(mosq, packet);
|
||||
}
|
||||
|
||||
@@ -80,9 +80,36 @@ struct metric metrics[mosq_metric_max] = {
|
||||
{ 1, 0, "$SYS/broker/packet/out/bytes", NULL, false }, /* mosq_gauge_out_packet_bytes */
|
||||
{ 1, 0, "$SYS/broker/connections/socket/count", NULL, false }, /* mosq_counter_socket_connections */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_connect_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_connect_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_connack_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_connack_sent */
|
||||
{ 1, 0, "$SYS/broker/publish/messages/dropped", NULL, false }, /* mosq_counter_mqtt_publish_dropped */
|
||||
{ 1, 0, "$SYS/broker/publish/messages/received", NULL, false }, /* mosq_counter_mqtt_publish_received */
|
||||
{ 1, 0, "$SYS/broker/publish/messages/sent", NULL, false }, /* mosq_counter_mqtt_publish_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_puback_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_puback_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pubrec_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pubrec_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pubrel_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pubrel_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pubcomp_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pubcomp_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_subscribe_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_subscribe_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_suback_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_suback_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_unsubscribe_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_unsubscribe_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_unsuback_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_unsuback_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pingreq_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pingreq_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pingresp_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_pingresp_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_disconnect_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_disconnect_sent */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_auth_received */
|
||||
{ 1, 0, NULL, NULL, false }, /* mosq_counter_mqtt_auth_sent */
|
||||
};
|
||||
|
||||
struct metric_load metric_loads[mosq_metric_load_max] = {
|
||||
|
||||
+30
-3
@@ -45,9 +45,36 @@ enum mosq_metric_type{
|
||||
mosq_gauge_out_packet_bytes = 19,
|
||||
mosq_counter_socket_connections = 20,
|
||||
mosq_counter_mqtt_connect_received = 21,
|
||||
mosq_counter_mqtt_publish_dropped = 22,
|
||||
mosq_counter_mqtt_publish_received = 23,
|
||||
mosq_counter_mqtt_publish_sent = 24,
|
||||
mosq_counter_mqtt_connect_sent = 22,
|
||||
mosq_counter_mqtt_connack_received = 23,
|
||||
mosq_counter_mqtt_connack_sent = 24,
|
||||
mosq_counter_mqtt_publish_dropped = 25,
|
||||
mosq_counter_mqtt_publish_received = 26,
|
||||
mosq_counter_mqtt_publish_sent = 27,
|
||||
mosq_counter_mqtt_puback_received = 28,
|
||||
mosq_counter_mqtt_puback_sent = 29,
|
||||
mosq_counter_mqtt_pubrec_received = 30,
|
||||
mosq_counter_mqtt_pubrec_sent = 31,
|
||||
mosq_counter_mqtt_pubrel_received = 32,
|
||||
mosq_counter_mqtt_pubrel_sent = 33,
|
||||
mosq_counter_mqtt_pubcomp_received = 34,
|
||||
mosq_counter_mqtt_pubcomp_sent = 35,
|
||||
mosq_counter_mqtt_subscribe_received = 36,
|
||||
mosq_counter_mqtt_subscribe_sent = 37,
|
||||
mosq_counter_mqtt_suback_received = 38,
|
||||
mosq_counter_mqtt_suback_sent = 39,
|
||||
mosq_counter_mqtt_unsubscribe_received = 40,
|
||||
mosq_counter_mqtt_unsubscribe_sent = 41,
|
||||
mosq_counter_mqtt_unsuback_received = 42,
|
||||
mosq_counter_mqtt_unsuback_sent = 43,
|
||||
mosq_counter_mqtt_pingreq_received = 44,
|
||||
mosq_counter_mqtt_pingreq_sent = 45,
|
||||
mosq_counter_mqtt_pingresp_received = 46,
|
||||
mosq_counter_mqtt_pingresp_sent = 47,
|
||||
mosq_counter_mqtt_disconnect_received = 48,
|
||||
mosq_counter_mqtt_disconnect_sent = 49,
|
||||
mosq_counter_mqtt_auth_received = 50,
|
||||
mosq_counter_mqtt_auth_sent = 51,
|
||||
|
||||
mosq_metric_max,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user