diff options
| author | 杨威 <[email protected]> | 2023-06-20 16:01:35 +0800 |
|---|---|---|
| committer | 杨威 <[email protected]> | 2023-06-26 20:18:26 +0800 |
| commit | 096bbda71ea301fe6dbdc603b5cbf06bfc0d73ed (patch) | |
| tree | 7009752d8a71c4f7f4aafcce6263464d5277be80 /src/extensions | |
| parent | acc0ee76193f032c64dca379acad9c7256d6e13f (diff) | |
🦄 refactor(Remove obsolete code): makefile and dictator
Diffstat (limited to 'src/extensions')
| -rw-r--r-- | src/extensions/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | src/extensions/Makefile | 150 | ||||
| -rw-r--r-- | src/extensions/sapp_assistant.cpp | 432 | ||||
| -rw-r--r-- | src/extensions/sapp_metrics.cpp | 433 |
4 files changed, 440 insertions, 590 deletions
diff --git a/src/extensions/CMakeLists.txt b/src/extensions/CMakeLists.txt index 897f33c..86581af 100644 --- a/src/extensions/CMakeLists.txt +++ b/src/extensions/CMakeLists.txt @@ -26,14 +26,9 @@ set_target_properties(isakmp_protocol_plug PROPERTIES PREFIX "") add_library(inline_keepalive STATIC inline_keepalive.cpp) -if(ENABLE_STATIC_LINK) - add_library(sapp_assistant STATIC sapp_assistant.cpp) - add_library(gdev_assistant STATIC gdev_assistant.c) -else() - add_definitions(-fPIC) - add_library(sapp_assistant SHARED sapp_assistant.cpp) - add_library(gdev_assistant SHARED gdev_assistant.c) - install(TARGETS sapp_assistant DESTINATION ${MESA_SDK_PREFIX}/lib/) - install(TARGETS gdev_assistant DESTINATION ${MESA_SDK_PREFIX}/lib/) -endif() +add_library(sapp_assistant STATIC sapp_assistant.cpp) +add_library(gdev_assistant STATIC gdev_assistant.c) + +add_library(sapp_metrics STATIC sapp_metrics.cpp) + diff --git a/src/extensions/Makefile b/src/extensions/Makefile deleted file mode 100644 index 4642a90..0000000 --- a/src/extensions/Makefile +++ /dev/null @@ -1,150 +0,0 @@ -#opt: OPTFLAGS = -O2
-#export OPTFLAGS
-
-#CC = g++
-#CCC = g++
-CFLAGS += -Wall
-CFLAGS += -g -fPIC -shared -D_DEFAULT_SOURCE -D_DEFAULT_SOURCE -D__DEFAULT_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H
-CFLAGS += $(OPTFLAGS)
-CFLAGS += -DPLATFORM_NSDPF_PAPP=1
-
-
-RELEASE_PLT_PATH=../../bin/plug/platform
-RELEASE_PRO_PATH=../../bin/plug/protocol
-RELEASE_BIZ_PATH=../../bin/plug/business
-
-H_DIR += $(INC)
-H_DIR += -I../../include/
-H_DIR += -I../../include/public
-H_DIR += -I../../include/private
-H_DIR += -I../../include/support
-H_DIR += -I/opt/MESA/include
-H_DIR += -I/opt/MESA/include/MESA
-H_DIR += -I/opt/mrzcpd/include
-
-LIB=-L/opt/MESA/lib -L/opt/mrzcpd/lib
-
-TARGET = isakmp_protocol_plug.so ipsec_biz_sample.so l2tp_protocol_plug.so l2tp_biz_sample.so
-TARGET += pptp_protocol_plug.so pptp_biz_sample.so
-TARGET += g_device_plug.so
-TARGET += wy_keepalive_plug.so
-
-OBJS=
-
-ifeq ($(link_mode), $(__LINK_MODE_STATIC))
- OBJS += sapp_assistant.o
- TARGET += libinner_plug.a
-else
- TARGET += libsapp_assistant.so
-endif
-
-
-ifeq ($(iomode), $(_MODE_PCAP))
-CFLAGS += -DIOMODE_PCAP=1
-endif
-
-ifeq ($(iomode), $(_MODE_PAG))
-CFLAGS += -DIOMODE_PAG=1
-endif
-
-ifeq ($(iomode), $(_MODE_PPF))
-CFLAGS += -DIOMODE_PPF=1
-endif
-
-ifeq ($(iomode), $(_MODE_PFRING))
-CFLAGS += -DIOMODE_PFRING=1
-endif
-
-ifeq ($(iomode), $(_MODE_DPDK))
-CFLAGS += -DIOMODE_DPDK=1
-endif
-
-ifeq ($(iomode), $(_MODE_TOPSEC))
-CFLAGS += -DIOMODE_TOPSEC=1
-endif
-
-ifeq ($(iomode), $(_MODE_IPFILE))
-CFLAGS += -DIOMODE_IPFILE=1
-endif
-
-ifeq ($(iomode), $(_MODE_MARSIO))
-CFLAGS += -DIOMODE_MARSIO=1
-LIB += -lmarsio
-endif
-
-ifeq ($(iomode), $(_MODE_SMITH))
-CFLAGS += -DIOMODE_SMITH=1
-endif
-
-all: $(TARGET)
-
-libinner_plug.a:sapp_assistant.o gdev_assistant.o
- rm -f $@;
- ar -r $@ $^;
- cp $@ ../lib;
-
-.c.o:
- $(CC) -c $(CFLAGS) -I. $(H_DIR) $<
-
-.cpp.o:
- $(CCC) -c $(CFLAGS) -I. $(H_DIR) $<
-
-
-#isakmp_protocol_plug.so:isakmp_protocol_plug.o
-isakmp_protocol_plug.so:isakmp_protocol_plug_add_nat.o
- $(CC) -o $@ -fPIC -shared -g -Wall $^;
- mkdir -p $(RELEASE_PRO_PATH)/isakmp_protocol_plug;
- cp $@ $(RELEASE_PRO_PATH)/isakmp_protocol_plug/ ;
-
-ipsec_biz_sample.so:ipsec_biz_sample.o
- $(CC) -o $@ -fPIC -shared -g -Wall $^;
- mkdir -p $(RELEASE_BIZ_PATH)/ipsec_biz_sample;
- cp $@ $(RELEASE_BIZ_PATH)/ipsec_biz_sample/ ;
-
-l2tp_protocol_plug.so:l2tp_protocol_plug.o
- $(CC) -o $@ -fPIC -shared -g -Wall $^;
- mkdir -p $(RELEASE_PRO_PATH)/l2tp_protocol_plug;
- cp $@ $(RELEASE_PRO_PATH)/l2tp_protocol_plug/ ;
-
-l2tp_biz_sample.so:l2tp_biz_sample.o
- $(CC) -o $@ -fPIC -shared -g -Wall $^;
- mkdir -p $(RELEASE_BIZ_PATH)/l2tp_biz_sample;
- cp $@ $(RELEASE_BIZ_PATH)/l2tp_biz_sample/ ;
-
-pptp_protocol_plug.so:pptp_protocol_plug.o
- $(CC) -o $@ -fPIC -shared -g -Wall $^;
- mkdir -p $(RELEASE_PRO_PATH)/pptp_protocol_plug;
- cp $@ $(RELEASE_PRO_PATH)/pptp_protocol_plug/ ;
-
-pptp_biz_sample.so:pptp_biz_sample.o
- $(CC) -o $@ -fPIC -shared -g -Wall $^;
- mkdir -p $(RELEASE_BIZ_PATH)/pptp_biz_sample;
- cp $@ $(RELEASE_BIZ_PATH)/pptp_biz_sample/ ;
-
-g_device_plug.so: g_device_plug.o
- $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES);
- mkdir -p $(RELEASE_PLT_PATH)/g_device_plug;
- cp $@ $(RELEASE_PLT_PATH)/g_device_plug/
-
-wy_keepalive_plug.so:wy_keepalive_plug.c
- $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES) $(H_DIR) $(LIB);
- mkdir -p $(RELEASE_PLT_PATH)/wy_keepalive_plug;
-
-libsapp_assistant.so: sapp_assistant.o gdev_assistant.o
- mkdir -p /opt/MESA/lib;
- cp ../lib/libc3client.so /opt/MESA/lib/;
- ldconfig;
- $(CC) -o $@ -shared -fPIC $(H_DIR) $(CFLAGS) $^ $(MODULES) -L/opt/MESA/lib -lMESA_field_stat2;
-
-
-libanti_flood_hijack.so:anti_flood_plug.o anti_flood_hijack.o
- $(CC) -o $@ -shared -fPIC $(CFLAGS) $^ $(MODULES);
- mkdir -p $(RELEASE_BIZ_PATH)/anti_flood;
- cp $@ $(RELEASE_BIZ_PATH)/anti_flood/;
- cp $@ /opt/MESA/lib/libanti_flood_hijack.so;
-
-clean:
- rm -f *.o *.so *.a $(TARGET)
-
-opt:
- $(MAKE) all
diff --git a/src/extensions/sapp_assistant.cpp b/src/extensions/sapp_assistant.cpp index 666605e..4ad351a 100644 --- a/src/extensions/sapp_assistant.cpp +++ b/src/extensions/sapp_assistant.cpp @@ -6,13 +6,11 @@ #include "sapp_api.h" #include "sapp_private_api.h" #include "sapp_declaration.h" -#include "field_stat2.h" -#include "fieldstat.h" + #include "marsio.h" -static int sapp_fs2_init(sapp_global_t *global_parameters); -static int sapp_fs3_init(sapp_global_t *global_parameters); + //extern time_t g_CurrentTime;//add by lqy 20070606 //extern int g_packet_io_thread_num; @@ -25,7 +23,6 @@ static pthread_t *g_plug_Independent_thread_pid; static const unsigned char G_BROADCAST_ADDR[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; -int sapp_assistant_version_VERSION_20181024; extern "C" int MESA_get_dev_ipv4(const char *device, int *ip_add); extern "C" int MESA_get_dev_mac(const char *device, unsigned char mac[6]); @@ -872,136 +869,6 @@ extern "C" int sapp_get_device_opt(const char *device, enum sapp_device_opt opt_ return ret; } -void sapp_fs2_update_count(int field_index, unsigned long long value) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_id_count_array[field_index], - 0, FS_OP_SET, (long long)value); - } -} - -void sapp_fs2_update_length(int field_index, unsigned long long value) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_id_length_array[field_index], - 0, FS_OP_SET, (long long)value); - } -} - - -void sapp_fs2_set_latency(int thead_seq, long long time_cost) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_latency_id_array[thead_seq], - 0, FS_OP_SET, time_cost); - } -} - - -void sapp_fs2_set_plug_entry_latency(int entry_id, long long time_cost) -{ - if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){ - return; - } - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_latency_plug_entrg_id_array[entry_id], - 0, FS_OP_SET, time_cost); - } -} - -/* - ģ�������������ʱ, ����ÿ����������һ��FS_operate(), - ��sapp timer�߳�ÿ��һ��ʱ�����sapp_fuzzy_latency_update(), ����filed_stat2����. -*/ -extern "C" void sapp_fs2_fuzzy_latency_update_per_thread(int thead_seq, long long time_cost) -{ - sapp_fuzzy_latency_stat_t *this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_thread; - - if(time_cost < this_thread_stat->min_time_cost){ - this_thread_stat->min_time_cost = time_cost; - } - - if(time_cost > this_thread_stat->max_time_cost){ - this_thread_stat->max_time_cost = time_cost; - } - - this_thread_stat->time_cost_sum += time_cost; - this_thread_stat->stat_count++; -} - -extern "C" void sapp_fs2_fuzzy_latency_update_per_entry(int thead_seq, int entry_id, long long time_cost) -{ - sapp_fuzzy_latency_stat_t *this_thread_stat; - if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){ - return; - } - - this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id]; - - if(time_cost < this_thread_stat->min_time_cost){ - this_thread_stat->min_time_cost = time_cost; - } - - if(time_cost > this_thread_stat->max_time_cost){ - this_thread_stat->max_time_cost = time_cost; - } - - this_thread_stat->time_cost_sum += time_cost; - this_thread_stat->stat_count++; - -} - - -/* - ��sapp timer�����̵߳���, ÿ��һ��ʱ��, �����۵İ�������ʱ����ˢ�¸�field_stat2. -*/ -void sapp_fuzzy_latency_update(void) -{ - int tid, entry_id, this_stat_count; - long long min_latency, max_latency; - double avg_latency; - sapp_fuzzy_latency_stat_t *this_thread_stat, *this_entry_stat; - - for(tid = 0; tid < g_packet_io_thread_num; tid++){ - this_thread_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_thread; - avg_latency = (double)this_thread_stat->time_cost_sum/(double)this_thread_stat->stat_count; - min_latency = this_thread_stat->min_time_cost; - max_latency = this_thread_stat->max_time_cost; - this_stat_count = this_thread_stat->stat_count; - - if(this_stat_count > 0){ - memset(this_thread_stat, 0, sizeof(sapp_fuzzy_latency_stat_t)); - this_thread_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */ - - /* ÿ�θ�������ֵ, ���,��С��ƽ��ֵ */ - sapp_fs2_set_latency(tid, min_latency); - sapp_fs2_set_latency(tid, max_latency); - sapp_fs2_set_latency(tid, (long long)avg_latency); - } - - for(entry_id = 1; entry_id < g_plug_global_entry_index; entry_id++){ - this_entry_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id]; - avg_latency = (double)this_entry_stat->time_cost_sum/(double)this_entry_stat->stat_count; - min_latency = this_entry_stat->min_time_cost; - max_latency = this_entry_stat->max_time_cost; - this_stat_count = this_entry_stat->stat_count; - if(this_stat_count > 0){ - memset(this_entry_stat, 0, sizeof(sapp_fuzzy_latency_stat_t)); - this_entry_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */ - - sapp_fs2_set_latency(tid, min_latency); - sapp_fs2_set_latency(tid, max_latency); - sapp_fs2_set_plug_entry_latency(entry_id, (long long)avg_latency); - } - } - } -} - - int sapp_independent_thread_init(void) { pthread_mutex_init(&g_plug_Independent_thread_mutex, NULL); @@ -1012,298 +879,3 @@ int sapp_independent_thread_init(void) return 0; } - -int sapp_metric_init(void) -{ - int ret = 0; - if( sapp_global_val->config.profiling.fs2.enabled == 1) - { - sapp_fs2_init(sapp_global_val); - } - if( sapp_global_val->config.profiling.fs3.enabled == 1) - { - sapp_fs3_init(sapp_global_val); - } - - return ret; -} - - -static int fs2_plug_entry_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt) -{ - int i; - /* 0������sapp���ò��, index��1��ʼ */ - for(i = 1; i < g_plug_global_entry_index; i++){ - fs_rt->fs_latency_plug_entrg_id_array[i] = FS_register_histogram(fs_rt->fs_metric_handle, //Field Stat��� - FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ - g_plug_global_entry[i].plug_entry_name, //ͳ�������ƣ��ַ��� - 1, //���ٵ���Сֵ - 1000000, //���ٵ����ֵ - 2); //���ȣ���С�����λ����Χ1~4 - if(fs_rt->fs_latency_plug_entrg_id_array[i] < 0){ - sapp_runtime_log(RLOG_LV_FATAL, "FS_register_histogram() error, plug name:%s", g_plug_global_entry[i].plug_entry_name); - return -1; - } - } - - return 0; -} - -void sapp_fs2_set_tcp_unorder_historgram(int thead_seq, long long unorder_num) -{ - if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ - FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, - sapp_global_val->individual_fixed.fs2_runtime.fs_tcp_unorder_id_array[thead_seq], - 0, FS_OP_SET, unorder_num); - } -} - -static int fs2_tcp_unorder_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt) -{ - int i; - char histogram_name[16]; - /* 0������sapp���ò��, index��1��ʼ */ - for (i = 1; i < g_packet_io_thread_num; i++) - { - sprintf(histogram_name, "OoO_num(tid_%d)", i); - fs_rt->fs_tcp_unorder_id_array[i] = - FS_register_histogram(fs_rt->fs_metric_handle, // Field Stat��� - FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ - histogram_name, //ͳ�������ƣ��ַ��� - 1, //���ٵ���Сֵ - 65536, //���ٵ����ֵ - 2); //���ȣ���С�����λ����Χ1~4 - if (fs_rt->fs_tcp_unorder_id_array[i] < 0) - { - sapp_runtime_log(RLOG_LV_FATAL, "FS_fs2_tcp_unorder_historgram_init() error, name:%s", - histogram_name); - return -1; - } - } - - return 0; -} - -/************************ C++ compiler **************************************/ -static int sapp_fs2_init(sapp_global_t *global_paramters) -{ - void *fs2_handle=NULL; - int fs2_opt; - sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; - sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2; - int fs2_local_enabled = 0; - int fs2_prometheus_enabled = 0; - - if(strlen(p_fs2_para->local_file) > 0) - { - fs2_local_enabled = 1; - } - if(strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0) - { - fs2_prometheus_enabled = 1; - } - - p_fs2_rt->fs_metric_handle = FS_create_handle(); - if(NULL == p_fs2_rt->fs_metric_handle){ - sapp_log(RLOG_LV_FATAL, 30, 30, "FS_create_handle() error: %s!\n", strerror(errno)); - return -1; - } - fs2_handle = p_fs2_rt->fs_metric_handle; - if(fs2_prometheus_enabled){ - FS_library_set_prometheus_port((unsigned short)p_fs2_para->prometheus_service_port); - FS_library_set_prometheus_url_path(p_fs2_para->prometheus_service_uri); - if(FS_library_init() < 0){ - sapp_log(RLOG_LV_FATAL, 30, 30, "FS_library_init() error, port:%d, url:%s\n", - p_fs2_para->prometheus_service_port, - p_fs2_para->prometheus_service_uri); - return -1; - } - fs2_opt = 1; - FS_set_para(fs2_handle, OUTPUT_PROMETHEUS, &fs2_opt, sizeof(int)); - } - - FS_set_para(fs2_handle, STAT_CYCLE, &p_fs2_para->refresh_interval_s, sizeof(int)); - - fs2_opt = 1; /* 1:Rewrite ,2: Append. */ - FS_set_para(fs2_handle, PRINT_MODE, &fs2_opt, sizeof(int)); - - fs2_opt = 1; - FS_set_para(fs2_handle, PRINT_TRIGGER, &fs2_opt, sizeof(int)); - - fs2_opt = 1; - FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &fs2_opt, sizeof(int)); - - if(fs2_local_enabled){ - FS_set_para(fs2_handle, OUTPUT_DEVICE, ABBR_FS2_LOG_DATA_FILE, strlen(ABBR_FS2_LOG_DATA_FILE)+1); - }else{ - sapp_log(RLOG_LV_INFO, 10, 10, "profiling.log.local.enabled is 0, not save local stat log file.\n"); - FS_set_para(fs2_handle, OUTPUT_DEVICE, "/dev/null", strlen("/dev/null") + 1); - } - FS_set_para(fs2_handle, APP_NAME, sapp_global_val->config.system.instance_name, strlen(sapp_global_val->config.system.instance_name)+1); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Bit"); - - if((DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin) - || (DEPOLYMENT_MODE_TRANSPARENT == sapp_global_val->config.packet_io.depolyment_mode_bin)){ - p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Inbound"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Inbound"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Outbound"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Outbound"); - } - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Pkt"); - //pfs_para->fs_id_length_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bit"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Bit"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_LOST_PKT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_Bit"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_LOST_PKT_STREAM_NUM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_STM"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_DUP_IDENTIFY_ERR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Key_Err"); /* dup�ظ���ʶ������key������� */ - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byT"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byK"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bit"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byT"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byK"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_New"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_Del"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DATA] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Concurrent"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_New"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_Del"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_MORE] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Concurrent"); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C_ALL"); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S_ALL"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C_ALL"); - - - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_RST] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_Rst"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_SYNACK] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_S/A"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Udp"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_GLOBAL_BYPASS] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "DDOS_Bypass"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Bit"); - - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_STM"); - p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Pkt"); - p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Bit"); - - if (unlikely(g_timestamp_record_sw)) - { - if (fs2_tcp_unorder_historgram_init(p_fs2_rt) < 0) - { - return -1; - } - for (int i = 0; i < g_packet_io_thread_num; i++) - { - char histogram_name[16]; - sprintf(histogram_name, "TD_ns(tid_%d)", i); - p_fs2_rt->fs_latency_id_array[i] = FS_register_histogram(fs2_handle, // Field Stat��� - FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ - histogram_name, //ͳ�������ƣ��ַ��� - 1, //���ٵ���Сֵ - 1000000, //���ٵ����ֵ - 2); //���ȣ���С�����λ����Χ1~4 - FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &p_fs2_rt->fs_latency_id_array[i], sizeof(int)); - } - - if (fs2_plug_entry_historgram_init(p_fs2_rt) < 0) - { - return -1; - } - } - FS_start(fs2_handle); - - return 0; -} - -static void sapp_fs2_destroy(sapp_global_t *global_paramters) -{ - sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2; - sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; - if (strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0) - { - FS_library_destroy(); - } - - if (p_fs2_rt->fs_metric_handle) - { - FS_stop(&p_fs2_rt->fs_metric_handle); - } -} - -static int sapp_fs3_init(sapp_global_t *global_paramters) -{ - sapp_config_profiling_metric_t *p_fs3_para = &global_paramters->config.profiling.fs3; - sapp_gval_individual_fixed_fs_t *p_fs3_rt = &global_paramters->individual_fixed.fs3_runtime; - return 0; -} - -static void sapp_fs3_destroy(sapp_global_t *global_paramters) -{ - return; -} - -void sapp_metric_destroy(void) -{ - - if( sapp_global_val->config.profiling.fs2.enabled == 1) - { - sapp_fs2_destroy(sapp_global_val); - } - if( sapp_global_val->config.profiling.fs3.enabled == 1) - { - sapp_fs3_destroy(sapp_global_val); - } -} - - diff --git a/src/extensions/sapp_metrics.cpp b/src/extensions/sapp_metrics.cpp new file mode 100644 index 0000000..6fd1f63 --- /dev/null +++ b/src/extensions/sapp_metrics.cpp @@ -0,0 +1,433 @@ +#include "field_stat2.h" +#include "fieldstat.h" + +#include "sapp_declaration.h" + +static int sapp_fs2_init(sapp_global_t *global_parameters); +static int sapp_fs3_init(sapp_global_t *global_parameters); + + +void sapp_fs2_update_count(int field_index, unsigned long long value) +{ + if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + sapp_global_val->individual_fixed.fs2_runtime.fs_id_count_array[field_index], + 0, FS_OP_SET, (long long)value); + } +} + +void sapp_fs2_update_length(int field_index, unsigned long long value) +{ + if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + sapp_global_val->individual_fixed.fs2_runtime.fs_id_length_array[field_index], + 0, FS_OP_SET, (long long)value); + } +} + + +void sapp_fs2_set_latency(int thead_seq, long long time_cost) +{ + if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + sapp_global_val->individual_fixed.fs2_runtime.fs_latency_id_array[thead_seq], + 0, FS_OP_SET, time_cost); + } +} + + +void sapp_fs2_set_plug_entry_latency(int entry_id, long long time_cost) +{ + if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){ + return; + } + if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + sapp_global_val->individual_fixed.fs2_runtime.fs_latency_plug_entrg_id_array[entry_id], + 0, FS_OP_SET, time_cost); + } +} + +/* + ģ�������������ʱ, ����ÿ����������һ��FS_operate(), + ��sapp timer�߳�ÿ��һ��ʱ�����sapp_fuzzy_latency_update(), ����filed_stat2����. +*/ +extern "C" void sapp_fs2_fuzzy_latency_update_per_thread(int thead_seq, long long time_cost) +{ + sapp_fuzzy_latency_stat_t *this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_thread; + + if(time_cost < this_thread_stat->min_time_cost){ + this_thread_stat->min_time_cost = time_cost; + } + + if(time_cost > this_thread_stat->max_time_cost){ + this_thread_stat->max_time_cost = time_cost; + } + + this_thread_stat->time_cost_sum += time_cost; + this_thread_stat->stat_count++; +} + +extern "C" void sapp_fs2_fuzzy_latency_update_per_entry(int thead_seq, int entry_id, long long time_cost) +{ + sapp_fuzzy_latency_stat_t *this_thread_stat; + if(unlikely(entry_id < 0 || entry_id >= SAPP_MAX_PLUG_ENTRY_NUM)){ + return; + } + + this_thread_stat = &sapp_global_val->mthread_volatile[thead_seq]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id]; + + if(time_cost < this_thread_stat->min_time_cost){ + this_thread_stat->min_time_cost = time_cost; + } + + if(time_cost > this_thread_stat->max_time_cost){ + this_thread_stat->max_time_cost = time_cost; + } + + this_thread_stat->time_cost_sum += time_cost; + this_thread_stat->stat_count++; + +} + + +/* + ��sapp timer�����̵߳���, ÿ��һ��ʱ��, �����۵İ�������ʱ����ˢ�¸�field_stat2. +*/ +void sapp_fuzzy_latency_update(void) +{ + int tid, entry_id, this_stat_count; + long long min_latency, max_latency; + double avg_latency; + sapp_fuzzy_latency_stat_t *this_thread_stat, *this_entry_stat; + + for(tid = 0; tid < g_packet_io_thread_num; tid++){ + this_thread_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_thread; + avg_latency = (double)this_thread_stat->time_cost_sum/(double)this_thread_stat->stat_count; + min_latency = this_thread_stat->min_time_cost; + max_latency = this_thread_stat->max_time_cost; + this_stat_count = this_thread_stat->stat_count; + + if(this_stat_count > 0){ + memset(this_thread_stat, 0, sizeof(sapp_fuzzy_latency_stat_t)); + this_thread_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */ + + /* ÿ�θ�������ֵ, ���,��С��ƽ��ֵ */ + sapp_fs2_set_latency(tid, min_latency); + sapp_fs2_set_latency(tid, max_latency); + sapp_fs2_set_latency(tid, (long long)avg_latency); + } + + for(entry_id = 1; entry_id < g_plug_global_entry_index; entry_id++){ + this_entry_stat = &sapp_global_val->mthread_volatile[tid]->fuzzy_pkt_latency_stat_per_entry_per_thread[entry_id]; + avg_latency = (double)this_entry_stat->time_cost_sum/(double)this_entry_stat->stat_count; + min_latency = this_entry_stat->min_time_cost; + max_latency = this_entry_stat->max_time_cost; + this_stat_count = this_entry_stat->stat_count; + if(this_stat_count > 0){ + memset(this_entry_stat, 0, sizeof(sapp_fuzzy_latency_stat_t)); + this_entry_stat->min_time_cost = 999999999; /* Ҫ��¼��Сֵ, ��ʼ��Ҫ������ֵ */ + + sapp_fs2_set_latency(tid, min_latency); + sapp_fs2_set_latency(tid, max_latency); + sapp_fs2_set_plug_entry_latency(entry_id, (long long)avg_latency); + } + } + } +} + + + + +int sapp_metric_init(void) +{ + int ret = 0; + if( sapp_global_val->config.profiling.fs2.enabled == 1) + { + sapp_fs2_init(sapp_global_val); + } + if( sapp_global_val->config.profiling.fs3.enabled == 1) + { + sapp_fs3_init(sapp_global_val); + } + + return ret; +} + + +static int fs2_plug_entry_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt) +{ + int i; + /* 0������sapp���ò��, index��1��ʼ */ + for(i = 1; i < g_plug_global_entry_index; i++){ + fs_rt->fs_latency_plug_entrg_id_array[i] = FS_register_histogram(fs_rt->fs_metric_handle, //Field Stat��� + FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ + g_plug_global_entry[i].plug_entry_name, //ͳ�������ƣ��ַ��� + 1, //���ٵ���Сֵ + 1000000, //���ٵ����ֵ + 2); //���ȣ���С�����λ����Χ1~4 + if(fs_rt->fs_latency_plug_entrg_id_array[i] < 0){ + sapp_runtime_log(RLOG_LV_FATAL, "FS_register_histogram() error, plug name:%s", g_plug_global_entry[i].plug_entry_name); + return -1; + } + } + + return 0; +} + +void sapp_fs2_set_tcp_unorder_historgram(int thead_seq, long long unorder_num) +{ + if(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle != NULL){ + FS_operate(sapp_global_val->individual_fixed.fs2_runtime.fs_metric_handle, + sapp_global_val->individual_fixed.fs2_runtime.fs_tcp_unorder_id_array[thead_seq], + 0, FS_OP_SET, unorder_num); + } +} + +static int fs2_tcp_unorder_historgram_init(sapp_gval_individual_fixed_fs_t *fs_rt) +{ + int i; + char histogram_name[16]; + /* 0������sapp���ò��, index��1��ʼ */ + for (i = 1; i < g_packet_io_thread_num; i++) + { + sprintf(histogram_name, "OoO_num(tid_%d)", i); + fs_rt->fs_tcp_unorder_id_array[i] = + FS_register_histogram(fs_rt->fs_metric_handle, // Field Stat��� + FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ + histogram_name, //ͳ�������ƣ��ַ��� + 1, //���ٵ���Сֵ + 65536, //���ٵ����ֵ + 2); //���ȣ���С�����λ����Χ1~4 + if (fs_rt->fs_tcp_unorder_id_array[i] < 0) + { + sapp_runtime_log(RLOG_LV_FATAL, "FS_fs2_tcp_unorder_historgram_init() error, name:%s", + histogram_name); + return -1; + } + } + + return 0; +} + +/************************ C++ compiler **************************************/ +static int sapp_fs2_init(sapp_global_t *global_paramters) +{ + void *fs2_handle=NULL; + int fs2_opt; + sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; + sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2; + int fs2_local_enabled = 0; + int fs2_prometheus_enabled = 0; + + if(strlen(p_fs2_para->local_file) > 0) + { + fs2_local_enabled = 1; + } + if(strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0) + { + fs2_prometheus_enabled = 1; + } + + p_fs2_rt->fs_metric_handle = FS_create_handle(); + if(NULL == p_fs2_rt->fs_metric_handle){ + sapp_log(RLOG_LV_FATAL, 30, 30, "FS_create_handle() error: %s!\n", strerror(errno)); + return -1; + } + fs2_handle = p_fs2_rt->fs_metric_handle; + if(fs2_prometheus_enabled){ + FS_library_set_prometheus_port((unsigned short)p_fs2_para->prometheus_service_port); + FS_library_set_prometheus_url_path(p_fs2_para->prometheus_service_uri); + if(FS_library_init() < 0){ + sapp_log(RLOG_LV_FATAL, 30, 30, "FS_library_init() error, port:%d, url:%s\n", + p_fs2_para->prometheus_service_port, + p_fs2_para->prometheus_service_uri); + return -1; + } + fs2_opt = 1; + FS_set_para(fs2_handle, OUTPUT_PROMETHEUS, &fs2_opt, sizeof(int)); + } + + FS_set_para(fs2_handle, STAT_CYCLE, &p_fs2_para->refresh_interval_s, sizeof(int)); + + fs2_opt = 1; /* 1:Rewrite ,2: Append. */ + FS_set_para(fs2_handle, PRINT_MODE, &fs2_opt, sizeof(int)); + + fs2_opt = 1; + FS_set_para(fs2_handle, PRINT_TRIGGER, &fs2_opt, sizeof(int)); + + fs2_opt = 1; + FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &fs2_opt, sizeof(int)); + + if(fs2_local_enabled){ + FS_set_para(fs2_handle, OUTPUT_DEVICE, ABBR_FS2_LOG_DATA_FILE, strlen(ABBR_FS2_LOG_DATA_FILE)+1); + }else{ + sapp_log(RLOG_LV_INFO, 10, 10, "profiling.log.local.enabled is 0, not save local stat log file.\n"); + FS_set_para(fs2_handle, OUTPUT_DEVICE, "/dev/null", strlen("/dev/null") + 1); + } + FS_set_para(fs2_handle, APP_NAME, sapp_global_val->config.system.instance_name, strlen(sapp_global_val->config.system.instance_name)+1); + + + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_LINE] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Line_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Bit"); + + if((DEPOLYMENT_MODE_INLINE == sapp_global_val->config.packet_io.depolyment_mode_bin) + || (DEPOLYMENT_MODE_TRANSPARENT == sapp_global_val->config.packet_io.depolyment_mode_bin)){ + p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Inbound"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_INBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Inbound"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Pkt_Outbound"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_ETH_OUTBOUND] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Bit_Outbound"); + } + + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UNKNOWN] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Unknown_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Pkt"); + //pfs_para->fs_id_length_array[SAPP_STAT_SND_ERROR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Snd_Err_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV4] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv4_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_IPV6] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Ipv6_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bit"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_TCP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Tcp_Bit"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_LOST_PKT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_Bit"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_LOST_PKT_STREAM_NUM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Lost_STM"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_DUP_IDENTIFY_ERR] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Key_Err"); /* dup�ظ���ʶ������key������� */ + + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byT"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Close_byK"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bit"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_RCV_DUP_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Dup_Udp_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_TIMEOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byT"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_CLOSE_BY_KICKOUT] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Close_byK"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_New"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Link_Del"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DATA] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Concurrent"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_NEW] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_New"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DEL] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Link_Del"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_MORE] = FS_register(fs2_handle, FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Concurrent"); + + + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Tcp_Link_Double_ALL"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_C2S_ALL"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Tcp_Link_S2C_ALL"); + + + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_DOUBLE] = FS_register(fs2_handle, FS_STYLE_STATUS,FS_CALC_CURRENT, "Udp_Link_Double_ALL"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_C2S] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_C2S_ALL"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_STREAM_TOTAL_S2C] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "Udp_Link_S2C_ALL"); + + + p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_RST] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_Rst"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_TCP_SYNACK] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Tcp_S/A"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_SND_UDP] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Send_Udp"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_GLOBAL_BYPASS] = FS_register(fs2_handle,FS_STYLE_STATUS, FS_CALC_CURRENT, "DDOS_Bypass"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_STM"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Bypass_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_STM"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_BYPASS_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_BYPASS_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Bypass_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_STM"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_TCP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_TCP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Tcp_Offload_Bit"); + + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_STREAM] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_STM"); + p_fs2_rt->fs_id_count_array[SAPP_STAT_UDP_OFFLOAD_PKTS] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Pkt"); + p_fs2_rt->fs_id_length_array[SAPP_STAT_UDP_OFFLOAD_BYTES] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Udp_Offload_Bit"); + + if (unlikely(g_timestamp_record_sw)) + { + if (fs2_tcp_unorder_historgram_init(p_fs2_rt) < 0) + { + return -1; + } + for (int i = 0; i < g_packet_io_thread_num; i++) + { + char histogram_name[16]; + sprintf(histogram_name, "TD_ns(tid_%d)", i); + p_fs2_rt->fs_latency_id_array[i] = FS_register_histogram(fs2_handle, // Field Stat��� + FS_CALC_SPEED, //����ۼ�ֵ��˲ʱֵ + histogram_name, //ͳ�������ƣ��ַ��� + 1, //���ٵ���Сֵ + 1000000, //���ٵ����ֵ + 2); //���ȣ���С�����λ����Χ1~4 + FS_set_para(fs2_handle, NOT_SEND_METRIC_TO_SERVER, &p_fs2_rt->fs_latency_id_array[i], sizeof(int)); + } + + if (fs2_plug_entry_historgram_init(p_fs2_rt) < 0) + { + return -1; + } + } + FS_start(fs2_handle); + + return 0; +} + +static void sapp_fs2_destroy(sapp_global_t *global_paramters) +{ + sapp_config_profiling_metric_t *p_fs2_para = &global_paramters->config.profiling.fs2; + sapp_gval_individual_fixed_fs_t *p_fs2_rt = &global_paramters->individual_fixed.fs2_runtime; + if (strlen(p_fs2_para->prometheus_service_uri) > 0 && p_fs2_para->prometheus_service_port > 0) + { + FS_library_destroy(); + } + + if (p_fs2_rt->fs_metric_handle) + { + FS_stop(&p_fs2_rt->fs_metric_handle); + } +} + +static int sapp_fs3_init(sapp_global_t *global_paramters) +{ + sapp_config_profiling_metric_t *p_fs3_para = &global_paramters->config.profiling.fs3; + sapp_gval_individual_fixed_fs_t *p_fs3_rt = &global_paramters->individual_fixed.fs3_runtime; + return 0; +} + +static void sapp_fs3_destroy(sapp_global_t *global_paramters) +{ + return; +} + +void sapp_metric_destroy(void) +{ + + if( sapp_global_val->config.profiling.fs2.enabled == 1) + { + sapp_fs2_destroy(sapp_global_val); + } + if( sapp_global_val->config.profiling.fs3.enabled == 1) + { + sapp_fs3_destroy(sapp_global_val); + } +} |
