fs增加远程输出
This commit is contained in:
@@ -21,7 +21,13 @@ bypass: drome: pme_new_fail: destroy_pme
|
||||
#include "kni_send_logger.h"
|
||||
#include <linux/if_ether.h>
|
||||
#include "tfe_mgr.h"
|
||||
#include "dablooms.h"
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "dablooms.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#include "kni_tun.h"
|
||||
|
||||
struct kni_handle *g_kni_handle = NULL;
|
||||
@@ -280,6 +286,12 @@ static void pme_info_destroy(void *data){
|
||||
}
|
||||
|
||||
static struct pme_info* pme_info_new(const struct streaminfo *stream, int thread_seq){
|
||||
if(stream->addr.addrtype == ADDR_TYPE_IPV6){
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV6_STM], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
else{
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV4_STM], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
void *logger = g_kni_handle->local_logger;
|
||||
struct pme_info* pmeinfo = ALLOC(struct pme_info, 1);
|
||||
pmeinfo->addr_type = (enum addr_type_t)stream->addr.addrtype;
|
||||
@@ -455,15 +467,6 @@ static void stream_destroy(struct pme_info *pmeinfo, int do_log){
|
||||
KNI_LOG_DEBUG(logger, "Succeed at log_generate, stream traceid = %s", pmeinfo->stream_traceid);
|
||||
}
|
||||
}
|
||||
//intercept traffic stat
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_BYTES], 0, FS_OP_ADD,
|
||||
pmeinfo->server_bytes + pmeinfo->client_bytes);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_STM], 0, FS_OP_ADD, 1);
|
||||
if(pmeinfo->intercept_state == 1){
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_TFE_INTCP_BYTES], 0, FS_OP_ADD,
|
||||
pmeinfo->server_bytes + pmeinfo->client_bytes);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_TFE_INTCP_STM], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
//free pme
|
||||
pme_info_destroy(pmeinfo);
|
||||
}
|
||||
@@ -723,6 +726,8 @@ static int send_to_tfe_normal_mode(char *raw_data, uint16_t raw_len, int thread_
|
||||
}
|
||||
|
||||
static int send_to_tfe_tun_mode(char *raw_data, uint16_t raw_len, addr_type_t addr_type){
|
||||
//intercept traffic stat
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_BYTES], 0, FS_OP_ADD, raw_len);
|
||||
struct kni_tun_handle *handle = g_kni_handle->tun_handle;
|
||||
char *dst_data = ALLOC(char, KNI_MTU);
|
||||
add_ether_header(dst_data, raw_data, raw_len, addr_type);
|
||||
@@ -1028,9 +1033,9 @@ static int first_data_intercept(struct streaminfo *stream, struct pme_info *pmei
|
||||
}
|
||||
else{
|
||||
KNI_LOG_DEBUG(logger, "Succeed at send first packet to tfe%d, stream traceid = %s", pmeinfo->tfe_id, pmeinfo->stream_traceid);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_KNI_INTCP_STM], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
FREE(&buff);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_INTCP_STM], 0, FS_OP_ADD, 1);
|
||||
return APP_STATE_DROPPKT | APP_STATE_GIVEME;
|
||||
}
|
||||
|
||||
@@ -1045,7 +1050,15 @@ static int dabloom_search(struct pkt_info *pktinfo, int thread_seq){
|
||||
KNI_LOG_ERROR(logger, "Failed at expiry_dablooms_search, errmsg = %s", expiry_dablooms_errno_trans((enum expiry_dablooms_errno)ret));
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_FAIL], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_SUCC], 0, FS_OP_ADD, 1);
|
||||
else{
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_SUCC], 0, FS_OP_ADD, 1);
|
||||
if(ret == 1){
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_HIT], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
else{
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_BLOOM_MISS], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
}
|
||||
uint64_t count = 0;
|
||||
expiry_dablooms_element_count_get(g_kni_handle->threads_handle[thread_seq].dabloom_handle, &count);
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->line_ids[0], g_kni_fs_handle->column_ids[thread_seq], FS_OP_SET, count);
|
||||
@@ -1287,12 +1300,6 @@ extern "C" char kni_tcpall_entry(struct streaminfo *stream, void** pme, int thre
|
||||
int ret;
|
||||
int can_destroy;
|
||||
struct pme_info *pmeinfo = *(struct pme_info **)pme;
|
||||
if(stream->addr.addrtype == ADDR_TYPE_IPV6){
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV6_STM], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
else{
|
||||
FS_operate(g_kni_fs_handle->handle, g_kni_fs_handle->fields[KNI_FIELD_IPV4_STM], 0, FS_OP_ADD, 1);
|
||||
}
|
||||
|
||||
/* a_packet == NULL && not op_state_close, continue
|
||||
close: a_packet may be null, if a_packet = null, do not send to tfe
|
||||
@@ -1507,6 +1514,7 @@ extern "C" char kni_polling_all_entry(const struct streaminfo *stream, void** pm
|
||||
tuple2stream_htable_search(tuple2stream_htable, ether_hdr, thread_seq);
|
||||
flag = 1;
|
||||
}
|
||||
marsio_buff_free(g_kni_handle->marsio_handle->instance, rx_buffs, nr_recv, 0, 0);
|
||||
}
|
||||
}
|
||||
//tun mode
|
||||
@@ -1774,26 +1782,43 @@ static void fs_destroy(struct kni_field_stat_handle *fs_handle){
|
||||
static struct kni_field_stat_handle * fs_init(const char *profile){
|
||||
void *logger = g_kni_handle->local_logger;
|
||||
const char *section = "field_stat";
|
||||
char stat_path[KNI_PATH_MAX];
|
||||
char local_path[KNI_PATH_MAX];
|
||||
struct kni_field_stat_handle *fs_handle = NULL;
|
||||
screen_stat_handle_t handle = NULL;
|
||||
const char *app_name = "fs2_kni";
|
||||
int value = 0;
|
||||
int ret = MESA_load_profile_string_nodef(profile, section, "stat_path", stat_path, sizeof(stat_path));
|
||||
if(ret < 0){
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load: stat_path not set, profile = %s, section = %s", profile, section);
|
||||
goto error_out;
|
||||
}
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n stat_path: %s\n", "field_stat", stat_path);
|
||||
int value = 0, ret;
|
||||
int remote_switch = 0;
|
||||
char remote_ip[INET_ADDRSTRLEN];
|
||||
int remote_port;
|
||||
MESA_load_profile_int_def(profile, section, "remote_switch", &remote_switch, 0);
|
||||
MESA_load_profile_string_def(profile, section, "local_path", local_path, sizeof(local_path), "./fs2_kni.status");
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n remote_switch: %d\n local_path: %s", section, remote_switch, local_path);
|
||||
handle = FS_create_handle();
|
||||
if(handle == NULL){
|
||||
KNI_LOG_ERROR(logger, "Failed at create FS_create_handle");
|
||||
goto error_out;
|
||||
}
|
||||
if(remote_switch == 1){
|
||||
ret = MESA_load_profile_string_nodef(profile, section, "remote_ip", remote_ip, sizeof(remote_ip));
|
||||
if(ret < 0){
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load: remote_ip not set, profile is %s, section is %s", profile, section);
|
||||
goto error_out;
|
||||
}
|
||||
ret = MESA_load_profile_int_nodef(profile, section, "remote_port", &remote_port);
|
||||
if(ret < 0){
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load: remote_port not set, profile is %s, section is %s", profile, section);
|
||||
goto error_out;
|
||||
}
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n remote_ip: %s\n remote_port: %d", section, remote_ip, remote_port);
|
||||
FS_set_para(handle, STATS_SERVER_IP, remote_ip, strlen(remote_ip));
|
||||
FS_set_para(handle, STATS_SERVER_PORT, &remote_port, sizeof(remote_port));
|
||||
value=FS_OUTPUT_STATSD;
|
||||
FS_set_para(handle, STATS_FORMAT, &value, sizeof(value));
|
||||
}
|
||||
fs_handle = ALLOC(struct kni_field_stat_handle, 1);
|
||||
fs_handle->handle = handle;
|
||||
FS_set_para(handle, APP_NAME, app_name, strlen(app_name) + 1);
|
||||
FS_set_para(handle, OUTPUT_DEVICE, stat_path, strlen(stat_path)+1);
|
||||
FS_set_para(handle, OUTPUT_DEVICE, local_path, strlen(local_path)+1);
|
||||
value = 0;
|
||||
FS_set_para(handle, FLUSH_BY_DATE, &value, sizeof(value));
|
||||
value = 1;
|
||||
@@ -1806,7 +1831,6 @@ static struct kni_field_stat_handle * fs_init(const char *profile){
|
||||
FS_set_para(handle, MAX_STAT_FIELD_NUM, &value, sizeof(value));
|
||||
fs_handle = ALLOC(struct kni_field_stat_handle, 1);
|
||||
fs_handle->handle = handle;
|
||||
fs_handle->fields[KNI_FIELD_INTCP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "intcp_stm");
|
||||
fs_handle->fields[KNI_FIELD_BYP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "byp_stm");
|
||||
fs_handle->fields[KNI_FIELD_BYP_STM_POLICY] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "byp_policy");
|
||||
fs_handle->fields[KNI_FIELD_BYP_STM_PME_NEW_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "byp_pme_new_F");
|
||||
@@ -1839,9 +1863,7 @@ static struct kni_field_stat_handle * fs_init(const char *profile){
|
||||
fs_handle->fields[KNI_FIELD_PME_FREE] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "pme_free");
|
||||
//intercept traffic stat
|
||||
fs_handle->fields[KNI_FIELD_KNI_INTCP_BYTES] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "kni_intcp_B");
|
||||
fs_handle->fields[KNI_FIELD_TFE_INTCP_BYTES] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "tfe_intcp_B");
|
||||
fs_handle->fields[KNI_FIELD_KNI_INTCP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "kni_intcp_stm");
|
||||
fs_handle->fields[KNI_FIELD_TFE_INTCP_STM] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "tfe_intcp_stm");
|
||||
//htable
|
||||
fs_handle->fields[KNI_FIELD_ID2PME_ADD_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "id2pme_add_S");
|
||||
fs_handle->fields[KNI_FIELD_ID2PME_ADD_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "id2pme_add_F");
|
||||
@@ -1856,6 +1878,8 @@ static struct kni_field_stat_handle * fs_init(const char *profile){
|
||||
fs_handle->fields[KNI_FIELD_SAPP_INJECT_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "sapp_inject_S");
|
||||
fs_handle->fields[KNI_FIELD_SAPP_INJECT_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "sapp_inject_F");
|
||||
fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_srch_S");
|
||||
fs_handle->fields[KNI_FIELD_BLOOM_HIT] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_hit");
|
||||
fs_handle->fields[KNI_FIELD_BLOOM_MISS] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_miss");
|
||||
fs_handle->fields[KNI_FIELD_BLOOM_SEARCH_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_srch_F");
|
||||
fs_handle->fields[KNI_FIELD_BLOOM_ADD_SUCC] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_add_S");
|
||||
fs_handle->fields[KNI_FIELD_BLOOM_ADD_FAIL] = FS_register(handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "bloom_add_F");
|
||||
@@ -1872,10 +1896,10 @@ static struct kni_field_stat_handle * fs_init(const char *profile){
|
||||
char buff[KNI_PATH_MAX];
|
||||
for(int i = 0; i < fs_handle->column_cnt; i++){
|
||||
snprintf(buff, sizeof(buff), "tid%d", i);
|
||||
fs_handle->column_ids[i] = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_SPEED, buff);
|
||||
fs_handle->column_ids[i] = FS_register(handle, FS_STYLE_COLUMN, FS_CALC_CURRENT, buff);
|
||||
}
|
||||
snprintf(buff, sizeof(buff), "bloom_cnt");
|
||||
fs_handle->line_ids[0] = FS_register(handle, FS_STYLE_LINE, FS_CALC_SPEED, buff);
|
||||
fs_handle->line_ids[0] = FS_register(handle, FS_STYLE_LINE, FS_CALC_CURRENT, buff);
|
||||
|
||||
fs_handle->handle = handle;
|
||||
FS_start(handle);
|
||||
@@ -1929,7 +1953,7 @@ int dup_traffic_dabloom_init(const char *profile, void *logger){
|
||||
MESA_load_profile_string_def(profile, section, "error_rate", error_rate_str, sizeof(error_rate_str), "0.05");
|
||||
MESA_load_profile_int_def(profile, section, "expiry_time", &expiry_time, 30);
|
||||
KNI_LOG_ERROR(logger, "MESA_prof_load, [%s]:\n action: %d\n capacity: %d\n error_rate: %s\n expiry_time: %d",
|
||||
section, capacity, error_rate_str, expiry_time);
|
||||
section, g_kni_handle->dup_traffic_action, capacity, error_rate_str, expiry_time);
|
||||
error_rate = atof(error_rate_str);
|
||||
for(int i = 0; i < g_kni_handle->thread_count; i++){
|
||||
struct expiry_dablooms_handle* dabloom_handle = expiry_dablooms_init(capacity, error_rate, expiry_time);
|
||||
|
||||
Reference in New Issue
Block a user