mirror of
https://github.com/emqx/neuron.git
synced 2026-10-26 03:40:01 +08:00
Merge pull request #880 from lixiumei123/main
update(metrics):modbus last_rtt_ms group_send_msgs_total
This commit is contained in:
@@ -64,8 +64,14 @@ int modbus_send_msg(void *ctx, uint16_t n_byte, uint8_t *bytes)
|
||||
int modbus_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group,
|
||||
uint16_t max_byte)
|
||||
{
|
||||
neu_adapter_update_metric_cb_t update_metric =
|
||||
plugin->common.adapter_callbacks->update_metric;
|
||||
|
||||
struct modbus_group_data *gd = NULL;
|
||||
|
||||
uint64_t read_interval_tot = 0;
|
||||
uint64_t read_interval_avg = 0;
|
||||
|
||||
if (group->user_data == NULL) {
|
||||
gd = calloc(1, sizeof(struct modbus_group_data));
|
||||
|
||||
@@ -92,15 +98,29 @@ int modbus_group_timer(neu_plugin_t *plugin, neu_plugin_group_t *group,
|
||||
for (uint16_t i = 0; i < gd->cmd_sort->n_cmd; i++) {
|
||||
uint16_t response_size = 0;
|
||||
plugin->cmd_idx = i;
|
||||
int ret = modbus_stack_read(
|
||||
|
||||
uint64_t read_tms = neu_time_ms();
|
||||
|
||||
int ret = modbus_stack_read(
|
||||
plugin->stack, gd->cmd_sort->cmd[i].slave_id,
|
||||
gd->cmd_sort->cmd[i].area, gd->cmd_sort->cmd[i].start_address,
|
||||
gd->cmd_sort->cmd[i].n_register, &response_size);
|
||||
if (ret > 0) {
|
||||
uint64_t recv_tms = neu_time_ms();
|
||||
|
||||
read_interval_tot += (recv_tms - read_tms);
|
||||
read_interval_avg = (uint64_t)(read_interval_tot / (i + 1));
|
||||
|
||||
process_protocol_buf(plugin, response_size);
|
||||
}
|
||||
}
|
||||
|
||||
update_metric(plugin->common.adapter, NEU_METRIC_LAST_RTT_MS,
|
||||
read_interval_avg, NULL);
|
||||
|
||||
update_metric(plugin->common.adapter, NEU_METRIC_GROUP_LAST_SEND_MSGS,
|
||||
gd->cmd_sort->n_cmd, group->group_name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ static const adapter_callbacks_t callback_funs = {
|
||||
REGISTER_METRIC(adapter, NEU_METRIC_SEND_BYTES, 0); \
|
||||
REGISTER_METRIC(adapter, NEU_METRIC_RECV_BYTES, 0); \
|
||||
REGISTER_METRIC(adapter, NEU_METRIC_TAG_READS_TOTAL, 0); \
|
||||
REGISTER_METRIC(adapter, NEU_METRIC_TAG_READ_ERRORS_TOTAL, 0)
|
||||
REGISTER_METRIC(adapter, NEU_METRIC_TAG_READ_ERRORS_TOTAL, 0);
|
||||
|
||||
#define REGISTER_APP_METRICS(adapter) \
|
||||
REGISTER_METRIC(adapter, NEU_METRIC_SEND_MSGS_TOTAL, 0); \
|
||||
|
||||
Reference in New Issue
Block a user