summaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2024-03-07 16:17:36 +0800
committerluwenpeng <[email protected]>2024-03-07 16:17:36 +0800
commit0946effa1bcb9b8b6daccfc615ef0d0adc59e24d (patch)
tree3af0a5614d7dc8f8f1470e477d7fdf433e2b082b /plugin
parent4bde4e0abbb67ba847ce0ffc51380169673abc6e (diff)
TFE增加decrypted traffic mirror的监控指标
Diffstat (limited to 'plugin')
-rw-r--r--plugin/business/traffic-mirror/include/traffic_mirror.h24
-rw-r--r--plugin/business/traffic-mirror/src/entry.cpp50
-rw-r--r--plugin/business/traffic-mirror/src/rebuild.cpp9
3 files changed, 80 insertions, 3 deletions
diff --git a/plugin/business/traffic-mirror/include/traffic_mirror.h b/plugin/business/traffic-mirror/include/traffic_mirror.h
index a062f64..5423ca2 100644
--- a/plugin/business/traffic-mirror/include/traffic_mirror.h
+++ b/plugin/business/traffic-mirror/include/traffic_mirror.h
@@ -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);
diff --git a/plugin/business/traffic-mirror/src/entry.cpp b/plugin/business/traffic-mirror/src/entry.cpp
index cf00a2b..ef56552 100644
--- a/plugin/business/traffic-mirror/src/entry.cpp
+++ b/plugin/business/traffic-mirror/src/entry.cpp
@@ -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);
diff --git a/plugin/business/traffic-mirror/src/rebuild.cpp b/plugin/business/traffic-mirror/src/rebuild.cpp
index 5cb5524..b595256 100644
--- a/plugin/business/traffic-mirror/src/rebuild.cpp
+++ b/plugin/business/traffic-mirror/src/rebuild.cpp
@@ -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);
}
}