修复部分日志包数为0的问题, 通信时长精确到ms
This commit is contained in:
@@ -58,7 +58,7 @@ struct pme_info{
|
||||
pthread_mutex_t lock;
|
||||
enum stream_error error;
|
||||
char stream_traceid[stream_traceid_LEN];
|
||||
//TODO: union, cjson check protocol
|
||||
//cjson check protocol
|
||||
union{
|
||||
char host[KNI_DOMAIN_MAX]; //http only
|
||||
char sni[KNI_DOMAIN_MAX]; //ssl only
|
||||
@@ -74,8 +74,8 @@ struct pme_info{
|
||||
uint64_t server_pkts;
|
||||
uint64_t client_pkts;
|
||||
|
||||
time_t start_time;
|
||||
time_t end_time;
|
||||
struct timespec start_time;
|
||||
struct timespec end_time;
|
||||
uint64_t con_duration_ms;
|
||||
//from tfe, kafka log
|
||||
uint64_t intercept_state;
|
||||
@@ -203,7 +203,7 @@ static struct pme_info* pme_info_new(const struct streaminfo *stream, int thread
|
||||
uuid_generate_random(uu);
|
||||
uuid_unparse(uu, pmeinfo->stream_traceid);
|
||||
pmeinfo->addr = layer_addr_dup(&(stream->addr));
|
||||
pmeinfo->start_time = time(NULL);
|
||||
clock_gettime(CLOCK_MONOTONIC, &(pmeinfo->start_time));
|
||||
char stream_addr[KNI_SYMBOL_MAX] = "";
|
||||
//init pme_lock
|
||||
int ret = pthread_mutex_init(&(pmeinfo->lock), NULL);
|
||||
@@ -233,11 +233,12 @@ static int sendlog_to_kafka(struct pme_info *pmeinfo, void *local_logger){
|
||||
//service
|
||||
cJSON_AddNumberToObject(log_obj, "service", pmeinfo->service);
|
||||
//start_time
|
||||
cJSON_AddNumberToObject(log_obj, "start_time", pmeinfo->start_time);
|
||||
cJSON_AddNumberToObject(log_obj, "start_time", pmeinfo->start_time.tv_sec);
|
||||
//end_time
|
||||
cJSON_AddNumberToObject(log_obj, "end_time", pmeinfo->end_time);
|
||||
cJSON_AddNumberToObject(log_obj, "end_time", pmeinfo->end_time.tv_sec);
|
||||
//con_duration_ms
|
||||
cJSON_AddNumberToObject(log_obj, "con_duration_ms", (pmeinfo->end_time - pmeinfo->start_time) * 1000);
|
||||
cJSON_AddNumberToObject(log_obj, "con_duration_ms", (pmeinfo->end_time.tv_sec - pmeinfo->start_time.tv_sec) * 1000
|
||||
+ (pmeinfo->end_time.tv_nsec - pmeinfo->start_time.tv_nsec) / 1000000);
|
||||
//stream_info: addr_type, trans_proto, client_ip, client_port, server_ip, server_port
|
||||
const struct layer_addr *addr = pmeinfo->addr;
|
||||
char client_ip_str[INET6_ADDRSTRLEN] = "";
|
||||
@@ -608,6 +609,11 @@ static char pending_opstate(const struct streaminfo *stream, struct pme_info *pm
|
||||
static char data_opstate(const struct streaminfo *stream, struct pme_info *pmeinfo, struct pkt_info *pktinfo, int thread_seq){
|
||||
//pmeinfo->tfe_release = 1: intercept, tfe end first. so droppkt and dropme
|
||||
if(pmeinfo->tfe_release == 1){
|
||||
pmeinfo->server_bytes=stream->ptcpdetail->serverbytes;
|
||||
pmeinfo->client_bytes=stream->ptcpdetail->clientbytes;
|
||||
pmeinfo->server_pkts=stream->ptcpdetail->serverpktnum;
|
||||
pmeinfo->client_pkts=stream->ptcpdetail->clientpktnum;
|
||||
pmeinfo->dir=stream->dir;
|
||||
return APP_STATE_DROPPKT | APP_STATE_DROPME;
|
||||
}
|
||||
void *logger = g_kni_handle->local_logger;
|
||||
@@ -784,7 +790,7 @@ static char data_opstate(const struct streaminfo *stream, struct pme_info *pmein
|
||||
|
||||
static char close_opstate(const struct streaminfo *stream, struct pme_info *pmeinfo, struct pkt_info *pktinfo, int thread_seq){
|
||||
//close: a_packet = null, do not sendto tfe
|
||||
pmeinfo->end_time = time(NULL);
|
||||
clock_gettime(CLOCK_MONOTONIC, &(pmeinfo->end_time));
|
||||
void *logger = g_kni_handle->local_logger;
|
||||
pmeinfo->server_bytes=stream->ptcpdetail->serverbytes;
|
||||
pmeinfo->client_bytes=stream->ptcpdetail->clientbytes;
|
||||
@@ -1124,7 +1130,7 @@ static long traceid2pme_htable_search_cb(void *data, const uchar *key, uint size
|
||||
wrapped_kni_cmsg_get(pmeinfo, cmsg, TFE_CMSG_SSL_PINNING_STATE, sizeof(pmeinfo->pinningst), logger);
|
||||
wrapped_kni_cmsg_get(pmeinfo, cmsg, TFE_CMSG_SSL_CERT_VERIFY, sizeof(pmeinfo->ssl_cert_verify), logger);
|
||||
wrapped_kni_cmsg_get(pmeinfo, cmsg, TFE_CMSG_SSL_ERROR, sizeof(pmeinfo->ssl_error), logger);
|
||||
pmeinfo->end_time = time(NULL);
|
||||
clock_gettime(CLOCK_MONOTONIC, &(pmeinfo->end_time));
|
||||
KNI_LOG_INFO(logger, "recv cmsg from tfe, stream traceid is %s", pmeinfo->stream_traceid);
|
||||
judge_pme_destroy(pmeinfo, CALLER_TFE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user