diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 851bae5..2e1329d 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(common src/tfe_stat.cpp src/tfe_utils.cpp src/tfe_future.cpp src/tfe_http.cpp src/tfe_plugin.cpp src/tfe_rpc.cpp) +add_library(common src/tfe_utils.cpp src/tfe_future.cpp src/tfe_http.cpp src/tfe_plugin.cpp src/tfe_rpc.cpp) target_include_directories(common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_link_libraries(common MESA_handle_logger libevent-static libevent-static-openssl libevent-static-pthreads) diff --git a/common/include/tfe_stat.h b/common/include/tfe_stat.h deleted file mode 100644 index 09b886d..0000000 --- a/common/include/tfe_stat.h +++ /dev/null @@ -1,23 +0,0 @@ -#include "tfe_types.h" -enum TFE_STAT_FIELD -{ - STREAM_NUM=0, - STREAM_OPEN, - STREAM_CLOSE, - STREAM_ERROR, - SSL_NUM, - SSL_OPEN, - SSL_CLOSE, - SSL_ERROR, - SNI_PEAK_FAIL, - IN_BYTES, - OUT_BYTES, - TFE_STAT_MAX -}; -struct tfe_stats -{ - long long value[TFE_STAT_MAX]; - void * fs_handle; - - int fs_ids[TFE_STAT_MAX]; -}; diff --git a/common/src/tfe_stat.cpp b/common/src/tfe_stat.cpp deleted file mode 100644 index 3df0bc8..0000000 --- a/common/src/tfe_stat.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -void* tfe_stat_init(void* fs_handle) -{ - return NULL; -} -void tfe_stat_flush(void* handle) -{ - return; -} - diff --git a/platform/include/internal/platform.h b/platform/include/internal/platform.h index fed6137..b39dbf4 100644 --- a/platform/include/internal/platform.h +++ b/platform/include/internal/platform.h @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -17,7 +16,6 @@ struct tfe_thread_ctx struct event_base * evbase; unsigned char running; - struct tfe_stats stat; struct cert_mgr * cert_mgr; unsigned int nr_modules; diff --git a/platform/include/internal/proxy.h b/platform/include/internal/proxy.h index 6d305fd..72effd1 100644 --- a/platform/include/internal/proxy.h +++ b/platform/include/internal/proxy.h @@ -7,6 +7,11 @@ struct ssl_mgr; struct key_keeper; struct kni_acceptor; +enum TFE_STAT_FIELD +{ + STAT_SIGPIPE, + TFE_STAT_MAX +}; struct tfe_proxy_tcp_options { @@ -53,6 +58,11 @@ struct tfe_proxy /* DEBUG OPTIONS */ unsigned int tcp_all_passthrough; struct tfe_proxy_tcp_options tcp_options; + + /* PERFOMANCE MONIOTR VARIABLES*/ + long long stat_val[TFE_STAT_MAX]; + int fs_id[TFE_STAT_MAX]; + }; diff --git a/platform/src/proxy.cpp b/platform/src/proxy.cpp index 7f3b04d..8847b90 100644 --- a/platform/src/proxy.cpp +++ b/platform/src/proxy.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include static int signals[] = {SIGTERM, SIGQUIT, SIGHUP, SIGPIPE, SIGUSR1}; @@ -127,6 +128,7 @@ static void __signal_handler_cb(evutil_socket_t fd, short what, void * arg) case SIGUSR1: break; case SIGPIPE: + ATOMIC_INC(&(ctx->stat_val[STAT_SIGPIPE])); TFE_LOG_ERROR(ctx->logger, "Warning: Received SIGPIPE; ignoring.\n"); break; default: @@ -138,6 +140,12 @@ static void __signal_handler_cb(evutil_socket_t fd, short what, void * arg) static void __gc_handler_cb(evutil_socket_t fd, short what, void * arg) { tfe_proxy * ctx = (tfe_proxy *) arg; + int i=0; + for(i=0;ifs_handle, ctx->fs_id[i], 0, FS_OP_SET, ATOMIC_READ(&(ctx->stat_val[i]))); + } + FS_passive_output(ctx->fs_handle); return; } @@ -205,6 +213,31 @@ int tfe_proxy_config(struct tfe_proxy * proxy, const char * profile) return 0; } +int tfe_stat_init(struct tfe_proxy * proxy, const char * profile) +{ + const char* fieldstat_output="./tfe.fieldstat"; + const char* app_name="tfe3a"; + int value=0, i=0; + screen_stat_handle_t fs_handle=NULL; + fs_handle=FS_create_handle(); + FS_set_para(fs_handle, OUTPUT_DEVICE, fieldstat_output, strlen(fieldstat_output)+1); + value=1; + FS_set_para(fs_handle, PRINT_MODE, &value, sizeof(value)); + value=0; + FS_set_para(fs_handle, CREATE_THREAD, &value, sizeof(value)); + FS_set_para(fs_handle, APP_NAME, app_name, strlen(app_name)+1); + + const char* spec[TFE_STAT_MAX]; + spec[STAT_SIGPIPE]="sigpipe"; + + for(i=0;ifs_id[i]=FS_register(fs_handle, FS_STYLE_FIELD, FS_CALC_CURRENT,spec[i]); + } + FS_start(fs_handle); + proxy->fs_handle=fs_handle; + return 0; +} #define CHECK_OR_EXIT(condition, fmt, ...) \ @@ -213,7 +246,6 @@ do { if(!(condition)) { TFE_LOG_ERROR(g_default_logger, fmt, ##__VA_ARGS__); exi int main(int argc, char *argv[]) { const char* main_profile="./conf/tfe.conf"; - const char* fieldstat_output="./tfe.fieldstat"; g_default_logger = MESA_create_runtime_log_handle("log/tfe.log", RLOG_LV_DEBUG); if (unlikely(g_default_logger == NULL)) @@ -234,15 +266,8 @@ int main(int argc, char *argv[]) CHECK_OR_EXIT(ret == 0, "Failed at loading profile %s, Exit.", main_profile); /* PERFOMANCE MONITOR */ - g_default_proxy->fs_handle=FS_create_handle(); - FS_set_para(g_default_proxy->fs_handle, OUTPUT_DEVICE, fieldstat_output, strlen(fieldstat_output)+1); - int value=1; - FS_set_para(g_default_proxy->fs_handle, PRINT_MODE, &value, sizeof(value)); - value=0; - FS_set_para(g_default_proxy->fs_handle, CREATE_THREAD, &value, sizeof(value)); - FS_set_para(g_default_proxy->fs_handle, APP_NAME, g_default_proxy->name, strlen(g_default_proxy->name)+1); - FS_start(g_default_proxy->fs_handle); - + tfe_stat_init(g_default_proxy, main_profile); + /* LOGGER */ g_default_proxy->logger = g_default_logger; diff --git a/platform/src/ssl_stream.cpp b/platform/src/ssl_stream.cpp index 0b19890..0cf2da7 100644 --- a/platform/src/ssl_stream.cpp +++ b/platform/src/ssl_stream.cpp @@ -339,7 +339,7 @@ ssl_stream_gc_cb(evutil_socket_t fd, short what, void * arg) int i=0; for(i=0;ifs_handle, i, 0, FS_OP_SET, ATOMIC_READ(&(mgr->stat_val[i]))); + FS_operate(mgr->fs_handle, mgr->fs_id[i], 0, FS_OP_SET, ATOMIC_READ(&(mgr->stat_val[i]))); } return; }