mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-05-21 12:24:29 +02:00
Fix $SYS load values not being published initially.
Closes #3459. Thanks to hessijames79
This commit is contained in:
parent
a06b45e319
commit
df7b703080
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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; i<mosq_metric_load_max; i++){
|
||||
if(metric_loads[i].interval == METRIC_LOAD_1MIN){
|
||||
calc_load(buf, 0.0, 0.0, &metric_loads[i], true);
|
||||
}else if(metric_loads[i].interval == METRIC_LOAD_5MIN){
|
||||
calc_load(buf, 0.0, 0.0, &metric_loads[i], true);
|
||||
}else{
|
||||
calc_load(buf, 0.0, 0.0, &metric_loads[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -187,22 +214,6 @@ void metrics__int_dec(enum mosq_metric_type m, int64_t value)
|
|||
}
|
||||
|
||||
|
||||
static void calc_load(char *buf, double exponent, double i_mult, struct metric_load *m)
|
||||
{
|
||||
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){
|
||||
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<mosq_metric_load_max; i++){
|
||||
if(metric_loads[i].interval == METRIC_LOAD_1MIN){
|
||||
calc_load(buf, exponent_1min, i_mult, &metric_loads[i]);
|
||||
calc_load(buf, exponent_1min, i_mult, &metric_loads[i], false);
|
||||
}else if(metric_loads[i].interval == METRIC_LOAD_5MIN){
|
||||
calc_load(buf, exponent_5min, i_mult, &metric_loads[i]);
|
||||
calc_load(buf, exponent_5min, i_mult, &metric_loads[i], false);
|
||||
}else{
|
||||
calc_load(buf, exponent_15min, i_mult, &metric_loads[i]);
|
||||
calc_load(buf, exponent_15min, i_mult, &metric_loads[i], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue