TFE增加decrypted traffic mirror的监控指标

This commit is contained in:
luwenpeng
2024-03-07 16:17:36 +08:00
parent 4bde4e0abb
commit 0946effa1b
3 changed files with 80 additions and 3 deletions

View File

@@ -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);
@@ -438,7 +485,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);