diff --git a/ChangeLog.txt b/ChangeLog.txt index d0b7a8a0..5482e7ee 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -9,6 +9,7 @@ environments like kubernetes. Closes #3461. - Fix inconsistent disconnect log message format, and add address:port. - Fix `plugin`/`global_plugin` option not allowing space characters. +- Fix $SYS load values not being published initially. Closes #3459. # Plugins - Fix incorrect linking of libmosquitto_common.so for the acl and password diff --git a/src/sys_tree.c b/src/sys_tree.c index 4bcab89d..a0203553 100644 --- a/src/sys_tree.c +++ b/src/sys_tree.c @@ -151,9 +151,25 @@ time_t broker_uptime(void) } +static void calc_load(char *buf, double exponent, double i_mult, struct metric_load *m, bool force) +{ + double new_value; + uint32_t len; + double interval; + + interval = (double)(metrics[m->load_ref].next - metrics[m->load_ref].current)*i_mult; + new_value = interval + exponent*(m->current - interval); + if(fabs(new_value - (m->current)) >= 0.01 || force){ + len = (uint32_t)snprintf(buf, BUFLEN, "%.2f", new_value); + db__messages_easy_queue(NULL, m->topic, SYS_TREE_QOS, len, buf, 1, MSG_EXPIRY_INFINITE, NULL); + } + m->current = new_value; +} + + void sys_tree__init(void) { - char buf[64]; + char buf[BUFLEN]; uint32_t len; if(db.config->sys_interval == 0){ @@ -168,6 +184,17 @@ void sys_tree__init(void) last_update = start_time; sys_tree__update(true); + + /* Force published load values to 0 */ + for(int i=0; iload_ref].next - metrics[m->load_ref].current)*i_mult; - new_value = interval + exponent*(m->current - interval); - if(fabs(new_value - (m->current)) >= 0.01){ - len = (uint32_t)snprintf(buf, BUFLEN, "%.2f", new_value); - db__messages_easy_queue(NULL, m->topic, SYS_TREE_QOS, len, buf, 1, MSG_EXPIRY_INFINITE, NULL); - } - m->current = new_value; -} - - /* Send messages for the $SYS hierarchy if the last update is longer than * 'interval' seconds ago. * 'interval' is the amount of seconds between updates. If 0, then no periodic @@ -257,11 +268,11 @@ void sys_tree__update(bool force) for(int i=0; i