适配libfieldstat3

This commit is contained in:
liuxueli
2023-06-13 11:27:49 +08:00
parent 1e121ac169
commit fdfc48ad20
17 changed files with 789 additions and 502 deletions

View File

@@ -2,13 +2,13 @@ cmake_minimum_required(VERSION 2.8)
add_definitions(-fPIC) add_definitions(-fPIC)
set(SRC tsg_entry.cpp tsg_rule.cpp tsg_ssl_utils.cpp tsg_send_log.cpp tsg_statistic.cpp tsg_ssh_utils.cpp tsg_gtp_signaling.cpp tsg_action.cpp tsg_leaky_bucket.cpp tsg_dns.cpp tsg_icmp.cpp tsg_tamper.cpp tsg_bridge.cpp tsg_protocol.cpp tsg_sync_state.cpp tsg_variable.cpp tsg_proxy.cpp mpack.c) set(SRC tsg_entry.cpp tsg_rule.cpp tsg_ssl_utils.cpp tsg_send_log.cpp tsg_statistic.cpp tsg_ssh_utils.cpp tsg_gtp_signaling.cpp tsg_action.cpp tsg_leaky_bucket.cpp tsg_dns.cpp tsg_icmp.cpp tsg_tamper.cpp tsg_bridge.cpp tsg_protocol.cpp tsg_sync_state.cpp tsg_variable.cpp tsg_proxy.cpp mpack.c tsg_stat.cpp)
include_directories(${CMAKE_SOURCE_DIR}/inc) include_directories(${CMAKE_SOURCE_DIR}/inc)
include_directories(/opt/MESA/include/MESA/) include_directories(/opt/MESA/include/MESA/)
include_directories(/usr/include/) include_directories(/usr/include/)
set(TSG_MASTER_DEPEND_DYN_LIB MESA_handle_logger MESA_prof_load maat4 pthread MESA_field_stat2 rdkafka cjson MESA_jump_layer fieldstat3) set(TSG_MASTER_DEPEND_DYN_LIB MESA_handle_logger MESA_prof_load maat4 pthread rdkafka cjson MESA_jump_layer fieldstat3)
set(CMAKE_INSTALL_PREFIX /home/mesasoft/sapp_run) set(CMAKE_INSTALL_PREFIX /home/mesasoft/sapp_run)

View File

@@ -17,6 +17,7 @@
#include <MESA/stream.h> #include <MESA/stream.h>
#include <MESA/MESA_handle_logger.h> #include <MESA/MESA_handle_logger.h>
#include "tsg_stat.h"
#include "tsg_rule.h" #include "tsg_rule.h"
#include "app_label.h" #include "app_label.h"
#include "tsg_entry.h" #include "tsg_entry.h"
@@ -79,11 +80,11 @@ static int set_drop_stream(const struct streaminfo *a_stream, enum TSG_PROTOCOL
ret=MESA_set_stream_opt(a_stream, MSO_TIMEOUT, (void *)&g_tsg_para.timeout, sizeof(g_tsg_para.timeout)); ret=MESA_set_stream_opt(a_stream, MSO_TIMEOUT, (void *)&g_tsg_para.timeout, sizeof(g_tsg_para.timeout));
if(ret<0) if(ret<0)
{ {
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SET_TIMOUT_FAILED], 0, FS_OP_ADD, 1); tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_SET_TIMEOUT, 1);
} }
else else
{ {
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SET_TIMOUT_SUCCESS], 0, FS_OP_ADD, 1); tsg_stat_flow_update(STAT_STATUS_SUCCESS, FLOW_STAT_SET_TIMEOUT, 1);
} }
break; break;
default: default:
@@ -391,17 +392,18 @@ int tsg_send_inject_packet(const struct streaminfo *a_stream, enum sapp_inject_o
int ret=0; int ret=0;
if(payload==NULL || payload_len<=0) if(payload==NULL || payload_len<=0)
{ {
tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_INJECT, 1);
return -1; return -1;
} }
ret=sapp_inject_pkt((struct streaminfo *)a_stream, sio, payload, payload_len, raw_route_dir); ret=sapp_inject_pkt((struct streaminfo *)a_stream, sio, payload, payload_len, raw_route_dir);
if(ret<=0) if(ret<=0)
{ {
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_INJECT_PKT_FAILED], 0, FS_OP_ADD, 1); tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_INJECT, 1);
return -1; return -1;
} }
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_INJECT_PKT_SUCCESS], 0, FS_OP_ADD, 1); tsg_stat_flow_update(STAT_STATUS_SUCCESS, FLOW_STAT_INJECT, 1);
return 0; return 0;
} }

View File

@@ -20,6 +20,7 @@
#include <MESA/MESA_handle_logger.h> #include <MESA/MESA_handle_logger.h>
#include <MESA/MESA_jump_layer.h> #include <MESA/MESA_jump_layer.h>
#include "tsg_stat.h"
#include "app_label.h" #include "app_label.h"
#include "tsg_rule.h" #include "tsg_rule.h"
#include "tsg_entry.h" #include "tsg_entry.h"
@@ -58,64 +59,6 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL;
char TSG_MASTER_VERSION_20200805 = 0; char TSG_MASTER_VERSION_20200805 = 0;
const char *tsg_conffile="tsgconf/main.conf"; const char *tsg_conffile="tsgconf/main.conf";
struct id2field g_tsg_fs2_field[TSG_FS2_MAX]={{0, TSG_FS2_TCP_LINKS, "tcp_links"},
{0, TSG_FS2_UDP_LINKS, "udp_links"},
{0, TSG_FS2_BYPASS, "bypass"},
{0, TSG_FS2_HIT_ADDR, "hit_addr"},
{0, TSG_FS2_HIT_SHARE, "hit_share"},
{0, TSG_FS2_INTERCEPT, "intercept"},
{0, TSG_FS2_SHAPING, "shaping"},
{0, TSG_FS2_S_CHAINING, "s_chaining"},
{0, TSG_FS2_CTRL_OPENING, "ctrl_open"},
{0, TSG_FS2_CTRL_CLOSING, "ctrl_close"},
{0, TSG_FS2_CTRL_ACTIVE, "ctrl_active"},
{0, TSG_FS2_CTRL_RESETALL, "ctrl_rstall"},
{0, TSG_FS2_INJECT_CTRL_SUCCESS, "inject_ctrl_succuess"},
{0, TSG_FS2_INJECT_CTRL_FAILED, "inject_ctrl_failed"},
{0, TSG_FS2_EXCLUSION, "exclusion"},
{0, TSG_FS2_APP_DPKT_RESULT, "D_result"},
{0, TSG_FS2_APP_Q_RESULT, "Q_result"},
{0, TSG_FS2_APP_USER_RESULT, "U_result"},
{0, TSG_FS2_APP_BUILT_IN_RESULT, "B_result"},
{0, TSG_FS2_INJECT_PKT_SUCCESS, "inject_succuess"},
{0, TSG_FS2_INJECT_PKT_FAILED, "inject_failed"},
{0, TSG_FS2_MIRRORED_PKT_SUCCESS, "mirror_pkt_suc"},
{0, TSG_FS2_MIRRORED_BYTE_SUCCESS, "mirror_byte_suc"},
{0, TSG_FS2_MIRRORED_PKT_FAILED, "mirror_pkt_fai"},
{0, TSG_FS2_MIRRORED_BYTE_FAILED, "mirror_byte_fai"},
{0, TSG_FS2_SET_TIMOUT_SUCCESS, "set_timeout_suc"},
{0, TSG_FS2_SET_TIMOUT_FAILED, "set_timeout_fai"},
{0, TSG_FS2_SUCESS_TAMPER, "tamper_sucess"},
{0, TSG_FS2_TAMPER_FAILED_PLOAD_LESS_4, "tamper_nopload"},
{0, TSG_FS2_TAMPER_FAILED_NOSWAP, "tamper_noswap"},
{0, TSG_FS2_ASN_ADD, "asn_add"},
{0, TSG_FS2_ASN_DEL, "asn_del"},
{0, TSG_FS2_GTPC_ADD, "gtpc_add"},
{0, TSG_FS2_GTPC_DEL, "gtpc_del"},
{0, TSG_FS2_LOCATION_ADD, "location_add"},
{0, TSG_FS2_LOCATION_DEL, "location_del"},
{0, TSG_FS2_FQDN_ADD, "fqdn_add"},
{0, TSG_FS2_FQDN_DEL, "fqdn_del"},
{0, TSG_FS2_SUBSCRIBER_ADD, "subscriber_add"},
{0, TSG_FS2_SUBSCRIBER_DEL, "subscriber_del"},
{0, TSG_FS2_SECURIRY_ADD, "security_add"},
{0, TSG_FS2_SECURIRY_DEL, "security_del"},
{0, TSG_FS2_MIRRORED_ADD, "mirrored_add"},
{0, TSG_FS2_MIRRORED_DEL, "mirrored_del"},
{0, TSG_FS2_HTTP_RES_ADD, "http_res_add"},
{0, TSG_FS2_HTTP_RES_DEL, "http_res_del"},
{0, TSG_FS2_DNS_RES_ADD, "dns_profile_add"},
{0, TSG_FS2_DNS_RES_DEL, "dns_profile_del"},
{0, TSG_FS2_APP_ID_ADD, "app_id_add"},
{0, TSG_FS2_APP_ID_DEL, "app_id_del"},
{0, TSG_FS2_TUNNEL_CATALOG_ADD, "t_catalog_add"},
{0, TSG_FS2_TUNNEL_CATALOG_DEL, "t_catalog_del"},
{0, TSG_FS2_TUNNEL_ENDPOINT_ADD, "t_endpoint_add"},
{0, TSG_FS2_TUNNEL_ENDPOINT_DEL, "t_endpoint_del"},
{0, TSG_FS2_TUNNEL_LABEL_ADD, "t_label_add"},
{0, TSG_FS2_TUNNEL_LABEL_DEL, "t_label_del"}
};
static int init_page_template(const char *conffile) static int init_page_template(const char *conffile)
{ {
char page_path[256]; char page_path[256];
@@ -138,53 +81,6 @@ static int init_page_template(const char *conffile)
return 0; return 0;
} }
static int init_fs2_handle(const char *conffile)
{
int value=0,cycle=0;
int output_prometheus=0;
unsigned short fs_server_port=0;
char app_name[128]={0};
char fs_server_ip[MAX_IPV4_LEN]={0};
char fs_output_path[128]={0};
MESA_load_profile_int_def(conffile, "FIELD_STAT", "CYCLE", &cycle, 30);
MESA_load_profile_short_nodef(conffile, "FIELD_STAT","TELEGRAF_PORT", (short *)&(fs_server_port));
MESA_load_profile_string_nodef(conffile,"FIELD_STAT","TELEGRAF_IP",fs_server_ip, sizeof(fs_server_ip));
MESA_load_profile_string_def(conffile,"FIELD_STAT","OUTPUT_PATH",fs_output_path, sizeof(fs_output_path), "tsg_stat.log");
MESA_load_profile_string_def(conffile,"FIELD_STAT","APP_NAME", app_name, sizeof(app_name), "tsg_master");
MESA_load_profile_int_def(conffile, "FIELD_STAT", "PROMETHEUS", &output_prometheus, 1);
g_tsg_para.fs2_handle=FS_create_handle();
value=1;//Rewrite
FS_set_para(g_tsg_para.fs2_handle, PRINT_MODE, &value, sizeof(value));
value=1;//Do not create stat thread
FS_set_para(g_tsg_para.fs2_handle, CREATE_THREAD, &value, sizeof(value));
FS_set_para(g_tsg_para.fs2_handle, STAT_CYCLE, &cycle, sizeof(cycle));
FS_set_para(g_tsg_para.fs2_handle, APP_NAME, app_name, strlen(app_name)+1);
FS_set_para(g_tsg_para.fs2_handle, OUTPUT_DEVICE, fs_output_path, strlen(fs_output_path)+1);
value=1;
FS_set_para(g_tsg_para.fs2_handle, OUTPUT_PROMETHEUS, &output_prometheus, sizeof(output_prometheus));
if(fs_server_port > 0 && strlen(fs_server_ip) > 0)
{
FS_set_para(g_tsg_para.fs2_handle, STATS_SERVER_IP,fs_server_ip, strlen(fs_server_ip)+1);
FS_set_para(g_tsg_para.fs2_handle, STATS_SERVER_PORT,&(fs_server_port), sizeof(fs_server_port));
}
value=FS_OUTPUT_INFLUX_LINE;
FS_set_para(g_tsg_para.fs2_handle, STATS_FORMAT, &value, sizeof(value));
for(int i=0; i<TSG_FS2_MAX; i++)
{
g_tsg_para.fs2_field_id[i]=FS_register(g_tsg_para.fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, g_tsg_fs2_field[i].name);
}
return 0;
}
static int tsg_get_sn(char *filename, char *device_sn, int device_sn_len) static int tsg_get_sn(char *filename, char *device_sn, int device_sn_len)
{ {
int flags=0; int flags=0;
@@ -249,11 +145,11 @@ static int set_app_timeout(const struct streaminfo *a_stream, struct app_id_dict
int ret=MESA_set_stream_opt(a_stream, MSO_TIMEOUT, (void *)timeout, sizeof(unsigned short)); int ret=MESA_set_stream_opt(a_stream, MSO_TIMEOUT, (void *)timeout, sizeof(unsigned short));
if(ret<0) if(ret<0)
{ {
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SET_TIMOUT_FAILED], 0, FS_OP_ADD, 1); tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_SET_TIMEOUT, 1);
} }
else else
{ {
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SET_TIMOUT_SUCCESS], 0, FS_OP_ADD, 1); tsg_stat_flow_update(STAT_STATUS_SUCCESS, FLOW_STAT_SET_TIMEOUT, 1);
} }
return 1; return 1;
@@ -1181,7 +1077,6 @@ int session_state_sync_in_opening_and_closing(const struct streaminfo *a_stream,
if(atomic_inc(&g_tsg_para.send_resetall)==1) if(atomic_inc(&g_tsg_para.send_resetall)==1)
{ {
tsg_sync_resetall_state(a_stream); tsg_sync_resetall_state(a_stream);
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_CTRL_RESETALL], 0, FS_OP_ADD, 1);
} }
} }
@@ -1189,11 +1084,9 @@ int session_state_sync_in_opening_and_closing(const struct streaminfo *a_stream,
{ {
case OP_STATE_PENDING: case OP_STATE_PENDING:
tsg_sync_opening_state(a_stream, state); tsg_sync_opening_state(a_stream, state);
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_CTRL_OPENING], 0, FS_OP_ADD, 1);
break; break;
case OP_STATE_CLOSE: case OP_STATE_CLOSE:
tsg_sync_closing_state(a_stream, state); tsg_sync_closing_state(a_stream, state);
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_CTRL_CLOSING], 0, FS_OP_ADD, 1);
break; break;
default: default:
break; break;
@@ -1406,8 +1299,6 @@ int session_state_sync_in_activing(const struct streaminfo *a_stream, TSG_SERVIC
return 0; return 0;
} }
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_CTRL_ACTIVE], 0, FS_OP_ADD, 1);
memcpy(matched_rules->rules+matched_rules->n_rules, inc_rules, n_inc_results*sizeof(struct maat_rule)); memcpy(matched_rules->rules+matched_rules->n_rules, inc_rules, n_inc_results*sizeof(struct maat_rule));
matched_rules->n_rules+=n_inc_results; matched_rules->n_rules+=n_inc_results;
int ret=session_matched_rules_async(a_stream, service, (void *)matched_rules); int ret=session_matched_rules_async(a_stream, service, (void *)matched_rules);
@@ -1850,7 +1741,6 @@ static unsigned char matched_security_rules_deal(const struct streaminfo *a_stre
srt_process_context->is_hitted_allow=1; srt_process_context->is_hitted_allow=1;
session_matched_rules_notify(a_stream, TSG_SERVICE_SECURITY, p_rule, 1, a_stream->threadnum); session_matched_rules_notify(a_stream, TSG_SERVICE_SECURITY, p_rule, 1, a_stream->threadnum);
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_BYPASS], 0, FS_OP_ADD, 1);
srt_action_context_set_rule_method(a_stream, TSG_METHOD_TYPE_ALLOW, a_stream->threadnum); srt_action_context_set_rule_method(a_stream, TSG_METHOD_TYPE_ALLOW, a_stream->threadnum);
break; break;
default: default:
@@ -1871,8 +1761,6 @@ static unsigned char matched_security_rules_deal(const struct streaminfo *a_stre
int matched_shaping_rules_deal(const struct streaminfo *a_stream, struct maat_rule *shaping_rules, size_t n_shaping_rules, int thread_seq) int matched_shaping_rules_deal(const struct streaminfo *a_stream, struct maat_rule *shaping_rules, size_t n_shaping_rules, int thread_seq)
{ {
session_state_sync_in_activing(a_stream, TSG_SERVICE_SHAPING, shaping_rules, n_shaping_rules, thread_seq); session_state_sync_in_activing(a_stream, TSG_SERVICE_SHAPING, shaping_rules, n_shaping_rules, thread_seq);
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SHAPING], 0, FS_OP_ADD, 1);
srt_action_context_set_rule_method(a_stream, TSG_METHOD_TYPE_UNKNOWN, thread_seq); srt_action_context_set_rule_method(a_stream, TSG_METHOD_TYPE_UNKNOWN, thread_seq);
return 0; return 0;
@@ -1883,7 +1771,6 @@ int matched_intercept_rules_deal(const struct streaminfo *a_stream, struct maat_
struct maat_rule *p_rule=matched_rules_decision_criteria(intercept_rules, n_intercept_rules); struct maat_rule *p_rule=matched_rules_decision_criteria(intercept_rules, n_intercept_rules);
session_state_sync_in_activing(a_stream, TSG_SERVICE_INTERCEPT, p_rule, 1, thread_seq); session_state_sync_in_activing(a_stream, TSG_SERVICE_INTERCEPT, p_rule, 1, thread_seq);
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_INTERCEPT], 0, FS_OP_ADD, 1);
srt_action_context_set_rule_method(a_stream, TSG_METHOD_TYPE_UNKNOWN, thread_seq); srt_action_context_set_rule_method(a_stream, TSG_METHOD_TYPE_UNKNOWN, thread_seq);
return 0; return 0;
@@ -1997,7 +1884,7 @@ int session_app_identify_result_cb(const struct streaminfo *a_stream, int bridge
break; break;
case ORIGIN_QM_ENGINE: case ORIGIN_QM_ENGINE:
srt_process_context->is_app_link=FLAG_TRUE; srt_process_context->is_app_link=FLAG_TRUE;
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_APP_Q_RESULT], 0, FS_OP_ADD, 1); tsg_stat_sync_application_update(SYNC_APP_THRID, 1);
gather_result->qm_engine_num=session_app_gather_results_update(&(gather_result->qm_engine), gather_result->qm_engine_num, identify_result, get_packet_sequence(a_stream), a_stream->threadnum); gather_result->qm_engine_num=session_app_gather_results_update(&(gather_result->qm_engine), gather_result->qm_engine_num, identify_result, get_packet_sequence(a_stream), a_stream->threadnum);
scan_app=gather_result->qm_engine; scan_app=gather_result->qm_engine;
@@ -2005,7 +1892,7 @@ int session_app_identify_result_cb(const struct streaminfo *a_stream, int bridge
break; break;
case ORIGIN_USER_DEFINE: case ORIGIN_USER_DEFINE:
srt_process_context->is_app_link=FLAG_TRUE; srt_process_context->is_app_link=FLAG_TRUE;
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_APP_USER_RESULT], 0, FS_OP_ADD, 1); tsg_stat_sync_application_update(SYNC_APP_USER_DEFINE, 1);
gather_result->user_define_num=session_app_gather_results_update(&(gather_result->user_define), gather_result->user_define_num, identify_result, get_packet_sequence(a_stream), a_stream->threadnum); gather_result->user_define_num=session_app_gather_results_update(&(gather_result->user_define), gather_result->user_define_num, identify_result, get_packet_sequence(a_stream), a_stream->threadnum);
scan_app=gather_result->user_define; scan_app=gather_result->user_define;
@@ -2013,7 +1900,7 @@ int session_app_identify_result_cb(const struct streaminfo *a_stream, int bridge
break; break;
case ORIGIN_BUILT_IN: case ORIGIN_BUILT_IN:
srt_process_context->is_app_link=FLAG_TRUE; srt_process_context->is_app_link=FLAG_TRUE;
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_APP_BUILT_IN_RESULT], 0, FS_OP_ADD, 1); tsg_stat_sync_application_update(SYNC_APP_BUILT_IN, 1);
gather_result->built_in_num=session_app_gather_results_update(&(gather_result->built_in), gather_result->built_in_num, identify_result, get_packet_sequence(a_stream), a_stream->threadnum); gather_result->built_in_num=session_app_gather_results_update(&(gather_result->built_in), gather_result->built_in_num, identify_result, get_packet_sequence(a_stream), a_stream->threadnum);
scan_app=gather_result->built_in; scan_app=gather_result->built_in;
@@ -2021,6 +1908,7 @@ int session_app_identify_result_cb(const struct streaminfo *a_stream, int bridge
break; break;
case ORIGIN_BASIC_PROTOCOL: case ORIGIN_BASIC_PROTOCOL:
srt_process_context->is_app_link=FLAG_TRUE; srt_process_context->is_app_link=FLAG_TRUE;
tsg_stat_sync_application_update(SYNC_APP_LPI, 1);
if(srt_process_context->proto==PROTO_UNKONWN || srt_process_context->proto==PROTO_APP) if(srt_process_context->proto==PROTO_UNKONWN || srt_process_context->proto==PROTO_APP)
{ {
srt_process_context_set_l7_protocol(srt_process_context, identify_result->app_id[identify_result->app_id_num-1]); srt_process_context_set_l7_protocol(srt_process_context, identify_result->app_id[identify_result->app_id_num-1]);
@@ -2134,10 +2022,8 @@ size_t session_pending_state_deal(const struct streaminfo *a_stream, struct sess
if(ret>0) if(ret>0)
{ {
matched_cnt+=ret; matched_cnt+=ret;
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_HIT_ADDR], 0, FS_OP_ADD, 1);
} }
matched_cnt+=session_app_gather_results_scan(a_stream, matched_rules+matched_cnt, n_matched_rules-matched_cnt, srt_process_context, a_stream->threadnum); matched_cnt+=session_app_gather_results_scan(a_stream, matched_rules+matched_cnt, n_matched_rules-matched_cnt, srt_process_context, a_stream->threadnum);
matched_cnt+=tsg_scan_session_flags(a_stream, g_tsg_maat_feather, srt_process_context->session_flag, (srt_process_context->mid), matched_rules+matched_cnt, n_matched_rules-matched_cnt); matched_cnt+=tsg_scan_session_flags(a_stream, g_tsg_maat_feather, srt_process_context->session_flag, (srt_process_context->mid), matched_rules+matched_cnt, n_matched_rules-matched_cnt);
@@ -2183,15 +2069,6 @@ static unsigned char tsg_master_data_entry(const struct streaminfo *a_stream, vo
{ {
srt_process_context->first_origin_pkt=1; srt_process_context->first_origin_pkt=1;
if(a_stream->type==STREAM_TYPE_TCP)
{
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TCP_LINKS], 0, FS_OP_ADD, 1);
}
else
{
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_UDP_LINKS], 0, FS_OP_ADD, 1);
}
matched_cnt+=session_pending_state_deal(a_stream, srt_process_context, matched_rules+matched_cnt, n_matched_rules-matched_cnt, a_packet); matched_cnt+=session_pending_state_deal(a_stream, srt_process_context, matched_rules+matched_cnt, n_matched_rules-matched_cnt, a_packet);
if (a_stream->type == STREAM_TYPE_TCP && a_packet != NULL) if (a_stream->type == STREAM_TYPE_TCP && a_packet != NULL)
{ {
@@ -2590,7 +2467,8 @@ extern "C" int TSG_MASTER_INIT()
} }
init_page_template(tsg_conffile); init_page_template(tsg_conffile);
init_fs2_handle(tsg_conffile); tsg_stat_create(tsg_conffile);
tsg_stat_init();
ret=tsg_maat_rule_init(tsg_conffile); ret=tsg_maat_rule_init(tsg_conffile);
if(ret<0) if(ret<0)
@@ -2599,16 +2477,17 @@ extern "C" int TSG_MASTER_INIT()
return -1; return -1;
} }
g_tsg_log_instance=tsg_sendlog_init(tsg_conffile, g_tsg_para.fs2_handle); g_tsg_log_instance=tsg_sendlog_init(tsg_conffile);
if(g_tsg_log_instance==NULL) if(g_tsg_log_instance==NULL)
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "INIT_SENDLOG", "tsg_sendlog_init failed ..."); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "INIT_SENDLOG", "tsg_sendlog_init failed ...");
return -1; return -1;
} }
FS_start(g_tsg_para.fs2_handle); // wait send log topic statistic
tsg_stat_start();
ret = tsg_metric_init(tsg_conffile, g_tsg_para.logger); ret=tsg_metric_init(tsg_conffile, g_tsg_para.logger);
if(ret<0) if(ret<0)
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "INIT_STATISTIC", "tsg_metric_init failed ..."); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "INIT_STATISTIC", "tsg_metric_init failed ...");

View File

@@ -5,6 +5,7 @@
#include <time.h> #include <time.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "tsg_stat.h"
#include "MESA/http.h" #include "MESA/http.h"
#include "MESA/cJSON.h" #include "MESA/cJSON.h"
#include <MESA/stream.h> #include <MESA/stream.h>
@@ -443,7 +444,7 @@ void ex_data_gtp_c_new(const char *table_name, int table_id, const char* key, co
atomic_inc(&user_info->ref_cnt); atomic_inc(&user_info->ref_cnt);
*ad=(void *)user_info; *ad=(void *)user_info;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_GTPC_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_GTPC, 1);
return; return;
} }
@@ -462,7 +463,7 @@ void ex_data_gtp_c_free(int table_id, void **ad, long argl, void* argp)
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_GTPC_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_GTPC, 1);
} }
} }
@@ -509,7 +510,7 @@ void ex_data_asn_number_new(const char *table_name, int table_id, const char* ke
atomic_inc(&asn->ref_cnt); atomic_inc(&asn->ref_cnt);
*ad=(void *)asn; *ad=(void *)asn;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_ASN_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_ASN, 1);
return; return;
} }
@@ -525,7 +526,7 @@ void ex_data_asn_number_free(int table_id, void **ad, long argl, void* argp)
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_ASN_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_ASN, 1);
} }
} }
@@ -569,7 +570,7 @@ void ex_data_location_new(const char *table_name, int table_id, const char* key,
atomic_inc(&location->ref_cnt); atomic_inc(&location->ref_cnt);
*ad=(void *)location; *ad=(void *)location;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_LOCATION_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_LOCATION, 1);
return; return;
} }
@@ -588,7 +589,7 @@ void ex_data_location_free(int table_id, void **ad, long argl, void* argp)
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_LOCATION_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_LOCATION, 1);
} }
} }
@@ -627,7 +628,7 @@ void ex_data_fqdn_category_id_new(const char *table_name, int table_id, const ch
atomic_inc(&fqdn_cat->ref_cnt); atomic_inc(&fqdn_cat->ref_cnt);
*ad=(void *)fqdn_cat; *ad=(void *)fqdn_cat;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_FQDN_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_FQDN_CATEGORY, 1);
return; return;
} }
@@ -640,7 +641,7 @@ void ex_data_fqdn_category_id_free(int table_id, void **ad, long argl, void* arg
{ {
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_FQDN_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_FQDN_CATEGORY, 1);
} }
} }
@@ -676,7 +677,7 @@ void ex_data_subscriber_id_new(const char *table_name, int table_id, const char*
atomic_inc(&subscriber->ref_cnt); atomic_inc(&subscriber->ref_cnt);
*ad=(void *)subscriber; *ad=(void *)subscriber;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SUBSCRIBER_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_SUBSCRIBER, 1);
return; return;
} }
@@ -691,7 +692,7 @@ void ex_data_subscriber_id_free(int table_id, void **ad, long argl, void* argp)
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SUBSCRIBER_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_SUBSCRIBER, 1);
} }
} }
@@ -796,7 +797,7 @@ void ex_data_app_id_dict_new(const char *table_name, int table_id, const char* k
atomic_inc(&dict->ref_cnt); atomic_inc(&dict->ref_cnt);
*ad=(void *)dict; *ad=(void *)dict;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_APP_ID_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_APP_ID_DICT, 1);
return; return;
} }
@@ -817,7 +818,7 @@ void ex_data_app_id_dict_free(int table_id, void **ad, long argl, void* argp)
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_APP_ID_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_APP_ID_DICT, 1);
} }
} }
return; return;
@@ -1254,7 +1255,8 @@ void ex_data_security_compile_new(const char *table_name, int table_id, const ch
atomic_inc(&compile->ref_cnt); atomic_inc(&compile->ref_cnt);
*ad=(void *)compile; *ad=(void *)compile;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SECURIRY_ADD], 0, FS_OP_ADD, 1);
tsg_stat_sync_exdata_add_update(SYNC_EXDATA_COMPILE, 1);
return ; return ;
} }
@@ -1357,9 +1359,8 @@ void ex_data_security_compile_free(int table_id, void **ad, long argl, void *arg
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SECURIRY_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_COMPILE, 1);
} }
} }
static char *get_http_pages_content(const char *filename, int *filelen) static char *get_http_pages_content(const char *filename, int *filelen)
@@ -1464,7 +1465,7 @@ void ex_data_http_response_pages_new(const char *table_name, int table_id, const
res_pages=NULL; res_pages=NULL;
} }
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_HTTP_RES_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_HTTP_RESPONSE, 1);
} }
void ex_data_http_response_pages_free(int table_id, void **ad, long argl, void* argp) void ex_data_http_response_pages_free(int table_id, void **ad, long argl, void* argp)
@@ -1478,7 +1479,7 @@ void ex_data_http_response_pages_free(int table_id, void **ad, long argl, void*
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_HTTP_RES_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_HTTP_RESPONSE, 1);
} }
} }
} }
@@ -1552,7 +1553,7 @@ void ex_data_dns_profile_records_new(const char *table_name, int table_id, const
profile_records=NULL; profile_records=NULL;
} }
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_DNS_RES_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_DNS_RESPONSE, 1);
return ; return ;
} }
@@ -1587,7 +1588,7 @@ void ex_data_dns_profile_records_free(int table_id, void **ad, long argl, void *
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_DNS_RES_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_DNS_RESPONSE, 1);
} }
} }
} }
@@ -1625,7 +1626,7 @@ void ex_data_mirrored_profile_new(const char *table_name, int table_id, const ch
tsg_free_field(vlan_ids_str); tsg_free_field(vlan_ids_str);
vlan_ids_str=NULL; vlan_ids_str=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_MIRRORED_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_MIRRORED, 1);
return ; return ;
} }
@@ -1651,7 +1652,7 @@ void ex_data_mirrored_profile_free(int table_id, void **ad, long argl, void *arg
{ {
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_MIRRORED_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_MIRRORED, 1);
} }
} }
} }
@@ -1681,7 +1682,7 @@ void ex_data_tunnel_catalog_new(const char *table_name, int table_id, const char
atomic_inc(&t_catalog->ref_cnt); atomic_inc(&t_catalog->ref_cnt);
*ad=(void *)t_catalog; *ad=(void *)t_catalog;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TUNNEL_CATALOG_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_TUNNEL_CATALOG, 1);
return; return;
} }
void ex_data_tunnel_catalog_free(int table_id, void **ad, long argl, void *argp) void ex_data_tunnel_catalog_free(int table_id, void **ad, long argl, void *argp)
@@ -1699,7 +1700,7 @@ void ex_data_tunnel_catalog_free(int table_id, void **ad, long argl, void *argp)
tsg_free_field(t_catalog->composition); tsg_free_field(t_catalog->composition);
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TUNNEL_CATALOG_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_TUNNEL_CATALOG, 1);
} }
} }
void ex_data_tunnel_catalog_dup(int table_id, void **to, void **from, long argl, void *argp) void ex_data_tunnel_catalog_dup(int table_id, void **to, void **from, long argl, void *argp)
@@ -1722,7 +1723,7 @@ void ex_data_tunnel_endpoint_new(const char *table_name, int table_id, const cha
atomic_inc(&t_endpoint->ref_cnt); atomic_inc(&t_endpoint->ref_cnt);
*ad=(void *)t_endpoint; *ad=(void *)t_endpoint;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TUNNEL_ENDPOINT_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_TUNNEL_ENDPOINT, 1);
return ; return ;
} }
@@ -1749,7 +1750,7 @@ void ex_data_tunnel_endpoint_free(int table_id, void **ad, long argl, void *argp
tsg_free_field(t_endpoint->description); tsg_free_field(t_endpoint->description);
tsg_free_field((char *)(*ad)); tsg_free_field((char *)(*ad));
*ad=NULL; *ad=NULL;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TUNNEL_ENDPOINT_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_TUNNEL_ENDPOINT, 1);
} }
} }
} }
@@ -1763,7 +1764,7 @@ void ex_data_tunnel_label_new(const char *table_name, int table_id, const char*
{ {
int label_id=column_integer_get_value(table_line, 1); int label_id=column_integer_get_value(table_line, 1);
*ad=(void *)(long)label_id; *ad=(void *)(long)label_id;
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TUNNEL_LABEL_ADD], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_add_update(SYNC_EXDATA_TUNNEL_LABEL, 1);
return ; return ;
} }
@@ -1776,7 +1777,7 @@ void ex_data_tunnel_label_dup(int table_id, void **to, void **from, long argl, v
void ex_data_tunnel_label_free(int table_id, void **ad, long argl, void *argp) void ex_data_tunnel_label_free(int table_id, void **ad, long argl, void *argp)
{ {
//FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TUNNEL_LABEL_DEL], 0, FS_OP_ADD, 1); tsg_stat_sync_exdata_del_update(SYNC_EXDATA_TUNNEL_LABEL, 1);
} }
int init_scan_table(struct maat *feather, const char *conffile) int init_scan_table(struct maat *feather, const char *conffile)

View File

@@ -17,6 +17,7 @@
#include <MESA/MESA_prof_load.h> #include <MESA/MESA_prof_load.h>
#include <MESA/MESA_handle_logger.h> #include <MESA/MESA_handle_logger.h>
#include "tsg_stat.h"
#include "app_label.h" #include "app_label.h"
#include "tsg_entry.h" #include "tsg_entry.h"
#include "tsg_bridge.h" #include "tsg_bridge.h"
@@ -45,21 +46,6 @@ struct TLD_handle_t
Document *document; Document *document;
}; };
id2field_t g_log_fs2_field[LOG_FS2_TYPE_MAX]={
{0, LOG_FS2_ABORT_ALLOW, "abort_allow"},
{0, LOG_FS2_ABORT_DENY, "abort_deny"},
{0, LOG_FS2_ABORT_MONITOR, "abort_monitor"},
{0, LOG_FS2_ABORT_INTERCEPT, "abort_intercept"},
{0, LOG_FS2_ABORT_UNKNOWN, "abort_unknown"},
{0, LOG_FS2_CREATE_LOG_HANDLE, "create_log_cnt"},
{0, LOG_FS2_DUP_LOG_HANDLE, "dup_log_cnt"},
{0, LOG_FS2_APPEND_LOG_HANDLE, "append_log_cnt"},
{0, LOG_FS2_FREE_LOG_HANDLE, "free_log_cnt"},
{0, LOG_FS2_FREE_RAPID_SIZE, "free_rapid_size"},
{0, LOG_FS2_FREE_RAPID_CAPACITY, "free_rapid_capacity"}
};
const id2field_t tld_type[TLD_TYPE_MAX]={{TLD_TYPE_UNKNOWN, TLD_TYPE_UNKNOWN, "UNKOWN"}, const id2field_t tld_type[TLD_TYPE_MAX]={{TLD_TYPE_UNKNOWN, TLD_TYPE_UNKNOWN, "UNKOWN"},
{TLD_TYPE_LONG, TLD_TYPE_LONG, "LONG"}, {TLD_TYPE_LONG, TLD_TYPE_LONG, "LONG"},
{TLD_TYPE_STRING, TLD_TYPE_STRING, "STRING"}, {TLD_TYPE_STRING, TLD_TYPE_STRING, "STRING"},
@@ -132,50 +118,52 @@ static int register_topic(struct tsg_log_instance_t *instance, struct topic_stat
topic->drop_start[i]=tsg_get_current_time_ms(); topic->drop_start[i]=tsg_get_current_time_ms();
} }
topic->fs2_line_id=FS_register(_instance->fs2_handle, FS_STYLE_LINE, FS_CALC_SPEED, topic->name); topic->row_idx=tsg_stat_sendlog_row_init((const char *)(topic->name));
return 1; return 1;
} }
static int update_percent(struct tsg_log_instance_t *_instance, int service_id, enum LOG_COLUMN_STATUS column, int thread_id) static int update_percent(struct tsg_log_instance_t *_instance, int service_id, enum LOG_STATUS column, int thread_id)
{ {
long long current_time_ms=tsg_get_current_time_ms(); long long current_time_ms=tsg_get_current_time_ms();
struct topic_stat *topic=(struct topic_stat *)&(_instance->service2topic[service_id]); struct topic_stat *topic=(struct topic_stat *)&(_instance->service2topic[service_id]);
switch(column) switch(column)
{ {
case LOG_COLUMN_STATUS_SUCCESS: case LOG_STATUS_SUCCESS:
FS_operate(_instance->fs2_handle, topic->fs2_line_id, _instance->fs2_column_id[column], FS_OP_ADD, 1); tsg_stat_sendlog_update(topic->row_idx, column, 1);
FS_operate(_instance->fs2_handle, topic->fs2_line_id, _instance->fs2_column_id[column+1], FS_OP_ADD, 1); //tsg_stat_sendlog_update(topic->row_idx, column+1, 1);
FS_operate(_instance->fs2_handle, _instance->sum_line_id, _instance->fs2_column_id[column], FS_OP_ADD, 1); tsg_stat_sendlog_update(_instance->sum_stat_row_id, column, 1);
FS_operate(_instance->fs2_handle, _instance->sum_line_id, _instance->fs2_column_id[column+1], FS_OP_ADD, 1); //tsg_stat_sendlog_update(_instance->sum_stat_row_id, column+1, 1);
break; break;
case LOG_COLUMN_STATUS_FAIL: case LOG_STATUS_FAIL:
FS_operate(_instance->fs2_handle, topic->fs2_line_id, _instance->fs2_column_id[column], FS_OP_ADD, 1); tsg_stat_sendlog_update(topic->row_idx, column, 1);
FS_operate(_instance->fs2_handle, topic->fs2_line_id, _instance->fs2_column_id[column+1], FS_OP_ADD, 1); //tsg_stat_sendlog_update(topic->row_idx, column+1, 1);
tsg_stat_sendlog_update(_instance->sum_stat_row_id, column, 1);
//tsg_stat_sendlog_update(_instance->sum_stat_row_id, column+1, 1);
FS_operate(_instance->fs2_handle, _instance->sum_line_id, _instance->fs2_column_id[column], FS_OP_ADD, 1);
FS_operate(_instance->fs2_handle, _instance->sum_line_id, _instance->fs2_column_id[column+1], FS_OP_ADD, 1);
if(current_time_ms - topic->drop_start[thread_id]>=1000) if(current_time_ms - topic->drop_start[thread_id]>=1000)
{ {
topic->send_log_percent[thread_id]/=2; topic->send_log_percent[thread_id]/=2;
topic->drop_start[thread_id]=current_time_ms; topic->drop_start[thread_id]=current_time_ms;
} }
break; break;
case LOG_COLUMN_STATUS_DROP: case LOG_STATUS_DROP:
if((current_time_ms%100) > topic->send_log_percent[thread_id]) if((current_time_ms%100) > topic->send_log_percent[thread_id])
{ {
FS_operate(_instance->fs2_handle, topic->fs2_line_id, _instance->fs2_column_id[column], FS_OP_ADD, 1); tsg_stat_sendlog_update(topic->row_idx, column, 1);
FS_operate(_instance->fs2_handle, topic->fs2_line_id, _instance->fs2_column_id[column+1], FS_OP_ADD, 1); //tsg_stat_sendlog_update(topic->row_idx, column+1, 1);
tsg_stat_sendlog_update(_instance->sum_stat_row_id, column, 1);
//tsg_stat_sendlog_update(_instance->sum_stat_row_id, column+1, 1);
FS_operate(_instance->fs2_handle, _instance->sum_line_id, _instance->fs2_column_id[column], FS_OP_ADD, 1);
FS_operate(_instance->fs2_handle, _instance->sum_line_id, _instance->fs2_column_id[column+1], FS_OP_ADD, 1);
return 1; return 1;
} }
break; break;
case LOG_COLUMN_STATUS_MAX: case LOG_STATUS_MAX:
if(topic->send_log_percent[thread_id]>=100) if(topic->send_log_percent[thread_id]>=100)
{ {
break; break;
@@ -194,16 +182,6 @@ static int update_percent(struct tsg_log_instance_t *_instance, int service_id,
return 0; return 0;
} }
static struct tsg_log_instance_t *get_log_instance(void)
{
if(g_tsg_log_instance!=NULL)
{
return g_tsg_log_instance;
}
return NULL;
}
static int is_tunnels(const struct streaminfo *a_stream) static int is_tunnels(const struct streaminfo *a_stream)
{ {
const struct streaminfo *ptmp = a_stream; const struct streaminfo *ptmp = a_stream;
@@ -876,28 +854,49 @@ static int set_link_mac(struct tsg_log_instance_t *_instance, struct TLD_handle_
return 1; return 1;
} }
static int action2fs_id(int action) enum RULE_STAT
{ {
RULE_STAT_ABORT=0,
RULE_STAT_SEND
};
static void fs3_rule_stat_update(enum RULE_STAT stat_type, int action, long long increase)
{
enum RULE_TYPE rule_type=RULE_TYPE_UNKNOW;
switch(action) switch(action)
{ {
case TSG_ACTION_DENY: case TSG_ACTION_DENY:
return LOG_FS2_ABORT_DENY; rule_type=RULE_TYPE_DENY; break;
break;
case TSG_ACTION_BYPASS: case TSG_ACTION_BYPASS:
return LOG_FS2_ABORT_ALLOW; rule_type=RULE_TYPE_ALLOW; break;
break;
case TSG_ACTION_MONITOR: case TSG_ACTION_MONITOR:
return LOG_FS2_ABORT_MONITOR; rule_type=RULE_TYPE_MONITOR; break;
break;
case TSG_ACTION_INTERCEPT: case TSG_ACTION_INTERCEPT:
return LOG_FS2_ABORT_INTERCEPT; rule_type=RULE_TYPE_INTERCEPT; break;
break; case TSG_ACTION_NO_INTERCEPT:
rule_type=RULE_TYPE_NO_INTERCEPT; break;
case TSG_ACTION_S_CHAINING:
rule_type=RULE_TYPE_SERVICE_CHAINING; break;
case TSG_ACTION_SHAPING:
rule_type=RULE_TYPE_SHAPING; break;
case TSG_ACTION_SHUNT:
rule_type=RULE_TYPE_SHUNT; break;
default: default:
return LOG_FS2_ABORT_UNKNOWN; rule_type=RULE_TYPE_UNKNOW; break;
break;
} }
return LOG_FS2_ABORT_UNKNOWN; switch(stat_type)
{
case RULE_STAT_ABORT:
tsg_stat_abort_rule_update(rule_type, increase);
break;
case RULE_STAT_SEND:
tsg_stat_send_rule_update(rule_type, increase);
break;
default:
break;
}
} }
int TLD_cancel(struct TLD_handle_t *handle) int TLD_cancel(struct TLD_handle_t *handle)
@@ -907,13 +906,12 @@ int TLD_cancel(struct TLD_handle_t *handle)
if (handle->document != NULL) if (handle->document != NULL)
{ {
long long length=0; long long length=0;
struct tsg_log_instance_t *_instance=get_log_instance();
length=handle->document->GetAllocator().Size(); length=handle->document->GetAllocator().Size();
FS_operate(_instance->fs2_handle, _instance->fs2_field_id[LOG_FS2_FREE_RAPID_SIZE], 0, FS_OP_ADD, length); tsg_stat_log_handle_update(LOG_HANDLE_FREE_SIZE, length);
length=handle->document->GetAllocator().Capacity(); length=handle->document->GetAllocator().Capacity();
FS_operate(_instance->fs2_handle, _instance->fs2_field_id[LOG_FS2_FREE_RAPID_CAPACITY], 0, FS_OP_ADD, length); tsg_stat_log_handle_update(LOG_HANDLE_FREE_CAPACITY, length);
delete handle->document; delete handle->document;
handle->document = NULL; handle->document = NULL;
@@ -921,7 +919,7 @@ int TLD_cancel(struct TLD_handle_t *handle)
delete handle->valueAllocator; delete handle->valueAllocator;
handle->valueAllocator=NULL; handle->valueAllocator=NULL;
FS_operate(_instance->fs2_handle, _instance->fs2_field_id[LOG_FS2_FREE_LOG_HANDLE], 0, FS_OP_ADD, 1); tsg_stat_log_handle_update(LOG_HANDLE_FREE_CNT, 1);
} }
free(handle); free(handle);
@@ -987,9 +985,7 @@ int TLD_append(struct TLD_handle_t *handle, char *key, void *value, TLD_TYPE typ
break; break;
} }
struct tsg_log_instance_t *_instance=get_log_instance(); tsg_stat_log_handle_update(LOG_HANDLE_APPEND_CNT, 1);
FS_operate(_instance->fs2_handle, _instance->fs2_field_id[LOG_FS2_APPEND_LOG_HANDLE], 0, FS_OP_ADD, 1);
return 0; return 0;
} }
@@ -1041,16 +1037,14 @@ struct TLD_handle_t *TLD_duplicate(struct TLD_handle_t *handle)
_handle->document->CopyFrom(*handle->document, _handle->document->GetAllocator()); _handle->document->CopyFrom(*handle->document, _handle->document->GetAllocator());
struct tsg_log_instance_t *_instance=get_log_instance(); tsg_stat_log_handle_update(LOG_HANDLE_DUP_CNT, 1);
FS_operate(_instance->fs2_handle, _instance->fs2_field_id[LOG_FS2_DUP_LOG_HANDLE], 0, FS_OP_ADD, 1);
return _handle; return _handle;
} }
struct TLD_handle_t *TLD_create(int thread_id) struct TLD_handle_t *TLD_create(int thread_id)
{ {
struct tsg_log_instance_t *_instance=get_log_instance(); if(g_tsg_log_instance->mode==CLOSE)
if(_instance->mode==CLOSE)
{ {
return NULL; return NULL;
} }
@@ -1062,7 +1056,7 @@ struct TLD_handle_t *TLD_create(int thread_id)
_handle->document = new Document(_handle->valueAllocator); _handle->document = new Document(_handle->valueAllocator);
_handle->document->SetObject(); _handle->document->SetObject();
FS_operate(_instance->fs2_handle, _instance->fs2_field_id[LOG_FS2_CREATE_LOG_HANDLE], 0, FS_OP_ADD, 1);
return _handle; return _handle;
} }
@@ -1246,6 +1240,8 @@ int set_sce_profile_ids(struct tsg_log_instance_t *_instance, struct TLD_handle_
TLD_append(_handle, _instance->id2field[LOG_COMMON_SCE_PROFILE_IDS].name, (void *) &sce_profile_ids_array, TLD_TYPE_OBJECT); TLD_append(_handle, _instance->id2field[LOG_COMMON_SCE_PROFILE_IDS].name, (void *) &sce_profile_ids_array, TLD_TYPE_OBJECT);
fs3_rule_stat_update(RULE_STAT_SEND, TSG_ACTION_S_CHAINING, sce->n_profile_ids);
return 0; return 0;
} }
@@ -1277,7 +1273,7 @@ int set_shaping_profile_ids(struct tsg_log_instance_t *_instance, struct TLD_han
TLD_append(_handle, _instance->id2field[LOG_COMMON_SHAPING_PROFILE_IDS].name, &shaping_array, TLD_TYPE_OBJECT); TLD_append(_handle, _instance->id2field[LOG_COMMON_SHAPING_PROFILE_IDS].name, &shaping_array, TLD_TYPE_OBJECT);
//add_object_member(_handle, &shaping_object, _instance->id2field[LOG_COMMON_SHAPING_PROFILE_IDS].name, shaping_array); fs3_rule_stat_update(RULE_STAT_SEND, TSG_ACTION_SHAPING, shaping->n_shaper_rule);
return 0; return 0;
} }
@@ -1844,7 +1840,7 @@ int log_common_fields_new(const char *filename, id2field_t *id2field, struct top
return 0; return 0;
} }
struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile, screen_stat_handle_t fs2_handle) struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile)
{ {
char override_sled_ip[32]={0}; char override_sled_ip[32]={0};
char kafka_errstr[1024]={0}; char kafka_errstr[1024]={0};
@@ -1854,23 +1850,8 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile, screen_stat_ha
struct tsg_log_instance_t *_instance=NULL; struct tsg_log_instance_t *_instance=NULL;
char common_field_file[128]={0}; char common_field_file[128]={0};
char log_path[128]={0}; char log_path[128]={0};
_instance=(struct tsg_log_instance_t *)calloc(1, sizeof(struct tsg_log_instance_t)); _instance=(struct tsg_log_instance_t *)calloc(1, sizeof(struct tsg_log_instance_t));
_instance->fs2_handle=fs2_handle;
for(int i=0; i<LOG_FS2_TYPE_MAX; i++)
{
_instance->fs2_field_id[i]=FS_register(_instance->fs2_handle, FS_STYLE_FIELD, FS_CALC_SPEED, g_log_fs2_field[i].name);
}
_instance->fs2_column_id[LOG_COLUMN_STATUS_SUCCESS]=FS_register(_instance->fs2_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, "T_success_log");
_instance->fs2_column_id[LOG_COLUMN_STATUS_FAIL]=FS_register(_instance->fs2_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, "T_fail_log");
_instance->fs2_column_id[LOG_COLUMN_STATUS_DROP]=FS_register(_instance->fs2_handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, "T_drop_log");
_instance->fs2_column_id[LOG_COLUMN_STATUS_SUCCESS_S]=FS_register(_instance->fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, "success_log/s");
_instance->fs2_column_id[LOG_COLUMN_STATUS_FAIL_S]=FS_register(_instance->fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, "fail_log/s");
_instance->fs2_column_id[LOG_COLUMN_STATUS_DROP_S]=FS_register(_instance->fs2_handle, FS_STYLE_COLUMN, FS_CALC_SPEED, "drop_log/s");
_instance->sum_line_id=FS_register(_instance->fs2_handle, FS_STYLE_LINE, FS_CALC_SPEED, "SUM");
MESA_load_profile_int_def(conffile, "TSG_LOG", "LOG_LEVEL",&(_instance->level), 30); MESA_load_profile_int_def(conffile, "TSG_LOG", "LOG_LEVEL",&(_instance->level), 30);
MESA_load_profile_string_def(conffile, "TSG_LOG", "LOG_PATH", log_path, sizeof(log_path), "./log/tsglog"); MESA_load_profile_string_def(conffile, "TSG_LOG", "LOG_PATH", log_path, sizeof(log_path), "./log/tsglog");
@@ -1895,6 +1876,8 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile, screen_stat_ha
if(_instance->logger==NULL) if(_instance->logger==NULL)
{ {
printf("MESA_create_runtime_log_handle failed ..., path: %s level: %d", log_path, _instance->level); printf("MESA_create_runtime_log_handle failed ..., path: %s level: %d", log_path, _instance->level);
free(_instance);
_instance=NULL;
return NULL; return NULL;
} }
@@ -1981,6 +1964,7 @@ struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile, screen_stat_ha
if(_instance->service2topic!=NULL) if(_instance->service2topic!=NULL)
{ {
_instance->sum_stat_row_id=tsg_stat_sendlog_row_init("sum");
for(int i=0; i<_instance->max_service; i++) for(int i=0; i<_instance->max_service; i++)
{ {
if(_instance->service2topic[i].type==TLD_TYPE_MAX && strlen(_instance->service2topic[i].name)>0) if(_instance->service2topic[i].type==TLD_TYPE_MAX && strlen(_instance->service2topic[i].name)>0)
@@ -2048,7 +2032,7 @@ void tsg_sendlog_destroy(struct tsg_log_instance_t * instance)
int send_log_by_type(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream, LOG_TYPE log_type, int thread_id) int send_log_by_type(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream, LOG_TYPE log_type, int thread_id)
{ {
int ret=update_percent(_instance, log_type, LOG_COLUMN_STATUS_DROP, thread_id); int ret=update_percent(_instance, log_type, LOG_STATUS_DROP, thread_id);
if(ret==1) if(ret==1)
{ {
MESA_handle_runtime_log(_instance->logger, RLOG_LV_DEBUG, MESA_handle_runtime_log(_instance->logger, RLOG_LV_DEBUG,
@@ -2071,7 +2055,7 @@ int send_log_by_type(struct tsg_log_instance_t *_instance, struct TLD_handle_t *
int send_event_log(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream, LOG_TYPE log_type, struct maat_rule *rules, size_t n_rules, int thread_id) int send_event_log(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_handle, const struct streaminfo *a_stream, LOG_TYPE log_type, struct maat_rule *rules, size_t n_rules, int thread_id)
{ {
int fs_id=0,repeat_cnt=0; int repeat_cnt=0;
int policy_id[MAX_RESULT_NUM]={0}; int policy_id[MAX_RESULT_NUM]={0};
for(size_t i=0;i<n_rules; i++) for(size_t i=0;i<n_rules; i++)
@@ -2104,8 +2088,7 @@ int send_event_log(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_h
(a_stream==NULL ? "" : PRINTADDR(a_stream,_instance->level)) (a_stream==NULL ? "" : PRINTADDR(a_stream,_instance->level))
); );
fs_id=action2fs_id((int)rules[i].action); fs3_rule_stat_update(RULE_STAT_ABORT, (int)rules[i].action, 1);
FS_operate(_instance->fs2_handle, _instance->fs2_field_id[fs_id], 0, FS_OP_ADD, 1);
continue; continue;
break; break;
case LOG_ALL: case LOG_ALL:
@@ -2143,6 +2126,8 @@ int send_event_log(struct tsg_log_instance_t *_instance, struct TLD_handle_t *_h
TLD_delete(_handle, _instance->id2field[LOG_COMMON_ACTION].name); TLD_delete(_handle, _instance->id2field[LOG_COMMON_ACTION].name);
TLD_delete(_handle, _instance->id2field[LOG_COMMON_USER_REGION].name); TLD_delete(_handle, _instance->id2field[LOG_COMMON_USER_REGION].name);
TLD_delete(_handle, _instance->id2field[LOG_COMMON_VSYSTEM_ID].name); TLD_delete(_handle, _instance->id2field[LOG_COMMON_VSYSTEM_ID].name);
fs3_rule_stat_update(RULE_STAT_SEND, (int)rules[i].action, 1);
} }
return 0; return 0;
@@ -2186,7 +2171,8 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl
if(_instance->mode==CLOSE) if(_instance->mode==CLOSE)
{ {
TLD_cancel(handle); TLD_cancel(handle);
FS_operate(_instance->fs2_handle, _instance->sum_line_id, _instance->fs2_field_id[LOG_COLUMN_STATUS_DROP], FS_OP_ADD, 1); tsg_stat_sendlog_update(_instance->sum_stat_row_id, LOG_STATUS_DROP, 1);
tsg_stat_sendlog_update(_instance->sum_stat_row_id, LOG_STATUS_DROP_S, 1);
MESA_handle_runtime_log(_instance->logger, RLOG_LV_INFO, "tsg_send_log", "Disable tsg_send_log."); MESA_handle_runtime_log(_instance->logger, RLOG_LV_INFO, "tsg_send_log", "Disable tsg_send_log.");
return 0; return 0;
} }
@@ -2194,6 +2180,7 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl
if(is_hitted_shunt(a_stream)) if(is_hitted_shunt(a_stream))
{ {
TLD_cancel(handle); TLD_cancel(handle);
fs3_rule_stat_update(RULE_STAT_ABORT, TSG_ACTION_SHUNT, 1);
return 0; return 0;
} }
@@ -2300,7 +2287,7 @@ int tsg_send_payload(struct tsg_log_instance_t *instance, int topic_id, char *pa
status=rd_kafka_produce(_instance->service2topic[topic_id].topic_rkt, RD_KAFKA_PARTITION_UA, RD_KAFKA_MSG_F_COPY, payload, payload_len, NULL, 0, NULL); status=rd_kafka_produce(_instance->service2topic[topic_id].topic_rkt, RD_KAFKA_PARTITION_UA, RD_KAFKA_MSG_F_COPY, payload, payload_len, NULL, 0, NULL);
if(status<0) if(status<0)
{ {
update_percent(_instance, topic_id, LOG_COLUMN_STATUS_FAIL, thread_id); update_percent(_instance, topic_id, LOG_STATUS_FAIL, thread_id);
MESA_handle_runtime_log(_instance->logger, MESA_handle_runtime_log(_instance->logger,
RLOG_LV_INFO, RLOG_LV_INFO,
@@ -2317,7 +2304,7 @@ int tsg_send_payload(struct tsg_log_instance_t *instance, int topic_id, char *pa
} }
else else
{ {
update_percent(_instance, topic_id, LOG_COLUMN_STATUS_SUCCESS, thread_id); update_percent(_instance, topic_id, LOG_STATUS_SUCCESS, thread_id);
MESA_handle_runtime_log(_instance->logger, MESA_handle_runtime_log(_instance->logger,
RLOG_LV_DEBUG, RLOG_LV_DEBUG,
"tsg_send_log", "tsg_send_log",
@@ -2327,7 +2314,7 @@ int tsg_send_payload(struct tsg_log_instance_t *instance, int topic_id, char *pa
); );
} }
update_percent(_instance, topic_id, LOG_COLUMN_STATUS_MAX, thread_id); update_percent(_instance, topic_id, LOG_STATUS_MAX, thread_id);
return 0; return 0;
} }

View File

@@ -152,32 +152,6 @@ enum LOG_FIELD_ID
LOG_COMMON_MAX LOG_COMMON_MAX
}; };
enum LOG_COLUMN_STATUS
{
LOG_COLUMN_STATUS_SUCCESS=0,
LOG_COLUMN_STATUS_SUCCESS_S,
LOG_COLUMN_STATUS_FAIL,
LOG_COLUMN_STATUS_FAIL_S,
LOG_COLUMN_STATUS_DROP,
LOG_COLUMN_STATUS_DROP_S,
LOG_COLUMN_STATUS_MAX
};
enum LOG_FS2_TYPE{
LOG_FS2_ABORT_ALLOW,
LOG_FS2_ABORT_DENY,
LOG_FS2_ABORT_MONITOR,
LOG_FS2_ABORT_INTERCEPT,
LOG_FS2_ABORT_UNKNOWN,
LOG_FS2_CREATE_LOG_HANDLE,
LOG_FS2_DUP_LOG_HANDLE,
LOG_FS2_APPEND_LOG_HANDLE,
LOG_FS2_FREE_LOG_HANDLE,
LOG_FS2_FREE_RAPID_SIZE,
LOG_FS2_FREE_RAPID_CAPACITY,
LOG_FS2_TYPE_MAX
};
typedef struct _id2field typedef struct _id2field
{ {
int type; int type;
@@ -189,7 +163,7 @@ struct topic_stat
{ {
int status; int status;
int type; int type;
int fs2_line_id; int row_idx;
int *send_log_percent; int *send_log_percent;
char name[MAX_STRING_LEN32]; char name[MAX_STRING_LEN32];
long long *drop_start; long long *drop_start;
@@ -218,9 +192,7 @@ struct tsg_log_instance_t
int rapidjson_chunk_capacity; int rapidjson_chunk_capacity;
int tcp_flow_project_id; int tcp_flow_project_id;
int udp_flow_project_id; int udp_flow_project_id;
int sum_line_id; int sum_stat_row_id;
int fs2_column_id[LOG_COLUMN_STATUS_MAX];
int fs2_field_id[LOG_FS2_TYPE_MAX];
char tcp_label[MAX_STRING_LEN32]; char tcp_label[MAX_STRING_LEN32];
char udp_label[MAX_STRING_LEN32]; char udp_label[MAX_STRING_LEN32];
char sasl_username[MAX_STRING_LEN32]; char sasl_username[MAX_STRING_LEN32];
@@ -232,12 +204,11 @@ struct tsg_log_instance_t
id2field_t id2field[LOG_COMMON_MAX]; id2field_t id2field[LOG_COMMON_MAX];
rd_kafka_t *kafka_handle; rd_kafka_t *kafka_handle;
struct topic_stat *service2topic; struct topic_stat *service2topic;
screen_stat_handle_t fs2_handle;
void *logger; void *logger;
}; };
int tsg_unknown_app_id_get(struct tsg_log_instance_t *instance); int tsg_unknown_app_id_get(struct tsg_log_instance_t *instance);
char *log_field_id2name(struct tsg_log_instance_t *instance, enum LOG_FIELD_ID id); char *log_field_id2name(struct tsg_log_instance_t *instance, enum LOG_FIELD_ID id);
struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile, screen_stat_handle_t fs2_handle); struct tsg_log_instance_t *tsg_sendlog_init(const char *conffile);
void tsg_sendlog_destroy(struct tsg_log_instance_t * instance); void tsg_sendlog_destroy(struct tsg_log_instance_t * instance);

294
src/tsg_stat.cpp Normal file
View File

@@ -0,0 +1,294 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "tsg_stat.h"
#include <MESA/fieldstat.h>
#include <MESA/MESA_prof_load.h>
struct fs3_rule_stat
{
int table_id;
int abort_column_id[RULE_TYPE_MAX];
int send_column_id[RULE_TYPE_MAX];
};
struct fs3_tld_stat
{
int table_id;
int column_id[LOG_HANDLE_MAX];
};
struct fs3_sendlog_stat
{
int table_id;
int max_row_idx;
int (*column_id)[LOG_STATUS_MAX];
};
struct fs3_sync_ctrl_stat
{
int table_id;
int success_column_id[CTRL_SYNC_MAX];
int fail_column_id[CTRL_SYNC_MAX];
};
struct ctrl_service_status
{
int activing_column_id[CTRL_SERVICE_MAX];
int updating_column_id[CTRL_SERVICE_MAX];
};
struct fs3_sync_ctrl_service
{
int table_id;
struct ctrl_service_status fail;
struct ctrl_service_status success;
};
struct fs3_sync_application
{
int table_id;
int column_id[SYNC_APP_MAX];
};
struct fs3_sync_exdata
{
int table_id;
int add_column_id[SYNC_EXDATA_MAX];
int del_column_id[SYNC_EXDATA_MAX];
};
struct fs3_flow
{
int table_id;
int fail_column_id[FLOW_STAT_MAX];
int success_column_id[FLOW_STAT_MAX];
};
struct runtime_stat_para
{
struct fieldstat_tag tags;
struct fs3_flow flow;
struct fs3_tld_stat tld;
struct fs3_rule_stat rule;
struct fs3_sync_exdata exdata;
struct fs3_sendlog_stat sendlog;
struct fs3_sync_application app;
struct fs3_sync_ctrl_stat ctrl_sync;
struct fs3_sync_ctrl_service ctrl_service;
struct fieldstat_instance *fs_instance;
};
struct runtime_stat_para g_rt_stat_para={0};
static void stat_update(int column_id, long long increase)
{
fieldstat_value_incrby(g_rt_stat_para.fs_instance, column_id, increase);
}
void tsg_stat_abort_rule_update(enum RULE_TYPE column_idx, long long increase)
{
stat_update(g_rt_stat_para.rule.abort_column_id[column_idx], increase);
}
void tsg_stat_send_rule_update(enum RULE_TYPE column_idx, long long increase)
{
stat_update(g_rt_stat_para.rule.send_column_id[column_idx], increase);
}
void tsg_stat_sendlog_update(int row_idx, enum LOG_STATUS column_idx, long long increase)
{
stat_update(g_rt_stat_para.sendlog.column_id[row_idx][column_idx], increase);
}
void tsg_stat_log_handle_update(enum LOG_HANDLE column_idx, long long increase)
{
stat_update(g_rt_stat_para.tld.column_id[column_idx], increase);
}
void tsg_stat_flow_update(enum STAT_STATUS status, enum FLOW_STAT column_idx, long long increase)
{
switch(status)
{
case STAT_STATUS_FAIL:
stat_update(g_rt_stat_para.flow.fail_column_id[column_idx], increase);
break;
case STAT_STATUS_SUCCESS:
stat_update(g_rt_stat_para.flow.success_column_id[column_idx], increase);
break;
default:
break;
}
}
void tsg_stat_sync_ctrl_update(enum STAT_STATUS status, enum CTRL_SYNC column_idx, long long increase)
{
switch(status)
{
case STAT_STATUS_FAIL:
stat_update(g_rt_stat_para.ctrl_sync.fail_column_id[column_idx], increase);
break;
case STAT_STATUS_SUCCESS:
stat_update(g_rt_stat_para.ctrl_sync.success_column_id[column_idx], increase);
break;
default:
break;
}
}
void tsg_stat_sync_exdata_add_update(enum SYNC_EXDATA column_idx, long long increase)
{
stat_update(g_rt_stat_para.exdata.add_column_id[column_idx], increase);
}
void tsg_stat_sync_exdata_del_update(enum SYNC_EXDATA column_idx, long long increase)
{
stat_update(g_rt_stat_para.exdata.del_column_id[column_idx], increase);
}
void tsg_stat_sync_application_update(enum SYNC_APP column_idx, long long increase)
{
stat_update(g_rt_stat_para.app.column_id[column_idx], increase);
}
void tsg_stat_ctrl_service_activing_update(enum STAT_STATUS status, enum CTRL_SERVICE column_idx, long long increase)
{
switch(status)
{
case STAT_STATUS_FAIL:
stat_update(g_rt_stat_para.ctrl_service.fail.activing_column_id[column_idx], increase);
break;
case STAT_STATUS_SUCCESS:
stat_update(g_rt_stat_para.ctrl_service.success.activing_column_id[column_idx], increase);
break;
default:
break;
}
}
void tsg_stat_ctrl_service_updating_update(enum STAT_STATUS status, enum CTRL_SERVICE column_idx, long long increase)
{
switch(status)
{
case STAT_STATUS_FAIL:
stat_update(g_rt_stat_para.ctrl_service.fail.updating_column_id[column_idx], increase);
break;
case STAT_STATUS_SUCCESS:
stat_update(g_rt_stat_para.ctrl_service.success.updating_column_id[column_idx], increase);
break;
default:
break;
}
}
int tsg_stat_create(const char *conffile)
{
int cycle=0,vsystem_id=0;
unsigned short fs_server_port=0;
char instance_name[128]={0};
char fs_server_ip[32]={0};
char fs_output_path[128]={0};
MESA_load_profile_int_def(conffile, "FIELD_STAT", "CYCLE", &cycle, 30000);
MESA_load_profile_short_nodef(conffile, "FIELD_STAT","TELEGRAF_PORT", (short *)&(fs_server_port));
MESA_load_profile_string_nodef(conffile,"FIELD_STAT","TELEGRAF_IP",fs_server_ip, sizeof(fs_server_ip));
MESA_load_profile_string_def(conffile,"FIELD_STAT","OUTPUT_PATH",fs_output_path, sizeof(fs_output_path), "master.status");
MESA_load_profile_string_def(conffile,"FIELD_STAT","INSTANCE_NAME", instance_name, sizeof(instance_name), "tsg_master");
MESA_load_profile_int_def(conffile, "TSG_LOG", "VSYSTEM_ID", &vsystem_id, 1);
//memset(&(g_rt_stat_para), 0, sizeof(struct runtime_stat_para));
g_rt_stat_para.fs_instance=fieldstat_instance_new(instance_name);
fieldstat_set_output_interval(g_rt_stat_para.fs_instance, cycle);
fieldstat_enable_prometheus_output(g_rt_stat_para.fs_instance);
fieldstat_set_local_output(g_rt_stat_para.fs_instance, fs_output_path, "default");
if(fs_server_port > 0 && strlen(fs_server_ip) > 0)
{
fieldstat_set_line_protocol_server(g_rt_stat_para.fs_instance, fs_server_ip, fs_server_port);
}
g_rt_stat_para.tags.key="vsys_id";
g_rt_stat_para.tags.value_type=0;
g_rt_stat_para.tags.value_int=vsystem_id;
return 0;
}
int tsg_stat_init(void)
{
enum field_type exdata_column_type[SYNC_EXDATA_MAX]={FIELD_TYPE_COUNTER};
const char *exdata_column_name[SYNC_EXDATA_MAX]={"asn", "gtpc", "location", "fqdn_category", "subscriber", "compile", "mirror", "http_response", "dns_response", "app_id_dict", "tunnel_catalog", "tunnel_endpoint", "tunnel_label"};
g_rt_stat_para.exdata.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "sync_exdata", exdata_column_name, exdata_column_type, SYNC_EXDATA_MAX);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.exdata.table_id, "add", &(g_rt_stat_para.tags), 1, g_rt_stat_para.exdata.add_column_id);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.exdata.table_id, "del", &(g_rt_stat_para.tags), 1, g_rt_stat_para.exdata.del_column_id);
enum field_type flow_column_type[FLOW_STAT_MAX]={FIELD_TYPE_COUNTER};
const char *flow_column_name[FLOW_STAT_MAX]={"inject", "mirror_pkts", "mirror_bytes", "set_timeout", "tamper"};
g_rt_stat_para.flow.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "flow", flow_column_name, flow_column_type, FLOW_STAT_MAX);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.flow.table_id, "success", &(g_rt_stat_para.tags), 1, g_rt_stat_para.flow.success_column_id);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.flow.table_id, "fail", &(g_rt_stat_para.tags), 1, g_rt_stat_para.flow.fail_column_id);
enum field_type app_sync_column_type[SYNC_APP_MAX]={FIELD_TYPE_COUNTER};
const char *app_sync_column_name[SYNC_APP_MAX]={"lpi", "dpkt", "thrid", "user_define", "built_in"};
g_rt_stat_para.app.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "sync_application", app_sync_column_name, app_sync_column_type, SYNC_APP_MAX);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.app.table_id, "sum", &(g_rt_stat_para.tags), 1, g_rt_stat_para.app.column_id);
enum field_type ctrl_sync_column_type[CTRL_SYNC_MAX]={FIELD_TYPE_COUNTER};
const char *ctrl_sync_column_name[CTRL_SYNC_MAX]={"unknown", "rstall", "opening", "activing", "updating", "closing"};
g_rt_stat_para.ctrl_sync.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "ctrl_stat", ctrl_sync_column_name, ctrl_sync_column_type, CTRL_SYNC_MAX);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.ctrl_sync.table_id, "success", &(g_rt_stat_para.tags), 1, g_rt_stat_para.ctrl_sync.success_column_id);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.ctrl_sync.table_id, "fail", &(g_rt_stat_para.tags), 1, g_rt_stat_para.ctrl_sync.fail_column_id);
enum field_type ctrl_service_column_type[CTRL_SERVICE_MAX]={FIELD_TYPE_COUNTER};
const char *ctrl_service_column_name[CTRL_SERVICE_MAX]={"unknown", "sce", "shaping", "intercept"};
g_rt_stat_para.ctrl_service.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "ctrl_service", ctrl_service_column_name, ctrl_service_column_type, CTRL_SERVICE_MAX);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.ctrl_service.table_id, "activing_success", &(g_rt_stat_para.tags), 1, g_rt_stat_para.ctrl_service.success.activing_column_id);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.ctrl_service.table_id, "activing_fail", &(g_rt_stat_para.tags), 1, g_rt_stat_para.ctrl_service.fail.activing_column_id);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.ctrl_service.table_id, "updating_success", &(g_rt_stat_para.tags), 1, g_rt_stat_para.ctrl_service.success.updating_column_id);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.ctrl_service.table_id, "updating_fail", &(g_rt_stat_para.tags), 1, g_rt_stat_para.ctrl_service.fail.updating_column_id);
enum field_type rule_column_type[RULE_TYPE_MAX]={FIELD_TYPE_COUNTER};
const char *rule_column_name[RULE_TYPE_MAX]={"unknown", "shunt", "allow", "deny", "shaping", "intercept", "no_intercept", "service_chaining", "monitor"};
g_rt_stat_para.rule.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "matched_rule", rule_column_name, rule_column_type, RULE_TYPE_MAX);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.rule.table_id, "abort", &(g_rt_stat_para.tags), 1, g_rt_stat_para.rule.abort_column_id);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.rule.table_id, "send", &(g_rt_stat_para.tags), 1, g_rt_stat_para.rule.send_column_id);
enum field_type handle_column_type[LOG_HANDLE_MAX]={FIELD_TYPE_COUNTER};
const char *handle_column_name[LOG_HANDLE_MAX]={"create", "dup", "append", "free_cnt", "free_size", "free_capacity"};
g_rt_stat_para.tld.table_id=fieldstat_register_table(g_rt_stat_para.fs_instance, "tld_handle", handle_column_name, handle_column_type, LOG_HANDLE_MAX);
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.tld.table_id, "handle", &(g_rt_stat_para.tags), 1, g_rt_stat_para.tld.column_id);
enum field_type sendlog_column_type[LOG_STATUS_MAX]={FIELD_TYPE_COUNTER};
const char *sendlog_column_name[LOG_STATUS_MAX]={"T_success_log", "T_fail_log", "T_drop_log", "success_log/s", "fail_log/s", "drop_log/s"};
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);
return 0;
}
int tsg_stat_sendlog_row_init(const char *row_name)
{
int row_idx=g_rt_stat_para.sendlog.max_row_idx;
if(row_idx==0)
{
g_rt_stat_para.sendlog.column_id=(int (*)[LOG_STATUS_MAX])calloc(row_idx+1, sizeof(int[LOG_STATUS_MAX]));
}
else
{
g_rt_stat_para.sendlog.column_id=(int (*)[LOG_STATUS_MAX])realloc(g_rt_stat_para.sendlog.column_id, (row_idx+1)*sizeof(int[LOG_STATUS_MAX]));
}
fieldstat_register_table_row(g_rt_stat_para.fs_instance, g_rt_stat_para.sendlog.table_id, row_name, &(g_rt_stat_para.tags), 1, g_rt_stat_para.sendlog.column_id[row_idx]);
g_rt_stat_para.sendlog.max_row_idx++;
return row_idx;
}
void tsg_stat_start(void)
{
fieldstat_instance_start(g_rt_stat_para.fs_instance);
}

130
src/tsg_stat.h Normal file
View File

@@ -0,0 +1,130 @@
#pragma once
enum STAT_STATUS
{
STAT_STATUS_SUCCESS=0,
STAT_STATUS_FAIL
};
//table: inject, mirror, set_timeout, tamper
enum FLOW_STAT
{
FLOW_STAT_INJECT=0,
FLOW_STAT_MIRROR_PKT,
FLOW_STAT_MIRROR_BYTE,
FLOW_STAT_SET_TIMEOUT,
FLOW_STAT_TAMPER,
FLOW_STAT_MAX
};
//table: LPI, DPKT, THRID, USER_DEFINE, BUILT_IN
enum SYNC_APP
{
SYNC_APP_LPI=0,
SYNC_APP_DPKT,
SYNC_APP_THRID,
SYNC_APP_USER_DEFINE,
SYNC_APP_BUILT_IN,
SYNC_APP_MAX
};
//table: asn, gtpc, location, fqdn_category, subscriber, compile, mirror, http_response, dns_response, app_id_dict, tunnel_catalog, tunnel_endpoint, tunnel_label
enum SYNC_EXDATA
{
SYNC_EXDATA_ASN=0,
SYNC_EXDATA_GTPC,
SYNC_EXDATA_LOCATION,
SYNC_EXDATA_FQDN_CATEGORY,
SYNC_EXDATA_SUBSCRIBER,
SYNC_EXDATA_COMPILE,
SYNC_EXDATA_MIRRORED,
SYNC_EXDATA_HTTP_RESPONSE,
SYNC_EXDATA_DNS_RESPONSE,
SYNC_EXDATA_APP_ID_DICT,
SYNC_EXDATA_TUNNEL_CATALOG,
SYNC_EXDATA_TUNNEL_ENDPOINT,
SYNC_EXDATA_TUNNEL_LABEL,
SYNC_EXDATA_MAX
};
//table: success, success/s, fail, fail/s, drop, drop/s
enum LOG_STATUS
{
LOG_STATUS_SUCCESS=0,
LOG_STATUS_SUCCESS_S,
LOG_STATUS_FAIL,
LOG_STATUS_FAIL_S,
LOG_STATUS_DROP,
LOG_STATUS_DROP_S,
LOG_STATUS_MAX
};
//table: create, duplication, append, free_count, free_size, free_capacity
enum LOG_HANDLE
{
LOG_HANDLE_CREATE_CNT,
LOG_HANDLE_DUP_CNT,
LOG_HANDLE_APPEND_CNT,
LOG_HANDLE_FREE_CNT,
LOG_HANDLE_FREE_SIZE,
LOG_HANDLE_FREE_CAPACITY,
LOG_HANDLE_MAX
};
//table: unknown, shunt, allow, deny, shaping, intercept, no_intercept, service_chaining, monitor
enum RULE_TYPE
{
RULE_TYPE_UNKNOW=0,
RULE_TYPE_SHUNT,
RULE_TYPE_ALLOW,
RULE_TYPE_DENY,
RULE_TYPE_SHAPING,
RULE_TYPE_INTERCEPT,
RULE_TYPE_NO_INTERCEPT,
RULE_TYPE_SERVICE_CHAINING,
RULE_TYPE_MONITOR,
RULE_TYPE_MAX
};
//table: unknown, rstall, opening, activing, log_update, closing
enum CTRL_SYNC
{
CTRL_SYNC_UNKNOWN=0,
CTRL_SYNC_RSTALL,
CTRL_SYNC_OPENING,
CTRL_SYNC_ACTIVING,
CTRL_SYNC_LOG_UPDATE,
CTRL_SYNC_CLOSING,
CTRL_SYNC_MAX
};
//table: activing, updating
enum CTRL_SERVICE
{
CTRL_SERVICE_UNKNOWN=0,
CTRL_SERVICE_CHAINING,
CTRL_SERVICE_SHAPING,
CTRL_SERVICE_INTERCEPT,
CTRL_SERVICE_MAX
};
int tsg_stat_create(const char *conffile);
int tsg_stat_init(void);
int tsg_stat_sendlog_row_init(const char *row_name);
void tsg_stat_start(void);
// return row index
void tsg_stat_abort_rule_update(enum RULE_TYPE column_idx, long long increase);
void tsg_stat_send_rule_update(enum RULE_TYPE column_idx, long long increase);
void tsg_stat_log_handle_update(enum LOG_HANDLE column_idx, long long increase);
void tsg_stat_sync_exdata_add_update(enum SYNC_EXDATA column_idx, long long increase);
void tsg_stat_sync_exdata_del_update(enum SYNC_EXDATA column_idx, long long increase);
void tsg_stat_sync_application_update(enum SYNC_APP 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);
void tsg_stat_ctrl_service_activing_update(enum STAT_STATUS status, enum CTRL_SERVICE column_idx, long long increase);
void tsg_stat_ctrl_service_updating_update(enum STAT_STATUS status, enum CTRL_SERVICE column_idx, long long increase);

View File

@@ -4,6 +4,7 @@
#include <MESA/cJSON.h> #include <MESA/cJSON.h>
#include <MESA/MESA_handle_logger.h> #include <MESA/MESA_handle_logger.h>
#include "tsg_stat.h"
#include "tsg_variable.h" #include "tsg_variable.h"
#include "tsg_sync_state.h" #include "tsg_sync_state.h"
#include "tsg_send_log.h" #include "tsg_send_log.h"
@@ -43,13 +44,8 @@ static int mpack_send_pkt(const struct streaminfo *a_stream, mpack_writer_t *wri
ret = sapp_inject_ctrl_pkt((struct streaminfo *)a_stream, SIO_DEFAULT, *mpack_data, *mpack_size, a_stream->routedir); ret = sapp_inject_ctrl_pkt((struct streaminfo *)a_stream, SIO_DEFAULT, *mpack_data, *mpack_size, a_stream->routedir);
if (ret == -1) if (ret == -1)
{ {
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_INJECT_CTRL_FAILED], 0, FS_OP_ADD, 1);
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_DEBUG, "MSGPACK_BUFF_SEND", "An error occurred injecting the data! addr: %s", PRINTADDR(a_stream, g_tsg_para.level)); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_DEBUG, "MSGPACK_BUFF_SEND", "An error occurred injecting the data! addr: %s", PRINTADDR(a_stream, g_tsg_para.level));
} }
else
{
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_INJECT_CTRL_SUCCESS], 0, FS_OP_ADD, 1);
}
free(*mpack_data); free(*mpack_data);
*mpack_data = NULL; *mpack_data = NULL;
@@ -85,8 +81,9 @@ int tsg_send_session_state(const struct streaminfo *a_stream, unsigned char stat
int tsg_sync_resetall_state(const struct streaminfo *a_stream) int tsg_sync_resetall_state(const struct streaminfo *a_stream)
{ {
if (a_stream == NULL) if(a_stream==NULL)
{ {
tsg_stat_sync_ctrl_update(STAT_STATUS_FAIL, CTRL_SYNC_RSTALL, 1);
return -1; return -1;
} }
@@ -95,7 +92,17 @@ int tsg_sync_resetall_state(const struct streaminfo *a_stream)
mpack_writer_t writer; mpack_writer_t writer;
mpack_init_map(a_stream, &writer, "resetall", &mpack_data, &mpack_size); mpack_init_map(a_stream, &writer, "resetall", &mpack_data, &mpack_size);
return mpack_send_pkt(a_stream, &writer, &mpack_data, &mpack_size); int ret=mpack_send_pkt(a_stream, &writer, &mpack_data, &mpack_size);
if(ret==-1)
{
tsg_stat_sync_ctrl_update(STAT_STATUS_FAIL, CTRL_SYNC_RSTALL, 1);
}
else
{
tsg_stat_sync_ctrl_update(STAT_STATUS_SUCCESS, CTRL_SYNC_RSTALL, 1);
}
return 0;
} }
static void mpack_append_string(mpack_writer_t *writer, char *str) static void mpack_append_string(mpack_writer_t *writer, char *str)
@@ -282,6 +289,7 @@ int tsg_sync_policy_update(const struct streaminfo *a_stream, struct update_poli
{ {
if (a_stream == NULL || policy_update == NULL || policy_update->type >= POLICY_UPDATE_MAX || n_policy_update == 0) if (a_stream == NULL || policy_update == NULL || policy_update->type >= POLICY_UPDATE_MAX || n_policy_update == 0)
{ {
tsg_stat_sync_ctrl_update(STAT_STATUS_FAIL, CTRL_SYNC_UNKNOWN, 1);
return -1; return -1;
} }
@@ -301,21 +309,70 @@ int tsg_sync_policy_update(const struct streaminfo *a_stream, struct update_poli
{ {
mpack_append_update_policy(&writer, &policy_update[i], policy_update[i].type); mpack_append_update_policy(&writer, &policy_update[i], policy_update[i].type);
} }
mpack_complete_map(&writer); // params mpack_complete_map(&writer); // params
return mpack_send_pkt(a_stream, &writer, &mpack_data, &mpack_size); enum STAT_STATUS status;
int ret=mpack_send_pkt(a_stream, &writer, &mpack_data, &mpack_size);
if(ret==-1)
{
status=STAT_STATUS_FAIL;
}
else
{
status=STAT_STATUS_SUCCESS;
}
tsg_stat_sync_ctrl_update(status, CTRL_SYNC_ACTIVING, 1);
switch(policy_update[0].type)
{
case POLICY_UPDATE_SHAPING:
tsg_stat_ctrl_service_activing_update(status, CTRL_SERVICE_SHAPING, 1);
break;
case POLICY_UPDATE_INTERCEPT:
tsg_stat_ctrl_service_activing_update(status, CTRL_SERVICE_INTERCEPT, 1);
break;
case POLICY_UPDATE_SERVICE_CHAINING:
tsg_stat_ctrl_service_activing_update(status, CTRL_SERVICE_CHAINING, 1);
break;
default:
tsg_stat_ctrl_service_activing_update(status, CTRL_SERVICE_UNKNOWN, 1);
break;
}
return ret;
} }
int tsg_sync_closing_state(const struct streaminfo *a_stream, unsigned char state) int tsg_sync_closing_state(const struct streaminfo *a_stream, unsigned char state)
{ {
return tsg_send_session_state(a_stream, state); int ret=tsg_send_session_state(a_stream, state);
if(ret==-1)
{
tsg_stat_sync_ctrl_update(STAT_STATUS_FAIL, CTRL_SYNC_CLOSING, 1);
}
else
{
tsg_stat_sync_ctrl_update(STAT_STATUS_SUCCESS, CTRL_SYNC_CLOSING, 1);
}
return ret;
} }
int tsg_sync_opening_state(const struct streaminfo *a_stream, unsigned char state) int tsg_sync_opening_state(const struct streaminfo *a_stream, unsigned char state)
{ {
tsg_send_session_state(a_stream, state); int ret=tsg_send_session_state(a_stream, state);
if(ret==-1)
{
tsg_stat_sync_ctrl_update(STAT_STATUS_FAIL, CTRL_SYNC_OPENING, 1);
}
else
{
tsg_stat_sync_ctrl_update(STAT_STATUS_SUCCESS, CTRL_SYNC_OPENING, 1);
}
return 0; return ret;
} }
static char *mpack_parse_get_string(mpack_node_t node, char *p_str, int thread_seq) static char *mpack_parse_get_string(mpack_node_t node, char *p_str, int thread_seq)
@@ -466,8 +523,9 @@ int mpack_parse_proxy_intercept_info(const struct streaminfo *a_stream, mpack_tr
int tsg_parse_log_update_payload(const struct streaminfo *a_stream, const void *payload, unsigned int payload_len) int tsg_parse_log_update_payload(const struct streaminfo *a_stream, const void *payload, unsigned int payload_len)
{ {
if (a_stream == NULL || payload == NULL || payload_len == 0) if(a_stream==NULL || payload==NULL || payload_len==0)
{ {
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_UNKNOWN, 1);
return -1; return -1;
} }
@@ -480,6 +538,7 @@ int tsg_parse_log_update_payload(const struct streaminfo *a_stream, const void *
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "mpack_tree_parse error! payload_len = %u", payload_len); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "mpack_tree_parse error! payload_len = %u", payload_len);
mpack_tree_destroy(&tree); mpack_tree_destroy(&tree);
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_UNKNOWN, 1);
return -1; return -1;
} }
@@ -488,6 +547,7 @@ int tsg_parse_log_update_payload(const struct streaminfo *a_stream, const void *
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "method error! mpack_node_type(method) = %d", (int)mpack_node_type(method)); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "method error! mpack_node_type(method) = %d", (int)mpack_node_type(method));
mpack_tree_destroy(&tree); mpack_tree_destroy(&tree);
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_UNKNOWN, 1);
return -1; return -1;
} }
@@ -496,6 +556,7 @@ int tsg_parse_log_update_payload(const struct streaminfo *a_stream, const void *
// mpack_node_str(method) is contiguous memory // mpack_node_str(method) is contiguous memory
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "method error! mpack_node_strlen(method) = %lu", mpack_node_strlen(method)); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "method error! mpack_node_strlen(method) = %lu", mpack_node_strlen(method));
mpack_tree_destroy(&tree); mpack_tree_destroy(&tree);
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_UNKNOWN, 1);
return -1; return -1;
} }
@@ -505,6 +566,7 @@ int tsg_parse_log_update_payload(const struct streaminfo *a_stream, const void *
// if session_id = 0, it's could be mpack_node_type(root) = nil // if session_id = 0, it's could be mpack_node_type(root) = nil
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "session_id error! session_id: %llu, real session_id: %llu", session_id, tsg_get_stream_trace_id(a_stream)); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "session_id error! session_id: %llu, real session_id: %llu", session_id, tsg_get_stream_trace_id(a_stream));
mpack_tree_destroy(&tree); mpack_tree_destroy(&tree);
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_UNKNOWN, 1);
return -1; return -1;
} }
@@ -513,26 +575,59 @@ int tsg_parse_log_update_payload(const struct streaminfo *a_stream, const void *
{ {
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "params_node error!"); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_INFO, "PARSE_LOG_UPDATE", "params_node error!");
mpack_tree_destroy(&tree); mpack_tree_destroy(&tree);
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_UNKNOWN, 1);
return -1; return -1;
} }
mpack_node_t temp_node = mpack_node_map_str_optional(params_node, "sce", 3); mpack_node_t temp_node = mpack_node_map_str_optional(params_node, "sce", 3);
if (mpack_node_type(temp_node) != mpack_type_nil && mpack_node_type(temp_node) != mpack_type_missing) if (mpack_node_type(temp_node) != mpack_type_nil && mpack_node_type(temp_node) != mpack_type_missing)
{ {
return mpack_parse_sce_profile_ids(a_stream, tree, temp_node); int ret=mpack_parse_sce_profile_ids(a_stream, tree, temp_node);
if(ret==-1)
{
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_CHAINING, 1);
}
else
{
tsg_stat_ctrl_service_updating_update(STAT_STATUS_SUCCESS, CTRL_SERVICE_CHAINING, 1);
}
return ret;
} }
temp_node = mpack_node_map_str_optional(params_node, "shaper", 6); temp_node = mpack_node_map_str_optional(params_node, "shaper", 6);
if (mpack_node_type(temp_node) != mpack_type_nil && mpack_node_type(temp_node) != mpack_type_missing) if (mpack_node_type(temp_node) != mpack_type_nil && mpack_node_type(temp_node) != mpack_type_missing)
{ {
return mpack_parse_shaper_profile_ids(a_stream, tree, temp_node); int ret=mpack_parse_shaper_profile_ids(a_stream, tree, temp_node);
if(ret==-1)
{
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_SHAPING, 1);
}
else
{
tsg_stat_ctrl_service_updating_update(STAT_STATUS_SUCCESS, CTRL_SERVICE_SHAPING, 1);
}
return ret;
} }
temp_node = mpack_node_map_str_optional(params_node, "proxy", 5); temp_node = mpack_node_map_str_optional(params_node, "proxy", 5);
if (mpack_node_type(temp_node) != mpack_type_nil && mpack_node_type(temp_node) != mpack_type_missing) if (mpack_node_type(temp_node) != mpack_type_nil && mpack_node_type(temp_node) != mpack_type_missing)
{ {
return mpack_parse_proxy_intercept_info(a_stream, tree, temp_node); int ret=mpack_parse_proxy_intercept_info(a_stream, tree, temp_node);
if(ret==-1)
{
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_INTERCEPT, 1);
} }
else
{
tsg_stat_ctrl_service_updating_update(STAT_STATUS_SUCCESS, CTRL_SERVICE_INTERCEPT, 1);
}
return ret;
}
tsg_stat_ctrl_service_updating_update(STAT_STATUS_FAIL, CTRL_SERVICE_UNKNOWN, 1);
MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_DEBUG, "PDARSE_LOG_UPDATE", "pkt error! there is no log!"); MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_DEBUG, "PDARSE_LOG_UPDATE", "pkt error! there is no log!");
mpack_tree_destroy(&tree); mpack_tree_destroy(&tree);

