diff options
| author | fengweihao <[email protected]> | 2023-04-25 10:13:38 +0800 |
|---|---|---|
| committer | fengweihao <[email protected]> | 2023-04-25 10:13:38 +0800 |
| commit | 0bb38a69699f7f9cc601441e23475cd57e5a88f6 (patch) | |
| tree | c524dcc588b76072fae07eb4ef1bd9f5466bef88 /plugin/business/doh/src | |
| parent | 95c80c80cf7f26712e74cbeaadf33fa843cf920d (diff) | |
TSG-14786 TFE输出Proxy Rule Hits Metric
Diffstat (limited to 'plugin/business/doh/src')
| -rw-r--r-- | plugin/business/doh/src/doh.cpp | 35 | ||||
| -rw-r--r-- | plugin/business/doh/src/pub.h | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/plugin/business/doh/src/doh.cpp b/plugin/business/doh/src/doh.cpp index 5d0e79e..c0ba0a8 100644 --- a/plugin/business/doh/src/doh.cpp +++ b/plugin/business/doh/src/doh.cpp @@ -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); } } diff --git a/plugin/business/doh/src/pub.h b/plugin/business/doh/src/pub.h index 6606312..dd74761 100644 --- a/plugin/business/doh/src/pub.h +++ b/plugin/business/doh/src/pub.h @@ -69,6 +69,7 @@ struct doh_conf struct event *gcev; struct event_base *gc_evbase; screen_stat_handle_t fs_handle; + struct tfe_fieldstat_metric_t *fieldstat; struct maat *maat; struct maat_table tables[TYPE_MAX]; |
