diff options
| author | liuxueli <[email protected]> | 2023-10-11 11:41:32 +0800 |
|---|---|---|
| committer | liuxueli <[email protected]> | 2023-10-11 11:41:32 +0800 |
| commit | 24c3e11424c66b6ac57deef298e898a966e87af9 (patch) | |
| tree | 9483a3685e05a22d32bf0a83dd1c0fa7d7dbd876 | |
| parent | b174b308f019b5a6bd85dc70e34fda979d4aa4b4 (diff) | |
支持输出动态IPPORT表的查询数及命中数统计v6.0.54
| -rw-r--r-- | src/tsg_rule.cpp | 16 | ||||
| -rw-r--r-- | src/tsg_stat.cpp | 34 | ||||
| -rw-r--r-- | src/tsg_stat.h | 11 | ||||
| -rw-r--r-- | src/tsg_statistic.cpp | 2 |
4 files changed, 43 insertions, 20 deletions
diff --git a/src/tsg_rule.cpp b/src/tsg_rule.cpp index ff7abd7..ec16fc8 100644 --- a/src/tsg_rule.cpp +++ b/src/tsg_rule.cpp @@ -2442,12 +2442,24 @@ int srt_attribute_set_dynamic_ipport_mapping(const struct streaminfo *a_stream, if(*dest_mapping==NULL) { - maat_ipport_plugin_table_get_ex_data(feather, g_tsg_maat_rt_para.plugin_dyn_mapping_tb.id, &dest_ip, dest_port, (void **)dest_mapping, 1); + tsg_stat_dyn_ipport_mapping_metrics_update(a_stream->threadnum, THREAD_DYN_IPPORT_MAPPING_QUERY_METRICS, 1); + + int n_ex_data=maat_ipport_plugin_table_get_ex_data(feather, g_tsg_maat_rt_para.plugin_dyn_mapping_tb.id, &dest_ip, dest_port, (void **)dest_mapping, 1); + if(n_ex_data>0) + { + tsg_stat_dyn_ipport_mapping_metrics_update(a_stream->threadnum, THREAD_DYN_IPPORT_MAPPING_RESPONSE_METRICS, 1); + } } if(*source_mapping==NULL) { - maat_ipport_plugin_table_get_ex_data(feather, g_tsg_maat_rt_para.plugin_dyn_mapping_tb.id, &source_ip, source_port, (void **)source_mapping, 1); + tsg_stat_dyn_ipport_mapping_metrics_update(a_stream->threadnum, THREAD_DYN_IPPORT_MAPPING_QUERY_METRICS, 1); + + int n_ex_data=maat_ipport_plugin_table_get_ex_data(feather, g_tsg_maat_rt_para.plugin_dyn_mapping_tb.id, &source_ip, source_port, (void **)source_mapping, 1); + if(n_ex_data>0) + { + tsg_stat_dyn_ipport_mapping_metrics_update(a_stream->threadnum, THREAD_DYN_IPPORT_MAPPING_RESPONSE_METRICS, 1); + } } return 0; diff --git a/src/tsg_stat.cpp b/src/tsg_stat.cpp index cc9022c..57fc447 100644 --- a/src/tsg_stat.cpp +++ b/src/tsg_stat.cpp @@ -15,12 +15,6 @@ enum OP_EXDATA OP_EXDATA_MAX }; -enum APP_METRICS -{ - APP_METRICS_COUNT=0, - APP_METRICS_MAX -}; - struct fs3_rule_stat { int table_id; @@ -67,10 +61,10 @@ struct fs3_sync_application int column_id[SYNC_APP_MAX]; }; -struct fs3_application_metrics +struct fs3_thread_metrics { int table_id; - int *column_id; + int (*column_id)[THREAD_METRICS_MAX]; }; struct fs3_sync_exdata @@ -95,7 +89,7 @@ struct runtime_stat_para struct fs3_sync_exdata exdata; struct fs3_sendlog_stat sendlog; struct fs3_sync_application sync_app; - struct fs3_application_metrics app_metrics; + struct fs3_thread_metrics thread_metrics; struct fs3_sync_ctrl_stat ctrl_sync; struct fs3_sync_ctrl_service ctrl_service; struct fieldstat_instance *fs_instance; @@ -207,14 +201,22 @@ void tsg_stat_sync_application_update(enum SYNC_APP column_idx, long long increa } } -void tsg_stat_application_metrics_count_set(int row_idx, long long current) +void tsg_stat_application_metrics_count_set(int row_idx, enum THREAD_METRICS column_idx, long long current) { if(g_rt_stat_para.fs_instance!=NULL) { - fieldstat_value_set(g_rt_stat_para.fs_instance, g_rt_stat_para.app_metrics.column_id[row_idx], current); + fieldstat_value_set(g_rt_stat_para.fs_instance, g_rt_stat_para.thread_metrics.column_id[row_idx][column_idx], current); } } +void tsg_stat_dyn_ipport_mapping_metrics_update(int row_idx, enum THREAD_METRICS column_idx, long long increase) +{ + if(g_rt_stat_para.fs_instance!=NULL) + { + stat_update(g_rt_stat_para.thread_metrics.column_id[row_idx][column_idx], increase); + } +} + void tsg_stat_ctrl_service_activing_update(enum STAT_STATUS status, enum CTRL_SERVICE column_idx, long long increase) { if(g_rt_stat_para.fs_instance==NULL) @@ -363,16 +365,16 @@ int tsg_stat_init(void) g_rt_stat_para.sendlog.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "sendlog", sendlog_column_name, sendlog_column_type, LOG_STATUS_MAX); char fs3_table_name[128]={0}; - enum field_type app_metrics_column_type[APP_METRICS_MAX]={FIELD_TYPE_GAUGE}; - const char *app_metrics_column_name[APP_METRICS_MAX]={"metric_cnt"}; - g_rt_stat_para.app_metrics.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "application", app_metrics_column_name, app_metrics_column_type, APP_METRICS_MAX); + enum field_type thread_metrics_column_type[THREAD_METRICS_MAX]={FIELD_TYPE_GAUGE, FIELD_TYPE_GAUGE, FIELD_TYPE_GAUGE}; + const char *thread_metrics_column_name[THREAD_METRICS_MAX]={"app_metric_cnt", "dyn_mapping_Q", "dyn_mapping_R"}; + g_rt_stat_para.thread_metrics.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "thread", thread_metrics_column_name, thread_metrics_column_type, THREAD_METRICS_MAX); int thread_count=get_thread_count(); - g_rt_stat_para.app_metrics.column_id=(int *)calloc(thread_count, sizeof(int)); + g_rt_stat_para.thread_metrics.column_id=(int (*)[THREAD_METRICS_MAX])calloc(thread_count, sizeof(int[THREAD_METRICS_MAX])); for(int i=0; i<thread_count; i++) { snprintf(fs3_table_name, sizeof(fs3_table_name), "thread_%d", i); - fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.app_metrics.table_id, fs3_table_name, NULL, 0, &(g_rt_stat_para.app_metrics.column_id[i])); + fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.thread_metrics.table_id, fs3_table_name, NULL, 0, g_rt_stat_para.thread_metrics.column_id[i]); } return 0; diff --git a/src/tsg_stat.h b/src/tsg_stat.h index 5d3740b..453b5f7 100644 --- a/src/tsg_stat.h +++ b/src/tsg_stat.h @@ -119,6 +119,14 @@ enum CTRL_SERVICE CTRL_SERVICE_MAX }; +enum THREAD_METRICS +{ + THREAD_APP_METRICS_COUNT=0, + THREAD_DYN_IPPORT_MAPPING_QUERY_METRICS, + THREAD_DYN_IPPORT_MAPPING_RESPONSE_METRICS, + THREAD_METRICS_MAX +}; + int tsg_stat_create(const char *conffile); int tsg_stat_init(void); int tsg_stat_sendlog_row_init(const char *row_name); @@ -131,7 +139,8 @@ void tsg_stat_log_handle_update(enum LOG_HANDLE column_idx, long long increase); void tsg_stat_sync_exdata_add_update(enum SYNC_EXDATA_ROW row_idx, long long increase); void tsg_stat_sync_exdata_del_update(enum SYNC_EXDATA_ROW row_idx, long long increase); void tsg_stat_sync_application_update(enum SYNC_APP column_idx, long long increase); -void tsg_stat_application_metrics_count_set(int row_idx, long long current); +void tsg_stat_application_metrics_count_set(int row_idx, enum THREAD_METRICS column_idx, long long current); +void tsg_stat_dyn_ipport_mapping_metrics_update(int row_idx, enum THREAD_METRICS column_idx, long long increase); void tsg_stat_sendlog_update(int row_idx, enum LOG_STATUS column_idx, long long increase); void tsg_stat_flow_update(enum STAT_STATUS status, enum FLOW_STAT column_idx, long long increase); void tsg_stat_sync_ctrl_update(enum STAT_STATUS status, enum CTRL_SYNC column_idx, long long increase); diff --git a/src/tsg_statistic.cpp b/src/tsg_statistic.cpp index 9a05579..636bc5b 100644 --- a/src/tsg_statistic.cpp +++ b/src/tsg_statistic.cpp @@ -341,7 +341,7 @@ int tsg_set_application_metrics(const struct streaminfo *a_stream, const char *l thread_seq ); - tsg_stat_application_metrics_count_set(thread_seq, fieldstat_dynamic_read_htable_item_cnt(g_tsg_statis_para.fs_application.metrics_handle, thread_seq)); + tsg_stat_application_metrics_count_set(thread_seq, THREAD_APP_METRICS_COUNT, fieldstat_dynamic_read_htable_item_cnt(g_tsg_statis_para.fs_application.metrics_handle, thread_seq)); return 0; } |
