mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-08-18 01:48:32 +08:00
Add --message-rate option to mosquitto_sub
When active, this prints the count of messages received each second.
This commit is contained in:
@@ -190,6 +190,8 @@ Clients:
|
||||
- Add `--tls-keylog` option which can be used to generate a file that can be
|
||||
used by wireshark to decrypt TLS traffic for debugging purposes.
|
||||
- mosquitto_sub payload hex output can now be split by fixed field length.
|
||||
- Add `--message-rate` option to mosquitto_sub, for printing the count of
|
||||
messages received each second.
|
||||
|
||||
DB Dump:
|
||||
- Add `--json` output mode.
|
||||
|
||||
@@ -869,6 +869,11 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
|
||||
cfg->max_inflight = (unsigned int )tmpi;
|
||||
}
|
||||
i++;
|
||||
}else if(!strcmp(argv[i], "--message-rate")){
|
||||
if(pub_or_sub != CLIENT_SUB){
|
||||
goto unknown_option;
|
||||
}
|
||||
cfg->message_rate = true;
|
||||
}else if(!strcmp(argv[i], "--nodelay")){
|
||||
cfg->tcp_nodelay = true;
|
||||
}else if(!strcmp(argv[i], "--no-tls")){
|
||||
|
||||
@@ -142,6 +142,7 @@ struct mosq_config {
|
||||
bool have_topic_alias; /* pub */
|
||||
bool tcp_nodelay;
|
||||
bool no_tls;
|
||||
bool message_rate; /* sub */
|
||||
};
|
||||
|
||||
extern const char hexseplist[32];
|
||||
|
||||
+24
-1
@@ -37,8 +37,10 @@ Contributors:
|
||||
#include "sub_client_output.h"
|
||||
|
||||
struct mosq_config cfg;
|
||||
static bool run = true;
|
||||
bool process_messages = true;
|
||||
int msg_count = 0;
|
||||
int message_rate_msg_count = 0;
|
||||
struct mosquitto *g_mosq = NULL;
|
||||
int last_mid = 0;
|
||||
static bool timed_out = false;
|
||||
@@ -76,6 +78,7 @@ static void my_signal_handler(int signum)
|
||||
}else{
|
||||
exit(-1);
|
||||
}
|
||||
run = false;
|
||||
}
|
||||
if(signum == SIGALRM){
|
||||
timed_out = true;
|
||||
@@ -92,6 +95,8 @@ static void my_message_callback(struct mosquitto *mosq, void *obj, const struct
|
||||
UNUSED(obj);
|
||||
UNUSED(properties);
|
||||
|
||||
message_rate_msg_count++;
|
||||
|
||||
if(process_messages == false) return;
|
||||
|
||||
if(cfg.retained_only && !message->retain && process_messages){
|
||||
@@ -393,6 +398,10 @@ int main(int argc, char *argv[])
|
||||
if(cfg.debug){
|
||||
mosquitto_log_callback_set(g_mosq, my_log_callback);
|
||||
}
|
||||
if(cfg.message_rate){
|
||||
process_messages = false;
|
||||
cfg.watch = false;
|
||||
}
|
||||
mosquitto_subscribe_callback_set(g_mosq, my_subscribe_callback);
|
||||
mosquitto_connect_v5_callback_set(g_mosq, my_connect_callback);
|
||||
mosquitto_message_v5_callback_set(g_mosq, my_message_callback);
|
||||
@@ -436,7 +445,21 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
rc = mosquitto_loop_forever(g_mosq, -1, 1);
|
||||
if(cfg.message_rate){
|
||||
rc = mosquitto_loop_start(g_mosq);
|
||||
if(rc){
|
||||
return rc;
|
||||
}
|
||||
while(run){
|
||||
struct timespec ts = {1,0};
|
||||
nanosleep(&ts, NULL);
|
||||
int message_count = message_rate_msg_count;
|
||||
message_rate_msg_count = 0;
|
||||
printf("%d msgs/s\n", message_count);
|
||||
}
|
||||
}else{
|
||||
rc = mosquitto_loop_forever(g_mosq, -1, 1);
|
||||
}
|
||||
|
||||
mosquitto_destroy(g_mosq);
|
||||
mosquitto_lib_cleanup();
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<arg><option>-i</option> <replaceable>client-id</replaceable></arg>
|
||||
<arg><option>-I</option> <replaceable>client-id-prefix</replaceable></arg>
|
||||
<arg><option>-k</option> <replaceable>keepalive-time</replaceable></arg>
|
||||
<arg><option>--message-rate</option></arg>
|
||||
<arg><option>-N</option></arg>
|
||||
<arg><option>--nodelay</option></arg>
|
||||
<arg><option>--pretty</option></arg>
|
||||
@@ -431,6 +432,17 @@
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>--message-rate</option></term>
|
||||
<listitem>
|
||||
<para>
|
||||
Instead of printing the messages received, print a count
|
||||
of the messages received at one second intervals. Other
|
||||
options related to output formatting are not valid when
|
||||
this option is active.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
<varlistentry>
|
||||
<term><option>-N</option></term>
|
||||
<listitem>
|
||||
|
||||
Reference in New Issue
Block a user