bugfix:修复管控策略Policy Hits Metrics误发送pinning_status,根据route_dir发送字节数
This commit is contained in:
@@ -23,9 +23,9 @@ enum metric_tags_index
|
|||||||
{
|
{
|
||||||
TAG_VSYS_ID = 0,
|
TAG_VSYS_ID = 0,
|
||||||
TAG_RULE_ID,
|
TAG_RULE_ID,
|
||||||
TAG_PINNING_STATUS,
|
|
||||||
TAG_ACTION,
|
TAG_ACTION,
|
||||||
TAG_SUB_ACTION,
|
TAG_SUB_ACTION,
|
||||||
|
TAG_PINNING_STATUS,
|
||||||
TAG_MAX
|
TAG_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ struct tfe_fieldstat_metric_t
|
|||||||
};
|
};
|
||||||
|
|
||||||
void tfe_set_intercept_metric(struct tfe_stream *stream, int hit_count, int downstream_rx_pkts, int downstream_rx_bytes, int upstream_rx_pkts, int upstream_rx_bytes);
|
void tfe_set_intercept_metric(struct tfe_stream *stream, int hit_count, int downstream_rx_pkts, int downstream_rx_bytes, int upstream_rx_pkts, int upstream_rx_bytes);
|
||||||
int tfe_fieldstat_metric_incrby(struct tfe_fieldstat_metric_t *fieldstat, unsigned int column_id, long long value, const struct fieldstat_tag tags[], int thread_id);
|
int tfe_fieldstat_metric_incrby(struct tfe_fieldstat_metric_t *fieldstat, unsigned int column_id, long long value, const struct fieldstat_tag tags[], int n_tags, int thread_id);
|
||||||
struct tfe_fieldstat_metric_t *tfe_fieldstat_metric_create(char *telegraf_ip, int telegraf_port, char *app_name, int cycle, int max_thread, void *local_logger);
|
struct tfe_fieldstat_metric_t *tfe_fieldstat_metric_create(char *telegraf_ip, int telegraf_port, char *app_name, int cycle, int max_thread, void *local_logger);
|
||||||
void tfe_fieldstat_metric_destroy(struct tfe_fieldstat_metric_t *fieldstat);
|
void tfe_fieldstat_metric_destroy(struct tfe_fieldstat_metric_t *fieldstat);
|
||||||
|
|
||||||
|
|||||||
@@ -150,16 +150,16 @@ void tfe_set_intercept_metric(struct tfe_stream *stream, int hit_count, int down
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tfe_fieldstat_metric_incrby(struct tfe_fieldstat_metric_t *fieldstat, unsigned int column_id, long long value, const struct fieldstat_tag tags[], int thread_id)
|
int tfe_fieldstat_metric_incrby(struct tfe_fieldstat_metric_t *fieldstat, unsigned int column_id, long long value, const struct fieldstat_tag tags[], int n_tags, int thread_id)
|
||||||
{
|
{
|
||||||
return fieldstat_dynamic_table_metric_value_incrby(fieldstat->instance, fieldstat->table_id, column_id, "proxy_rule_hits", value, tags, (size_t)TAG_MAX, thread_id);
|
return fieldstat_dynamic_table_metric_value_incrby(fieldstat->instance, fieldstat->table_id, column_id, "proxy_rule_hits", value, tags, (size_t)n_tags, thread_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tfe_fieldstat_metric_t *tfe_fieldstat_metric_create(char *telegraf_ip, int telegraf_port, char *app_name, int cycle, int max_thread, void *local_logger)
|
struct tfe_fieldstat_metric_t *tfe_fieldstat_metric_create(char *telegraf_ip, int telegraf_port, char *app_name, int cycle, int max_thread, void *local_logger)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
struct fieldstat_tag metric_tags[TAG_MAX] = {{"vsys_id", 0, -1}, {"rule_id", 0, -1}, {"pinning_status", 0, -1 }, {"action", 0, -1}, {"sub_action", 2, -1} };
|
struct fieldstat_tag metric_tags[TAG_MAX - 1] = {{"vsys_id", 0, -1}, {"rule_id", 0, -1}, {"action", 0, -1}, {"sub_action", 2, -1}};
|
||||||
const char *column_field[COLUMN_MAX] = {"hit_count", "in_bytes", "out_bytes", "in_pkts", "out_pkts"};
|
const char *column_field[COLUMN_MAX] = {"hit_count", "in_bytes", "out_bytes", "in_pkts", "out_pkts"};
|
||||||
enum field_type column_type[COLUMN_MAX] = {FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER};
|
enum field_type column_type[COLUMN_MAX] = {FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER, FIELD_TYPE_COUNTER};
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ struct tfe_fieldstat_metric_t *tfe_fieldstat_metric_create(char *telegraf_ip, in
|
|||||||
fieldstat->tags = ALLOC(struct fieldstat_tag*, max_thread);
|
fieldstat->tags = ALLOC(struct fieldstat_tag*, max_thread);
|
||||||
for (i = 0; i < max_thread; i++)
|
for (i = 0; i < max_thread; i++)
|
||||||
{
|
{
|
||||||
fieldstat->tags[i] = ALLOC(struct fieldstat_tag, TAG_MAX);
|
fieldstat->tags[i] = ALLOC(struct fieldstat_tag, TAG_MAX-1);
|
||||||
memcpy(fieldstat->tags[i], metric_tags, sizeof(struct fieldstat_tag) * (size_t)TAG_MAX);
|
memcpy(fieldstat->tags[i], metric_tags, sizeof(struct fieldstat_tag) * (size_t)(TAG_MAX-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldstat_dynamic_instance_start(fieldstat->instance);
|
fieldstat_dynamic_instance_start(fieldstat->instance);
|
||||||
|
|||||||
@@ -869,9 +869,36 @@ void doh_send_metric_log(const struct tfe_stream * stream, struct doh_ctx *ctx,
|
|||||||
|
|
||||||
tfe_stream_info_get(stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &c2s_byte_num, sizeof(c2s_byte_num));
|
tfe_stream_info_get(stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &c2s_byte_num, sizeof(c2s_byte_num));
|
||||||
tfe_stream_info_get(stream, INFO_FROM_UPSTREAM_RX_OFFSET, &s2c_byte_num, sizeof(s2c_byte_num));
|
tfe_stream_info_get(stream, INFO_FROM_UPSTREAM_RX_OFFSET, &s2c_byte_num, sizeof(s2c_byte_num));
|
||||||
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_HIT_COUNT], 1, fieldstat->tags[thread_id], thread_id);
|
|
||||||
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_IN_BYTES], c2s_byte_num, fieldstat->tags[thread_id], thread_id);
|
uint16_t out_size;
|
||||||
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_OUT_BYTES], s2c_byte_num, fieldstat->tags[thread_id], thread_id);
|
unsigned int route_dir; int ret=0;
|
||||||
|
int in_bytes = 0, out_bytes = 0;
|
||||||
|
|
||||||
|
struct tfe_cmsg *cmsg = tfe_stream_get0_cmsg(stream);
|
||||||
|
if (cmsg != NULL)
|
||||||
|
{
|
||||||
|
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_COMMON_DIRECTION, (unsigned char *)&route_dir, sizeof(route_dir), &out_size);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(g_doh_conf->local_logger, "failed at fetch route_dir from cmsg: %s", strerror(-ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int dir_is_e2i=(route_dir==69) ? 0 : 1;
|
||||||
|
if (dir_is_e2i == 1)
|
||||||
|
{
|
||||||
|
in_bytes = c2s_byte_num;
|
||||||
|
out_bytes = s2c_byte_num;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_bytes = s2c_byte_num;
|
||||||
|
out_bytes = c2s_byte_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_HIT_COUNT], 1, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
|
||||||
|
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_IN_BYTES], in_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
|
||||||
|
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_OUT_BYTES], out_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3281,13 +3281,40 @@ void proxy_send_metric_log(const struct tfe_stream * stream, struct proxy_http_c
|
|||||||
{
|
{
|
||||||
fieldstat->tags[thread_id][TAG_SUB_ACTION].value_str = proxy_action_map[ctx->enforce_rules[i].action];
|
fieldstat->tags[thread_id][TAG_SUB_ACTION].value_str = proxy_action_map[ctx->enforce_rules[i].action];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t c2s_byte_num = 0, s2c_byte_num =0;
|
size_t c2s_byte_num = 0, s2c_byte_num =0;
|
||||||
tfe_stream_info_get(stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &c2s_byte_num, sizeof(c2s_byte_num));
|
tfe_stream_info_get(stream, INFO_FROM_DOWNSTREAM_RX_OFFSET, &c2s_byte_num, sizeof(c2s_byte_num));
|
||||||
tfe_stream_info_get(stream, INFO_FROM_UPSTREAM_RX_OFFSET, &s2c_byte_num, sizeof(s2c_byte_num));
|
tfe_stream_info_get(stream, INFO_FROM_UPSTREAM_RX_OFFSET, &s2c_byte_num, sizeof(s2c_byte_num));
|
||||||
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_HIT_COUNT], 1, fieldstat->tags[thread_id], thread_id);
|
|
||||||
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_IN_BYTES], c2s_byte_num, fieldstat->tags[thread_id], thread_id);
|
uint16_t out_size;
|
||||||
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_OUT_BYTES], s2c_byte_num, fieldstat->tags[thread_id], thread_id);
|
unsigned int route_dir; int ret=0;
|
||||||
|
int in_bytes = 0, out_bytes = 0;
|
||||||
|
|
||||||
|
struct tfe_cmsg *cmsg = tfe_stream_get0_cmsg(stream);
|
||||||
|
if (cmsg != NULL)
|
||||||
|
{
|
||||||
|
ret = tfe_cmsg_get_value(cmsg, TFE_CMSG_COMMON_DIRECTION, (unsigned char *)&route_dir, sizeof(route_dir), &out_size);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(g_proxy_rt->local_logger, "failed at fetch route_dir from cmsg: %s", strerror(-ret));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int dir_is_e2i=(route_dir==69) ? 0 : 1;
|
||||||
|
if (dir_is_e2i == 1)
|
||||||
|
{
|
||||||
|
in_bytes = c2s_byte_num;
|
||||||
|
out_bytes = s2c_byte_num;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
in_bytes = s2c_byte_num;
|
||||||
|
out_bytes = c2s_byte_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_HIT_COUNT], 1, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
|
||||||
|
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_IN_BYTES], in_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
|
||||||
|
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_OUT_BYTES], out_bytes, fieldstat->tags[thread_id], TAG_MAX - 1, thread_id);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user