View File

@@ -141,6 +141,8 @@ struct sce_log_update
uint32_t profile_ids[SCE_PROFILE_IDS]; uint32_t profile_ids[SCE_PROFILE_IDS];
}; };
int tsg_init_sync_status(struct fieldstat_instance *fs3_instance);
int tsg_sync_resetall_state(const struct streaminfo *a_stream); int tsg_sync_resetall_state(const struct streaminfo *a_stream);
int tsg_send_session_state(const struct streaminfo *a_stream, unsigned char state); int tsg_send_session_state(const struct streaminfo *a_stream, unsigned char state);
int tsg_sync_opening_state(const struct streaminfo *a_stream, unsigned char state); int tsg_sync_opening_state(const struct streaminfo *a_stream, unsigned char state);

View File

@@ -4,6 +4,7 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include "tsg_stat.h"
#include "tsg_entry.h" #include "tsg_entry.h"
#include <MESA/MESA_handle_logger.h> #include <MESA/MESA_handle_logger.h>
#include "tsg_protocol_common.h" #include "tsg_protocol_common.h"
@@ -36,14 +37,17 @@ int swap_payload2byte(char *str, int endlen)
{ {
char temp; char temp;
if(endlen<4){ //最少满<E5B091><E6BBA1>?<3F><>?6bit的长度即最<E58DB3><E69C80>?字节<E5AD97><E88A82>? if(endlen<4)
{
return 0; return 0;
} }
//这样交换是别面校验和不对的问<E79A84><E997AE>? for(int i=1; i<endlen; i=i+2)
for(int i=1; i<endlen; i=i+2){ {
for (int j=i+2; j<endlen; j=j+2){ for (int j=i+2; j<endlen; j=j+2)
if(str[i] != str[j]){ {
if(str[i] != str[j])
{
temp = str[i]; temp = str[i];
str[i] = str[j]; str[i] = str[j];
str[j] = temp; str[j] = temp;
@@ -51,6 +55,7 @@ int swap_payload2byte(char *str, int endlen)
} }
} }
} }
return 0; return 0;
} }
@@ -61,7 +66,9 @@ int send_tamper_xxx(const struct streaminfo *a_stream, long *tamper_count, const
char tamper_buf[MTU_LEN] = {0}; char tamper_buf[MTU_LEN] = {0};
int tamper_index = 0; int tamper_index = 0;
if(a_stream==NULL || raw_pkt==NULL){ if(a_stream==NULL || raw_pkt==NULL)
{
tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_TAMPER, 1);
return -1; return -1;
} }
@@ -70,52 +77,29 @@ int send_tamper_xxx(const struct streaminfo *a_stream, long *tamper_count, const
trans_layload_len = a_stream->ptcpdetail->datalen; trans_layload_len = a_stream->ptcpdetail->datalen;
if((p_trans_payload==NULL)||(trans_layload_len<=4)){ if((p_trans_payload==NULL)||(trans_layload_len<=4))
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TAMPER_FAILED_PLOAD_LESS_4], 0, FS_OP_ADD, 1); {
MESA_handle_runtime_log(g_tsg_para.logger, tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_TAMPER, 1);
RLOG_LV_DEBUG,
__FUNCTION__,
"Addr: %s, try send num %ld ptcpdetail->pdata %p, ptcpdetail->datalen %d rawpkt %p , but packet is not tamper because the payload is too short or there is no payload",
PRINTADDR(a_stream, g_tsg_para.level),
*tamper_count,
p_trans_payload,
trans_layload_len,
raw_pkt);
return -1; return -1;
} }
memcpy(tamper_buf, p_trans_payload, trans_layload_len); memcpy(tamper_buf, p_trans_payload, trans_layload_len);
tamper_index = swap_payload2byte(tamper_buf, trans_layload_len); tamper_index=swap_payload2byte(tamper_buf, trans_layload_len);
if(tamper_index > 0 ){ if(tamper_index<=0)
if(0 == tsg_send_inject_packet(a_stream, SIO_DEFAULT, tamper_buf, trans_layload_len, a_stream->routedir)){ {
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_SUCESS_TAMPER], 0, FS_OP_ADD, 1); tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_TAMPER, 1);
MESA_handle_runtime_log(g_tsg_para.logger,
RLOG_LV_DEBUG,
__FUNCTION__,
"Addr: %s, try send num %ld ptcpdetail->pdata %p, ptcpdetail->datalen %d rawpkt %p, modify the index(%d) position of the payload:(old: %02x %02x %02x %02x, new: %02x %02x %02x %02x)",
PRINTADDR(a_stream, g_tsg_para.level),
*tamper_count,
p_trans_payload,
trans_layload_len,
raw_pkt,
tamper_index,
(uint8_t)p_trans_payload[tamper_index-1], (uint8_t)p_trans_payload[tamper_index], (uint8_t)p_trans_payload[tamper_index+1], (uint8_t)p_trans_payload[tamper_index+2],
(uint8_t)tamper_buf[tamper_index-1], (uint8_t)tamper_buf[tamper_index], (uint8_t)tamper_buf[tamper_index+1], (uint8_t)tamper_buf[tamper_index+2]);
return 0;
}
}
FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_TAMPER_FAILED_NOSWAP], 0, FS_OP_ADD, 1);
MESA_handle_runtime_log(g_tsg_para.logger,
RLOG_LV_DEBUG,
__FUNCTION__,
"Addr: %s, try send num %ld ptcpdetail->pdata %p, ptcpdetail->datalen %d rawpkt %p, payload tamper failed because payload data same",
PRINTADDR(a_stream, g_tsg_para.level),
*tamper_count,
p_trans_payload,
trans_layload_len,
raw_pkt);
return -1; return -1;
}
int ret=tsg_send_inject_packet(a_stream, SIO_DEFAULT, tamper_buf, trans_layload_len, a_stream->routedir);
if(ret==-1)
{
tsg_stat_flow_update(STAT_STATUS_FAIL, FLOW_STAT_TAMPER, 1);
}
else
{
tsg_stat_flow_update(STAT_STATUS_SUCCESS, FLOW_STAT_TAMPER, 1);
}
return ret;
} }

