diff --git a/src/tsg_entry.cpp b/src/tsg_entry.cpp index f708993..2814683 100644 --- a/src/tsg_entry.cpp +++ b/src/tsg_entry.cpp @@ -41,7 +41,7 @@ static __attribute__((__used__)) const char * GIT_VERSION_UNKNOWN = NULL; #endif -char TSG_MASTER_VERSION_20200322=0; +char TSG_MASTER_VERSION_20200330=0; const char *tsg_conffile="tsgconf/main.conf"; g_tsg_para_t g_tsg_para; @@ -418,6 +418,8 @@ static int identify_application_protocol(struct streaminfo *a_stream, struct _id extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int thread_seq,void *a_packet) { int ret=0,hit_num=0; + struct timespec tv; + long establish_latency_ms=0; int state=APP_STATE_GIVEME; scan_status_t mid=NULL; Maat_rule_t *p_result=NULL; @@ -436,10 +438,8 @@ extern "C" char TSG_MASTER_TCP_ENTRY(struct streaminfo *a_tcp, void **pme, int t identify_application_protocol(a_tcp, &identify_info); if(identify_info.proto==PROTO_HTTP) { - struct timeval tv; - long establish_latency_ms=0; - gettimeofday(&tv, NULL); - establish_latency_ms=(tv.tv_sec-a_tcp->ptcpdetail->createtime)*1000+tv.tv_usec/1000; + clock_gettime(CLOCK_REALTIME, &tv); + establish_latency_ms=(tv.tv_sec-a_tcp->ptcpdetail->createtime)*1000+tv.tv_nsec/1000/1000; ret=project_req_add_long(a_tcp, g_tsg_para.establish_latency_project_id, establish_latency_ms); if(ret<0) { @@ -741,7 +741,6 @@ extern "C" int TSG_MASTER_INIT() if(g_tsg_para.establish_latency_project_id<0) { MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "PROJECT_REGISTER", "Register %s failed ...", label_buff); - return -1; } ret=tsg_rule_init(tsg_conffile, g_tsg_para.logger); @@ -757,6 +756,7 @@ extern "C" int TSG_MASTER_INIT() MESA_handle_runtime_log(g_tsg_para.logger, RLOG_LV_FATAL, "INIT_SENDLOG", "tsg_sendlog_init failed ..."); return -1; } + g_tsg_log_instance->establish_latency_project_id=g_tsg_para.establish_latency_project_id; MESA_load_profile_int_def(tsg_conffile, "FIELD_STAT", "CYCLE", &cycle, 30); MESA_load_profile_short_nodef(tsg_conffile, "FIELD_STAT","TELEGRAF_PORT", (short *)&(fs_server_port)); diff --git a/src/tsg_entry.h b/src/tsg_entry.h index 7492468..72f4b12 100644 --- a/src/tsg_entry.h +++ b/src/tsg_entry.h @@ -141,6 +141,7 @@ typedef struct _tsg_statistic int fs_line_id; int fs_field_id[STATIS_MAX]; struct _traffic_info *traffic_info[TSG_ACTION_MAX+1]; + struct _traffic_info default_total_info; screen_stat_handle_t fs2_handle; }tsg_statis_para_t; diff --git a/src/tsg_send_log.cpp b/src/tsg_send_log.cpp index 3c6513a..8bb1a84 100644 --- a/src/tsg_send_log.cpp +++ b/src/tsg_send_log.cpp @@ -19,7 +19,7 @@ #include "tsg_send_log.h" #include "tsg_send_log_internal.h" -char TSG_SEND_LOG_VERSION_20200119=0; +char TSG_SEND_LOG_VERSION_20200330=0; struct tsg_log_instance_t *g_tsg_log_instance; @@ -417,6 +417,7 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl { int i=0,status=0; char *payload=NULL; + long establish_latency_ms=0; struct TLD_handle_t *_handle=handle; struct tsg_log_instance_t *_instance=instance; @@ -459,6 +460,15 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl break; } + if(log_msg->result[i].action==TSG_ACTION_MONITOR && _instance->establish_latency_project_id>0) + { + establish_latency_ms=project_req_get_long(log_msg->a_stream, _instance->establish_latency_project_id); + if(establish_latency_ms>=0) + { + TLD_append(_handle, _instance->id2field[LOG_COMMON_ESTABLISH_LATENCY_MS].name, (void *)establish_latency_ms, TLD_TYPE_LONG); + } + } + TLD_append(_handle, _instance->id2field[LOG_COMMON_POLICY_ID].name, (void *)(long)(log_msg->result[i].config_id), TLD_TYPE_LONG); TLD_append(_handle, _instance->id2field[LOG_COMMON_SERVICE].name, (void *)(long)(log_msg->result[i].service_id), TLD_TYPE_LONG); TLD_append(_handle, _instance->id2field[LOG_COMMON_ACTION].name, (void *)(long)((unsigned char)log_msg->result[i].action), TLD_TYPE_LONG); @@ -485,6 +495,7 @@ int tsg_send_log(struct tsg_log_instance_t *instance, struct TLD_handle_t *handl TLD_delete(_handle, _instance->id2field[LOG_COMMON_POLICY_ID].name); TLD_delete(_handle, _instance->id2field[LOG_COMMON_SERVICE].name); TLD_delete(_handle, _instance->id2field[LOG_COMMON_ACTION].name); + TLD_delete(_handle, _instance->id2field[LOG_COMMON_ESTABLISH_LATENCY_MS].name); FS_operate(g_tsg_para.fs2_handle, g_tsg_para.fs2_field_id[TSG_FS2_LOG], 0, FS_OP_ADD, 1); } diff --git a/src/tsg_send_log_internal.h b/src/tsg_send_log_internal.h index 7f05dd5..bf94d6c 100644 --- a/src/tsg_send_log_internal.h +++ b/src/tsg_send_log_internal.h @@ -59,6 +59,7 @@ typedef enum _tsg_log_field_id LOG_COMMON_SCHAME_TYPE, LOG_HTTP_HOST, LOG_SSL_SNI, + LOG_COMMON_ESTABLISH_LATENCY_MS, LOG_COMMON_MAX }tsg_log_field_id_t; @@ -79,6 +80,7 @@ struct tsg_log_instance_t { int mode; int max_service; + int establish_latency_project_id; void *logger; char common_field_file[MAX_STRING_LEN*4]; char broker_list[MAX_STRING_LEN*4]; diff --git a/src/tsg_statistic.cpp b/src/tsg_statistic.cpp index b369091..92e54ec 100644 --- a/src/tsg_statistic.cpp +++ b/src/tsg_statistic.cpp @@ -61,15 +61,20 @@ static int _get_traffic_info(struct _traffic_info *total, struct _traffic_info * out->out_bytes=total->out_bytes-policy->out_bytes; out->out_packets=total->out_packets-policy->out_packets; - if(out->con_num<0 || out->in_bytes<0 || out->in_packets<0 || out->out_bytes<0 || out->out_packets<0) + if(out->con_num-g_tsg_statis_para.default_total_info.con_num<0 + || out->in_bytes-g_tsg_statis_para.default_total_info.in_bytes<0 + || out->in_packets-g_tsg_statis_para.default_total_info.in_packets<0 + || out->out_bytes-g_tsg_statis_para.default_total_info.out_bytes<0 + || out->out_packets-g_tsg_statis_para.default_total_info.out_packets<0) { - out->con_num=total->con_num; - out->in_bytes=total->in_bytes; - out->in_packets=total->in_packets; - out->out_bytes=total->out_bytes; - out->out_packets=total->out_packets; + memcpy(out, &g_tsg_statis_para.default_total_info, sizeof(struct _traffic_info)); } + else + { + memcpy(&g_tsg_statis_para.default_total_info, out, sizeof(struct _traffic_info)); + } } + return 0; }