From 828f7551d915860b4fe5ce25cf917b3f2d685bc1 Mon Sep 17 00:00:00 2001 From: yangwei Date: Tue, 16 Jul 2024 15:50:30 +0800 Subject: ✨ feat(metrics update): frome fs3 to fs4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SSL_Analyze.c | 41 +++++++++++++++++++++++++---------------- src/SSL_Analyze.h | 3 +-- src/SSL_Message.c | 17 +++++++++++++---- 3 files changed, 39 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/SSL_Analyze.c b/src/SSL_Analyze.c index d6ce467..e0def36 100644 --- a/src/SSL_Analyze.c +++ b/src/SSL_Analyze.c @@ -17,7 +17,7 @@ #include "ssl.h" #include #include "SSL_Proc.h" -#include "fieldstat.h" +#include "fieldstat/fieldstat_easy.h" #include @@ -224,8 +224,11 @@ extern "C" char SSL_DETAIN_ENTRY(const struct streaminfo *a_tcp, void**pme, int { p = pkts->p[i]; if (p)MESA_detain_pkt_forward_based_on_stream(a_tcp, p); - if(g_ssl_runtime_para.fs)fieldstat_value_incrby(g_ssl_runtime_para.fs, + if(g_ssl_runtime_para.fs)fieldstat_easy_counter_incrby(g_ssl_runtime_para.fs, + a_tcp->threadnum, g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FORWARD], + NULL, + 0, 1); pkts->p[i] = NULL; } @@ -246,16 +249,22 @@ static void ssl_retain_packet_bridge_free(const struct streaminfo *stream, int b { if(pkts->p_sz > 0) { - if(g_ssl_runtime_para.fs)fieldstat_value_incrby(g_ssl_runtime_para.fs, + if(g_ssl_runtime_para.fs)fieldstat_easy_counter_incrby(g_ssl_runtime_para.fs, + stream->threadnum, g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_TIMEOUT], + NULL, + 0, 1); } for(unsigned int i = 0; i < pkts->p_sz; i++) { p=pkts->p[i]; if (p)MESA_detain_pkt_free(p); - if(g_ssl_runtime_para.fs)fieldstat_value_incrby(g_ssl_runtime_para.fs, + if(g_ssl_runtime_para.fs)fieldstat_easy_counter_incrby(g_ssl_runtime_para.fs, + stream->threadnum, g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FREE], + NULL, + 0, 1); } @@ -284,17 +293,17 @@ extern "C" int SSL_INIT(void) MESA_load_profile_uint_def(filename, "SSL", "SSL_STAT_REFRESH_S", &refresh_s, 0); if(refresh_s > 0) { - g_ssl_runtime_para.fs=fieldstat_instance_new("SSL_DECODER"); - fieldstat_set_output_interval(g_ssl_runtime_para.fs, refresh_s * 1000); - fieldstat_set_local_output(g_ssl_runtime_para.fs, "./log/ssl.status", "default"); - fieldstat_enable_prometheus_output(g_ssl_runtime_para.fs); - fieldstat_instance_start(g_ssl_runtime_para.fs); - g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_SESSION]=fieldstat_register(g_ssl_runtime_para.fs, FIELD_TYPE_COUNTER, "FRAG_CH_SESS",NULL, 0); - g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FINISH]=fieldstat_register(g_ssl_runtime_para.fs, FIELD_TYPE_COUNTER, "FRAG_CH_FIN",NULL, 0); - g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_TIMEOUT]=fieldstat_register(g_ssl_runtime_para.fs, FIELD_TYPE_COUNTER, "FRAG_CH_TOT",NULL, 0); - g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_NUM]=fieldstat_register(g_ssl_runtime_para.fs, FIELD_TYPE_COUNTER, "FRAG_CH_NUM",NULL, 0); - g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FORWARD]=fieldstat_register(g_ssl_runtime_para.fs, FIELD_TYPE_COUNTER, "FRAG_CH_FORWARD",NULL, 0); - g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FREE]=fieldstat_register(g_ssl_runtime_para.fs, FIELD_TYPE_COUNTER, "FRAG_CH_FREE",NULL, 0); + MESA_load_profile_string_def(filename, "SSL", "SSL_STAT_FILE", g_ssl_runtime_para.stat_filename, sizeof(g_ssl_runtime_para.stat_filename), "./metrics/ssl_status.json"); + MESA_load_profile_string_def(filename, "SSL", "SSL_STAT_APPNAME", g_ssl_runtime_para.stat_appname, sizeof(g_ssl_runtime_para.stat_filename), "SSL_DECODER"); + g_ssl_runtime_para.fs=fieldstat_easy_new(get_thread_count(), g_ssl_runtime_para.stat_appname, NULL, 0); + fieldstat_easy_enable_auto_output(g_ssl_runtime_para.fs, g_ssl_runtime_para.stat_filename, refresh_s); + fieldstat_easy_enable_delta_in_active_output(g_ssl_runtime_para.fs); + g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_SESSION]=fieldstat_easy_register_counter(g_ssl_runtime_para.fs, "FRAG_CH_SESS"); + g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FINISH]=fieldstat_easy_register_counter(g_ssl_runtime_para.fs, "FRAG_CH_FIN"); + g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_TIMEOUT]=fieldstat_easy_register_counter(g_ssl_runtime_para.fs, "FRAG_CH_TOT"); + g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_NUM]=fieldstat_easy_register_counter(g_ssl_runtime_para.fs, "FRAG_CH_NUM"); + g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FORWARD]=fieldstat_easy_register_counter(g_ssl_runtime_para.fs, "FRAG_CH_FORWARD"); + g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FREE]=fieldstat_easy_register_counter(g_ssl_runtime_para.fs, "FRAG_CH_FREE"); } @@ -313,7 +322,7 @@ extern "C" void SSL_DESTROY(void) { if(g_ssl_runtime_para.fs != NULL) { - fieldstat_instance_free(g_ssl_runtime_para.fs); + fieldstat_easy_free(g_ssl_runtime_para.fs); } return; } diff --git a/src/SSL_Analyze.h b/src/SSL_Analyze.h index f69d86a..faaf049 100644 --- a/src/SSL_Analyze.h +++ b/src/SSL_Analyze.h @@ -70,14 +70,13 @@ struct ssl_runtime_para unsigned short ssl_plugid; char ssl_conf_regionname[MAX_REGION_NUM][REGION_NAME_LEN]; char stat_filename[256]; - char stat_dst_ip[64]; char stat_appname[16]; int proto_tag_id ; int max_cache_len; int parse_certificate_detail; unsigned int detain_frag_chello_num; int frag_chello_exdata_idx; - struct fieldstat_instance *fs; + struct fieldstat_easy *fs; int fs_metric_id[FS_METRIC_MAX]; }; diff --git a/src/SSL_Message.c b/src/SSL_Message.c index 57ef418..cab9954 100644 --- a/src/SSL_Message.c +++ b/src/SSL_Message.c @@ -12,7 +12,7 @@ #include "SSL_Message.h" #include "SSL_Proc.h" #include "SSL_Certificate.h" -#include "fieldstat.h" +#include "fieldstat/fieldstat_easy.h" #define SUITE_VALUELEN 2 @@ -994,8 +994,11 @@ static void ssl_detain_frag_chello(const struct streaminfo *a_tcp) if (pkts == NULL) { pkts=(struct frag_chello *)calloc(sizeof(struct frag_chello), 1); - if(g_ssl_runtime_para.fs)fieldstat_value_incrby(g_ssl_runtime_para.fs, + if(g_ssl_runtime_para.fs)fieldstat_easy_counter_incrby(g_ssl_runtime_para.fs, + a_tcp->threadnum, g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_SESSION], + NULL, + 0, 1); } if(pkts->finish == 1)return; @@ -1006,8 +1009,11 @@ static void ssl_detain_frag_chello(const struct streaminfo *a_tcp) pkts->p[pkts->p_sz]=dpkt; pkts->p_sz+=1; if(pkts->p_sz==g_ssl_runtime_para.detain_frag_chello_num)pkts->finish=1; - if(g_ssl_runtime_para.fs)fieldstat_value_incrby(g_ssl_runtime_para.fs, + if(g_ssl_runtime_para.fs)fieldstat_easy_counter_incrby(g_ssl_runtime_para.fs, + a_tcp->threadnum, g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_NUM], + NULL, + 0, 1); } stream_bridge_async_data_put(a_tcp, g_ssl_runtime_para.frag_chello_exdata_idx, pkts); @@ -1019,8 +1025,11 @@ static void ssl_detain_chello_finish(const struct streaminfo *a_tcp) if(g_ssl_runtime_para.detain_frag_chello_num == 0)return; struct frag_chello *pkts = (struct frag_chello *)stream_bridge_async_data_get(a_tcp, g_ssl_runtime_para.frag_chello_exdata_idx); if(pkts)pkts->finish=1; - if(g_ssl_runtime_para.fs)fieldstat_value_incrby(g_ssl_runtime_para.fs, + if(g_ssl_runtime_para.fs)fieldstat_easy_counter_incrby(g_ssl_runtime_para.fs, + a_tcp->threadnum, g_ssl_runtime_para.fs_metric_id[FS_METRIC_DETAIN_FRAG_CHELLO_FINISH], + NULL, + 0, 1); return; } -- cgit v1.2.3