TFE增加decrypted traffic mirror的监控指标
This commit is contained in:
@@ -19,6 +19,28 @@ enum traffic_mirror_target_addr_type
|
||||
TRAFFIC_MIRROR_TARGET_BY_ETHER_ADDR,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
TRAFFIC_MIRR_STAT_SUCC_BYTES,
|
||||
TRAFFIC_MIRR_STAT_SUCC_PKTS,
|
||||
|
||||
TRAFFIC_MIRR_STAT_FAIL_BYTES,
|
||||
TRAFFIC_MIRR_STAT_FAIL_PKTS,
|
||||
|
||||
TRAFFIC_MIRR_STAT_MAX,
|
||||
};
|
||||
|
||||
struct traffic_mirror_stat
|
||||
{
|
||||
screen_stat_handle_t fs_handle;
|
||||
|
||||
uint64_t stat_idx[TRAFFIC_MIRR_STAT_MAX];
|
||||
uint64_t stat_val[TRAFFIC_MIRR_STAT_MAX];
|
||||
|
||||
struct event_base *evbase;
|
||||
struct event *ev;
|
||||
};
|
||||
|
||||
struct traffic_mirror_instance
|
||||
{
|
||||
void * logger;
|
||||
@@ -35,6 +57,7 @@ struct traffic_mirror_instance
|
||||
char default_ether_addr_dst;
|
||||
|
||||
struct traffic_mirror_ethdev * ethdev;
|
||||
struct traffic_mirror_stat *stat;
|
||||
};
|
||||
|
||||
struct policy_table_ex_data
|
||||
@@ -108,6 +131,7 @@ struct traffic_mirror_rebuild_target
|
||||
int rewrite_as_target_vlan;
|
||||
};
|
||||
|
||||
extern struct traffic_mirror_instance *g_traffic_mirror_instance;
|
||||
struct traffic_mirror_ethdev * traffic_mirror_ethdev_pcap_create(const char * str_ethdev, void * logger);
|
||||
struct traffic_mirror_ethdev * traffic_mirror_ethdev_mr4_create(const char * str_ethdev,
|
||||
const char * str_app_name, unsigned int nr_threads, void * logger);
|
||||
|
||||
@@ -23,6 +23,53 @@ struct traffic_mirror_me
|
||||
struct traffic_mirror_instance __g_traffic_mirror_instance;
|
||||
struct traffic_mirror_instance * g_traffic_mirror_instance = &__g_traffic_mirror_instance;
|
||||
|
||||
static void stat_output_cb(evutil_socket_t fd, short what, void *arg)
|
||||
{
|
||||
struct traffic_mirror_stat *handle = (struct traffic_mirror_stat *)arg;
|
||||
for (int i = 0; i < TRAFFIC_MIRR_STAT_MAX; i++)
|
||||
{
|
||||
FS_operate(handle->fs_handle, handle->stat_idx[i], 0, FS_OP_SET, ATOMIC_READ(&(handle->stat_val[i])));
|
||||
}
|
||||
}
|
||||
|
||||
struct traffic_mirror_stat *traffic_mirror_stat_new()
|
||||
{
|
||||
struct traffic_mirror_stat *handle = (struct traffic_mirror_stat *)calloc(1, sizeof(struct traffic_mirror_stat));
|
||||
if (handle == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct timeval gc_delay = {5, 0};
|
||||
const char *stat_name[TRAFFIC_MIRR_STAT_MAX] = { 0 };
|
||||
stat_name[TRAFFIC_MIRR_STAT_SUCC_BYTES] = "mirr_succ_B";
|
||||
stat_name[TRAFFIC_MIRR_STAT_SUCC_PKTS] = "mirr_succ_P";
|
||||
stat_name[TRAFFIC_MIRR_STAT_FAIL_BYTES] = "mirr_fail_B";
|
||||
stat_name[TRAFFIC_MIRR_STAT_FAIL_PKTS] = "mirr_fail_P";
|
||||
handle->fs_handle = tfe_proxy_get_fs_handle();
|
||||
handle->evbase = tfe_proxy_get_gc_evbase();
|
||||
for (int i = 0; i < TRAFFIC_MIRR_STAT_MAX; i++)
|
||||
{
|
||||
handle->stat_idx[i] = FS_register(handle->fs_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, stat_name[i]);
|
||||
}
|
||||
handle->ev = event_new(handle->evbase, -1, EV_PERSIST, stat_output_cb, handle);
|
||||
evtimer_add(handle->ev, &gc_delay);
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
void traffic_mirror_stat_free(struct traffic_mirror_stat *handle)
|
||||
{
|
||||
if (handle)
|
||||
{
|
||||
if (handle->ev)
|
||||
{
|
||||
event_free(handle->ev);
|
||||
}
|
||||
free(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void policy_table_ex_data_free(struct policy_table_ex_data * object)
|
||||
{
|
||||
if ((__sync_sub_and_fetch(&object->atomic_refcnt, 1) == 0)) free(object);
|
||||
@@ -437,7 +484,8 @@ int traffic_mirror_init(struct tfe_proxy * proxy)
|
||||
{
|
||||
int result = 0;
|
||||
struct traffic_mirror_instance * instance = g_traffic_mirror_instance;
|
||||
instance->logger = tfe_proxy_get_error_logger();
|
||||
instance->logger = tfe_proxy_get_error_logger();
|
||||
instance->stat = traffic_mirror_stat_new();
|
||||
|
||||
/* Using PANGU-HTTP's profile */
|
||||
MESA_load_profile_uint_def("./conf/tfe/tfe.conf", "traffic_mirror", "enable", &(instance->enable), 1);
|
||||
|
||||
@@ -346,8 +346,13 @@ static void tcp_segment_send_to_target_group(struct tfe_stream_addr * addr, stru
|
||||
int ret = traffic_mirror_ethdev_finish(ethdev, tid, pkt_len);
|
||||
if (unlikely(ret < 0))
|
||||
{
|
||||
//TODO: 统计计数
|
||||
return;
|
||||
ATOMIC_ADD(&(g_traffic_mirror_instance->stat->stat_val[TRAFFIC_MIRR_STAT_FAIL_PKTS]), 1);
|
||||
ATOMIC_ADD(&(g_traffic_mirror_instance->stat->stat_val[TRAFFIC_MIRR_STAT_FAIL_BYTES]), pkt_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
ATOMIC_ADD(&(g_traffic_mirror_instance->stat->stat_val[TRAFFIC_MIRR_STAT_SUCC_PKTS]), 1);
|
||||
ATOMIC_ADD(&(g_traffic_mirror_instance->stat->stat_val[TRAFFIC_MIRR_STAT_SUCC_BYTES]), pkt_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user