TSG-14786 TFE输出Proxy Rule Hits Metric

This commit is contained in:
fengweihao
2023-04-25 10:13:38 +08:00
parent 95c80c80cf
commit 0bb38a6969
13 changed files with 229 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
#include "logger.h"
#include <tfe_scan.h>
#include <MESA/stream.h>
#include <tfe_fieldstat.h>
extern void increase_redirect_policy_hit_num(void);
@@ -661,6 +662,21 @@ static void doh_process_req(const struct tfe_stream *stream, const struct tfe_ht
}
}
struct tfe_fieldstat_metric_t *doh_fieldstat_init(const char* profile, const char *section, int max_thread)
{
int cycle=0;
unsigned short telegraf_port=0;
char telegraf_ip[TFE_STRING_MAX]={0};
char app_name[TFE_STRING_MAX]={0};
MESA_load_profile_short_nodef(profile, section, "telegraf_port", (short *)&(telegraf_port));
MESA_load_profile_string_nodef(profile, section, "telegraf_ip", telegraf_ip, sizeof(telegraf_ip));
MESA_load_profile_string_def(profile, section, "app_name", app_name, sizeof(app_name), "metric");
MESA_load_profile_int_def(profile, section, "cycle", &cycle, 1000);
return tfe_fieldstat_metric_create(telegraf_ip, telegraf_port, app_name, cycle, max_thread, g_doh_conf->local_logger);
}
int doh_on_init(struct tfe_proxy *proxy)
{
const char *profile = "./conf/doh/doh.conf";
@@ -679,6 +695,7 @@ int doh_on_init(struct tfe_proxy *proxy)
g_doh_conf->thread_num = tfe_proxy_get_work_thread_count();
g_doh_conf->local_logger = MESA_create_runtime_log_handle("doh", RLOG_LV_DEBUG);
g_doh_conf->fieldstat = doh_fieldstat_init(profile, "proxy_hits", g_doh_conf->thread_num);
g_doh_conf->gc_evbase = tfe_proxy_get_gc_evbase();
g_doh_conf->fs_handle = tfe_proxy_get_fs_handle();
@@ -856,6 +873,23 @@ int doh_on_data(const struct tfe_stream *stream, const struct tfe_http_session *
return NO_CALL_NEXT_PLUGIN;
}
void doh_send_metric_log(const struct tfe_stream * stream, struct doh_ctx *ctx, unsigned int thread_id)
{
size_t c2s_byte_num = 0, s2c_byte_num =0;
struct tfe_fieldstat_metric_t *fieldstat = g_doh_conf->fieldstat;
fieldstat->tags[thread_id][TAG_RULE_ID].value_int = ctx->result->config_id;
fieldstat->tags[thread_id][TAG_ACTION].value_int = 48;
fieldstat->tags[thread_id][TAG_SUB_ACTION].value_str = "redirect";
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_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);
tfe_fieldstat_metric_incrby(fieldstat, fieldstat->column_array[COLUMN_OUT_BYTES], s2c_byte_num, fieldstat->tags[thread_id], thread_id);
return;
}
void doh_on_end(const struct tfe_stream *stream, const struct tfe_http_session *session, unsigned int thread_id, void **pme)
{
if (!g_doh_conf->enable)
@@ -869,6 +903,7 @@ void doh_on_end(const struct tfe_stream *stream, const struct tfe_http_session *
int ret = doh_send_log(g_doh_conf, session, stream, ctx);
if (ret > 0)
{
doh_send_metric_log(stream, ctx, thread_id);
ATOMIC_ADD(&(g_doh_conf->stat_val[STAT_LOG_NUM]), ret);
}
}