From 64d7a1270152070d01cd3ca3c3fce11b36116f93 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 3 Feb 2023 09:57:11 -0500 Subject: [PATCH] MT#55283 add new `summary` mqtt option Change-Id: I7e4a2327f6aca2c73349b3ae02d4184460575e89 --- daemon/codec.c | 14 ++++++++++++-- daemon/main.c | 4 +++- daemon/mqtt.c | 7 +++++++ daemon/rtpengine.pod | 7 ++++--- include/main.h | 1 + include/mqtt.h | 2 ++ 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/daemon/codec.c b/daemon/codec.c index 46117b81c..d9ea65942 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -1419,6 +1419,13 @@ static void __mqtt_timer_run_global(struct codec_timer *ct) { __codec_mqtt_timer_schedule(mqt); mqtt_timer_run_global(); } +static void __mqtt_timer_run_summary(struct codec_timer *ct) { + struct mqtt_timer *mqt = (struct mqtt_timer *) ct; + if (!*mqt->self) + return; + __codec_mqtt_timer_schedule(mqt); + mqtt_timer_run_summary(); +} static void __codec_mqtt_timer_schedule(struct mqtt_timer *mqt) { timeval_add_usec(&mqt->ct.next, rtpe_config.mqtt_publish_interval * 1000); timerthread_obj_schedule_abs(&mqt->ct.tt_obj, &mqt->ct.next); @@ -1439,8 +1446,11 @@ void mqtt_timer_start(struct mqtt_timer **mqtp, struct call *call, struct call_m mqt->ct.timer_func = __mqtt_timer_run_media; else if (call) mqt->ct.timer_func = __mqtt_timer_run_call; - else - mqt->ct.timer_func = __mqtt_timer_run_global; + else { + // global or summary + mqt->ct.timer_func = mqtt_publish_scope() == MPS_GLOBAL + ? __mqtt_timer_run_global : __mqtt_timer_run_summary; + } __codec_mqtt_timer_schedule(mqt); } diff --git a/daemon/main.c b/daemon/main.c index 5078fdd0c..d9abdfdf9 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -572,7 +572,7 @@ static void options(int *argc, char ***argv) { { "mqtt-publish-qos",0,0,G_OPTION_ARG_INT, &rtpe_config.mqtt_publish_qos,"Mosquitto publish QoS", "0|1|2"}, { "mqtt-publish-topic",0,0,G_OPTION_ARG_STRING, &rtpe_config.mqtt_publish_topic,"Mosquitto publish topic", "STRING"}, { "mqtt-publish-interval",0,0,G_OPTION_ARG_INT, &rtpe_config.mqtt_publish_interval,"Publish timer interval", "MILLISECONDS"}, - { "mqtt-publish-scope",0,0,G_OPTION_ARG_STRING, &mqtt_publish_scope, "Scope for published mosquitto messages","global|call|media"}, + { "mqtt-publish-scope",0,0,G_OPTION_ARG_STRING, &mqtt_publish_scope, "Scope for published mosquitto messages","global|summary|call|media"}, #endif { "mos",0,0, G_OPTION_ARG_STRING, &mos, "Type of MOS calculation","CQ|LQ"}, { "measure-rtp",0,0, G_OPTION_ARG_NONE, &rtpe_config.measure_rtp,"Enable measuring RTP statistics and VoIP metrics",NULL}, @@ -845,6 +845,8 @@ static void options(int *argc, char ***argv) { rtpe_config.mqtt_publish_scope = MPS_CALL; else if (!strcmp(mqtt_publish_scope, "media")) rtpe_config.mqtt_publish_scope = MPS_MEDIA; + else if (!strcmp(mqtt_publish_scope, "summary")) + rtpe_config.mqtt_publish_scope = MPS_SUMMARY; else die("Invalid --mqtt-publish-scope option ('%s')", mqtt_publish_scope); } diff --git a/daemon/mqtt.c b/daemon/mqtt.c index d0fa3b28b..f706a166e 100644 --- a/daemon/mqtt.c +++ b/daemon/mqtt.c @@ -569,6 +569,13 @@ void mqtt_timer_run_global(void) { __mqtt_timer_outro(json); } +void mqtt_timer_run_summary(void) { + JsonBuilder *json = __mqtt_timer_intro(); + + mqtt_global_stats(json); + + __mqtt_timer_outro(json); +} diff --git a/daemon/rtpengine.pod b/daemon/rtpengine.pod index e95e0904a..34e281fc0 100644 --- a/daemon/rtpengine.pod +++ b/daemon/rtpengine.pod @@ -1049,10 +1049,11 @@ string. Interval in milliseconds to publish to Mosquitto. Defaults to 5000 (5 seconds). -=item B<--mqtt-publish-scope=>B|B|B +=item B<--mqtt-publish-scope=>B|B|B|B -When set to B, one message will be published to Mosquitto every -I milliseconds containing global stats plus a list of all running +When set to B, one message will be published to Mosquitto every +I milliseconds containing all global stats. A setting of B +has the same effect as B but will also contain a list of all running calls with stats for each call. When set to B, one message per call will be published to Mosquitto with stats for that call every I milliseconds, plus one message every I milliseconds with global diff --git a/include/main.h b/include/main.h index 4af3710ee..40e5592aa 100644 --- a/include/main.h +++ b/include/main.h @@ -153,6 +153,7 @@ struct rtpengine_config { MPS_GLOBAL = 0, MPS_CALL, MPS_MEDIA, + MPS_SUMMARY, } mqtt_publish_scope; enum { MOS_CQ = 0, diff --git a/include/mqtt.h b/include/mqtt.h index 9f37588f7..5b246634d 100644 --- a/include/mqtt.h +++ b/include/mqtt.h @@ -18,6 +18,7 @@ void mqtt_publish(char *); void mqtt_timer_run_media(struct call *, struct call_media *); void mqtt_timer_run_call(struct call *); void mqtt_timer_run_global(void); +void mqtt_timer_run_summary(void); #else @@ -30,6 +31,7 @@ INLINE int mqtt_publish_scope(void) { return MPS_NONE; }; INLINE void mqtt_timer_run_media(struct call *c, struct call_media *m) { } INLINE void mqtt_timer_run_call(struct call *c) { } INLINE void mqtt_timer_run_global(void) { } +INLINE void mqtt_timer_run_summary(void) { } #endif #endif