View File

@@ -4,71 +4,8 @@
#include "tsg_bridge.h" #include "tsg_bridge.h"
#include <MESA/stream.h> #include <MESA/stream.h>
#include <MESA/field_stat2.h>
#include <ctemplate/template.h> #include <ctemplate/template.h>
enum TSG_FS2_TYPE
{
TSG_FS2_TCP_LINKS=0,
TSG_FS2_UDP_LINKS,
TSG_FS2_BYPASS,
TSG_FS2_HIT_ADDR,
TSG_FS2_HIT_SHARE,
TSG_FS2_INTERCEPT,
TSG_FS2_SHAPING,
TSG_FS2_S_CHAINING,
TSG_FS2_CTRL_OPENING,
TSG_FS2_CTRL_CLOSING,
TSG_FS2_CTRL_ACTIVE,
TSG_FS2_CTRL_RESETALL,
TSG_FS2_INJECT_CTRL_SUCCESS,
TSG_FS2_INJECT_CTRL_FAILED,
TSG_FS2_EXCLUSION,
TSG_FS2_APP_DPKT_RESULT,
TSG_FS2_APP_Q_RESULT,
TSG_FS2_APP_USER_RESULT,
TSG_FS2_APP_BUILT_IN_RESULT,
TSG_FS2_INJECT_PKT_SUCCESS,
TSG_FS2_INJECT_PKT_FAILED,
TSG_FS2_MIRRORED_PKT_SUCCESS,
TSG_FS2_MIRRORED_BYTE_SUCCESS,
TSG_FS2_MIRRORED_PKT_FAILED,
TSG_FS2_MIRRORED_BYTE_FAILED,
TSG_FS2_SET_TIMOUT_SUCCESS,
TSG_FS2_SET_TIMOUT_FAILED,
TSG_FS2_SUCESS_TAMPER,
TSG_FS2_TAMPER_FAILED_PLOAD_LESS_4,
TSG_FS2_TAMPER_FAILED_NOSWAP,
TSG_FS2_ASN_ADD,
TSG_FS2_ASN_DEL,
TSG_FS2_GTPC_ADD,
TSG_FS2_GTPC_DEL,
TSG_FS2_LOCATION_ADD,
TSG_FS2_LOCATION_DEL,
TSG_FS2_FQDN_ADD,
TSG_FS2_FQDN_DEL,
TSG_FS2_SUBSCRIBER_ADD,
TSG_FS2_SUBSCRIBER_DEL,
TSG_FS2_SECURIRY_ADD,
TSG_FS2_SECURIRY_DEL,
TSG_FS2_MIRRORED_ADD,
TSG_FS2_MIRRORED_DEL,
TSG_FS2_HTTP_RES_ADD,
TSG_FS2_HTTP_RES_DEL,
TSG_FS2_DNS_RES_ADD,
TSG_FS2_DNS_RES_DEL,
TSG_FS2_APP_ID_ADD,
TSG_FS2_APP_ID_DEL,
TSG_FS2_TUNNEL_CATALOG_ADD,
TSG_FS2_TUNNEL_CATALOG_DEL,
TSG_FS2_TUNNEL_ENDPOINT_ADD,
TSG_FS2_TUNNEL_ENDPOINT_DEL,
TSG_FS2_TUNNEL_LABEL_ADD,
TSG_FS2_TUNNEL_LABEL_DEL,
TSG_FS2_MAX
};
enum DEPLOY_MODE enum DEPLOY_MODE
{ {
DEPLOY_MODE_MIRROR, DEPLOY_MODE_MIRROR,
@@ -137,13 +74,11 @@ struct tsg_rt_para
int identify_app_max_pkt_num; int identify_app_max_pkt_num;
int unknown_app_id; int unknown_app_id;
int proto_flag; //enum TSG_PROTOCOL int proto_flag; //enum TSG_PROTOCOL
int fs2_field_id[TSG_FS2_MAX];
char device_sn[MAX_STRING_LEN128]; char device_sn[MAX_STRING_LEN128];
char log_path[MAX_STRING_LEN128]; char log_path[MAX_STRING_LEN128];
char device_id_command[MAX_STRING_LEN128]; char device_id_command[MAX_STRING_LEN128];
void *logger; void *logger;
struct reset_argv reset; struct reset_argv reset;
screen_stat_handle_t fs2_handle;
struct l7_protocol *name_by_id; struct l7_protocol *name_by_id;
struct l7_protocol *id_by_name; struct l7_protocol *id_by_name;
struct traffic_mirror *mirror_handle; struct traffic_mirror *mirror_handle;

View File

@@ -9,21 +9,21 @@ include_directories(${PROJECT_SOURCE_DIR}/src/)
add_definitions(-std=c++11) add_definitions(-std=c++11)
LINK_DIRECTORIES(/opt/MESA/lib) LINK_DIRECTORIES(/opt/MESA/lib)
add_executable(gtest_rule ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp gtest_common.cpp gtest_rule.cpp) add_executable(gtest_rule ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp ${PROJECT_SOURCE_DIR}/src/tsg_stat.cpp gtest_common.cpp gtest_rule.cpp)
target_link_libraries(gtest_rule gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4) target_link_libraries(gtest_rule gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4 fieldstat3)
add_executable(gtest_tableinfo ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp gtest_common.cpp gtest_tableinfo.cpp) add_executable(gtest_tableinfo ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp ${PROJECT_SOURCE_DIR}/src/tsg_stat.cpp gtest_common.cpp gtest_tableinfo.cpp)
target_link_libraries(gtest_tableinfo gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4) target_link_libraries(gtest_tableinfo gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4 fieldstat3)
add_executable(gtest_bridge ${PROJECT_SOURCE_DIR}/src/tsg_bridge.cpp ${PROJECT_SOURCE_DIR}/src/tsg_protocol.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp gtest_common.cpp gtest_bridge.cpp) add_executable(gtest_bridge ${PROJECT_SOURCE_DIR}/src/tsg_bridge.cpp ${PROJECT_SOURCE_DIR}/src/tsg_protocol.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp ${PROJECT_SOURCE_DIR}/src/tsg_stat.cpp gtest_common.cpp gtest_bridge.cpp)
target_link_libraries(gtest_bridge gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4) target_link_libraries(gtest_bridge gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4 fieldstat3)
add_executable(gtest_action ${PROJECT_SOURCE_DIR}/src/tsg_action.cpp ${PROJECT_SOURCE_DIR}/src/tsg_leaky_bucket.cpp ${PROJECT_SOURCE_DIR}/src/tsg_dns.cpp ${PROJECT_SOURCE_DIR}/src/tsg_icmp.cpp ${PROJECT_SOURCE_DIR}/src/tsg_tamper.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp gtest_common.cpp gtest_action.cpp) add_executable(gtest_action ${PROJECT_SOURCE_DIR}/src/tsg_action.cpp ${PROJECT_SOURCE_DIR}/src/tsg_leaky_bucket.cpp ${PROJECT_SOURCE_DIR}/src/tsg_dns.cpp ${PROJECT_SOURCE_DIR}/src/tsg_icmp.cpp ${PROJECT_SOURCE_DIR}/src/tsg_tamper.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp ${PROJECT_SOURCE_DIR}/src/tsg_stat.cpp gtest_common.cpp gtest_action.cpp)
target_link_libraries(gtest_action gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4 MESA_field_stat2) target_link_libraries(gtest_action gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4 fieldstat3)
add_executable(gtest_sendlog ${PROJECT_SOURCE_DIR}/src/tsg_send_log.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp gtest_common.cpp gtest_kafka.cpp gtest_sendlog.cpp) add_executable(gtest_sendlog ${PROJECT_SOURCE_DIR}/src/tsg_send_log.cpp ${PROJECT_SOURCE_DIR}/src/tsg_variable.cpp ${PROJECT_SOURCE_DIR}/src/tsg_stat.cpp gtest_common.cpp gtest_kafka.cpp gtest_sendlog.cpp)
target_link_libraries(gtest_sendlog gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4 rdkafka MESA_field_stat2) target_link_libraries(gtest_sendlog gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger maat4 rdkafka fieldstat3)
set(TSG_MASTER_SRC ${PROJECT_SOURCE_DIR}/src/tsg_entry.cpp set(TSG_MASTER_SRC ${PROJECT_SOURCE_DIR}/src/tsg_entry.cpp
${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp
@@ -43,13 +43,14 @@ set(TSG_MASTER_SRC ${PROJECT_SOURCE_DIR}/src/tsg_entry.cpp
${PROJECT_SOURCE_DIR}/src/tsg_protocol.cpp ${PROJECT_SOURCE_DIR}/src/tsg_protocol.cpp
${PROJECT_SOURCE_DIR}/src/tsg_proxy.cpp ${PROJECT_SOURCE_DIR}/src/tsg_proxy.cpp
${PROJECT_SOURCE_DIR}/src/mpack.c ${PROJECT_SOURCE_DIR}/src/mpack.c
${PROJECT_SOURCE_DIR}/src/tsg_stat.cpp
) )
add_executable(gtest_master ${TSG_MASTER_SRC} gtest_kafka.cpp gtest_common.cpp gtest_master.cpp) add_executable(gtest_master ${TSG_MASTER_SRC} gtest_kafka.cpp gtest_common.cpp gtest_master.cpp)
target_link_libraries(gtest_master gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maat4 MESA_htable fieldstat3) target_link_libraries(gtest_master gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maat4 MESA_htable fieldstat3)
add_executable(gtest_sync_state ${PROJECT_SOURCE_DIR}/src/tsg_sync_state.cpp ${PROJECT_SOURCE_DIR}/src/mpack.c gtest_common.cpp gtest_sync_state.cpp) add_executable(gtest_sync_state ${PROJECT_SOURCE_DIR}/src/tsg_sync_state.cpp ${PROJECT_SOURCE_DIR}/src/mpack.c ${PROJECT_SOURCE_DIR}/src/tsg_stat.cpp gtest_common.cpp gtest_sync_state.cpp)
target_link_libraries(gtest_sync_state gtest-static cjson ctemplate-static MESA_handle_logger) target_link_libraries(gtest_sync_state gtest-static cjson ctemplate-static MESA_prof_load MESA_handle_logger fieldstat3)
add_executable(gtest_fieldstat3 ${TSG_MASTER_SRC} gtest_common.cpp gtest_kafka.cpp gtest_fieldstat3.cpp) add_executable(gtest_fieldstat3 ${TSG_MASTER_SRC} gtest_common.cpp gtest_kafka.cpp gtest_fieldstat3.cpp)
target_link_libraries(gtest_fieldstat3 gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maat4 MESA_htable fieldstat3) target_link_libraries(gtest_fieldstat3 gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maat4 MESA_htable fieldstat3)

View File

@@ -1,8 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "tsg_stat.h"
#include "tsg_rule.h" #include "tsg_rule.h"
#include "tsg_label.h" #include "tsg_label.h"
#include "tsg_entry.h" #include "tsg_entry.h"
@@ -1091,7 +1092,11 @@ TEST(TMAPI, ScanAppPropertiesPolicy)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
tsg_stat_create("./tsgconf/main.conf");
tsg_stat_init();
tsg_maat_rule_init("tsgconf/main.conf"); tsg_maat_rule_init("tsgconf/main.conf");
tsg_stat_start();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@@ -5,6 +5,7 @@
#include <MESA/field_stat2.h> #include <MESA/field_stat2.h>
#include <MESA/stream.h> #include <MESA/stream.h>
#include "tsg_stat.h"
#include "tsg_rule.h" #include "tsg_rule.h"
#include "tsg_bridge.h" #include "tsg_bridge.h"
#include "tsg_send_log.h" #include "tsg_send_log.h"
@@ -17,7 +18,7 @@
struct maat *g_tsg_maat_feather; struct maat *g_tsg_maat_feather;
extern struct tsg_log_instance_t *tsg_sendlog_init(const char * conffile, screen_stat_handle_t fs2_handle); extern struct tsg_log_instance_t *tsg_sendlog_init(const char * conffile, screen_stat_handle_t fs3_instance);
char *tsg_device_tag_get(void) char *tsg_device_tag_get(void)
{ {
@@ -365,21 +366,11 @@ TEST(Master, SendBgpRecord)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
screen_stat_handle_t fs2_handle=FS_create_handle(); tsg_stat_create("./tsgconf/main.conf");
tsg_stat_init();
int value=0,cycle=30; g_tsg_log_instance=tsg_sendlog_init("./tsgconf/main.conf");
value=1;//Rewrite tsg_stat_start();
FS_set_para(fs2_handle, PRINT_MODE, &value, sizeof(value));
value=1;//Do not create stat thread
FS_set_para(fs2_handle, CREATE_THREAD, &value, sizeof(value));
FS_set_para(fs2_handle, STAT_CYCLE, &cycle, sizeof(cycle));
FS_set_para(fs2_handle, APP_NAME, (char *)"test", strlen((char *)"test")+1);
value=FS_OUTPUT_INFLUX_LINE;
FS_set_para(fs2_handle, STATS_FORMAT, &value, sizeof(value));
g_tsg_log_instance=tsg_sendlog_init("./tsgconf/main.conf", fs2_handle);
FS_start(fs2_handle);
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();

View File

@@ -6,6 +6,7 @@
#include <MESA/cJSON.h> #include <MESA/cJSON.h>
#include <MESA/MESA_handle_logger.h> #include <MESA/MESA_handle_logger.h>
#include "tsg_stat.h"
#include "tsg_sync_state.h" #include "tsg_sync_state.h"
#include "tsg_variable.h" #include "tsg_variable.h"
#include "mpack.h" #include "mpack.h"
@@ -1465,7 +1466,10 @@ TEST(LOG_UPDATE, ProxyTwice)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
g_tsg_para.logger = MESA_create_runtime_log_handle("log/tsg_sync_state", 10); g_tsg_para.logger = MESA_create_runtime_log_handle("log/tsg_sync_state", 10);
// tsg_bridge_init("tsgconf/main.conf"); tsg_stat_create("./tsgconf/main.conf");
tsg_stat_init();
tsg_stat_start();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
int ret = RUN_ALL_TESTS(); int ret = RUN_ALL_TESTS();
MESA_destroy_runtime_log_handle(g_tsg_para.logger); MESA_destroy_runtime_log_handle(g_tsg_para.logger);

View File

@@ -1,8 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include "tsg_stat.h"
#include "tsg_rule.h" #include "tsg_rule.h"
#include "tsg_label.h" #include "tsg_label.h"
#include "tsg_entry.h" #include "tsg_entry.h"
@@ -1379,9 +1380,14 @@ TEST(TSG_Table, APP_SIG_SESSION_ATTRIBUTE_INTEGER)
maat_state_free(mid); maat_state_free(mid);
mid = NULL; mid = NULL;
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
tsg_stat_create("./tsgconf/main.conf");
tsg_stat_init();
tsg_maat_rule_init("tsgconf/main.conf"); tsg_maat_rule_init("tsgconf/main.conf");
tsg_stat_start();
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }