bugfix:TSG-15454:kni新增发送proxy_rule_hits metric
This commit is contained in:
@@ -34,7 +34,11 @@ env | sort
|
||||
: "${COMPILER_IS_GNUCXX:=OFF}"
|
||||
|
||||
# Install dependency from YUM
|
||||
yum install -y mrzcpd numactl-devel zlib-devel librdkafka-devel systemd-devel libMESA_handle_logger-devel libMESA_htable-devel libcjson-devel libMESA_field_stat2-devel sapp-devel framework_env libMESA_prof_load-devel libmaatframe-devel tsg_master-devel libasan
|
||||
yum install -y mrzcpd numactl-devel zlib-devel librdkafka-devel systemd-devel \
|
||||
libMESA_handle_logger-devel libMESA_htable-devel libcjson-devel \
|
||||
libfieldstat3-devel libMESA_field_stat2-devel sapp-devel \
|
||||
framework_env libMESA_prof_load-devel libmaatframe-devel \
|
||||
tsg_master-devel libasan
|
||||
|
||||
if [ $ASAN_OPTION ] && [ -f "/opt/rh/devtoolset-7/enable" ] ;then
|
||||
source /opt/rh/devtoolset-7/enable
|
||||
|
||||
@@ -106,6 +106,7 @@ enum kni_field{
|
||||
KNI_FIELD_DUP_TFC_STM,
|
||||
KNI_FIELD_DUP_TFC_BYTE,
|
||||
//intercept ready stream
|
||||
KNI_FIELD_NO_INTCP_STM,
|
||||
KNI_FIELD_INTCP_READY_STM,
|
||||
KNI_FIELD_INTCP_READY_BYTE,
|
||||
//pme
|
||||
|
||||
@@ -167,3 +167,9 @@ tcp_passthrough = 0
|
||||
|
||||
[share_session_attribute]
|
||||
SESSION_ATTRIBUTE_LABEL=TSG_MASTER_INTERNAL_LABEL
|
||||
|
||||
[proxy_hits]
|
||||
interval_ms=1000
|
||||
telegraf_port=8400
|
||||
telegraf_ip=127.0.0.1
|
||||
app_name="proxy_rule_hits"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
set(CMAKE_INSTALL_PREFIX /home/mesasoft/sapp_run)
|
||||
add_library(kni SHARED src/kni_entry.cpp src/tfe_mgr.cpp src/kni_tap_rss.cpp src/kni_iouring.cpp src/kni_pxy_tcp_option.cpp src/kni_dynamic_bypass.cpp)
|
||||
add_library(kni SHARED src/kni_entry.cpp src/tfe_mgr.cpp src/kni_tap_rss.cpp src/kni_iouring.cpp src/kni_pxy_tcp_option.cpp src/kni_dynamic_bypass.cpp src/kni_fieldstat.cpp)
|
||||
target_include_directories(kni PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
|
||||
target_link_libraries(kni common MESA_prof_load MESA_htable MESA_field_stat maatframe mrzcpd dabloom)
|
||||
target_link_libraries(kni common MESA_prof_load MESA_htable MESA_field_stat fieldstat3 maatframe mrzcpd dabloom)
|
||||
|
||||
if (SUPPORT_BPF)
|
||||
target_link_libraries(kni bpf)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "tfe_mgr.h"
|
||||
#include <tsg/tsg_label.h>
|
||||
#include "kni_iouring.h"
|
||||
#include "kni_fieldstat.h"
|
||||
|
||||
#define BURST_MAX 1
|
||||
#define CALLER_SAPP 0
|
||||
@@ -49,6 +50,7 @@ enum intercept_error{
|
||||
enum kni_action{
|
||||
KNI_ACTION_NONE = 0x00,
|
||||
KNI_ACTION_INTERCEPT = 0x02,
|
||||
KNI_ACTION_NO_INTERCEPT = 0x03,
|
||||
KNI_ACTION_BYPASS = 0x80
|
||||
};
|
||||
|
||||
@@ -146,7 +148,7 @@ struct pme_info{
|
||||
int has_dup_syn_ack;
|
||||
struct dup_traffic_dabloom_key *syn_packet;
|
||||
struct dup_traffic_dabloom_key *syn_ack_packet;
|
||||
struct _traffic_info traffic_info;
|
||||
struct traffic_info traffic_info;
|
||||
//for kni dynamic bypass
|
||||
int thread_seq;
|
||||
int is_dynamic_bypass;
|
||||
@@ -156,6 +158,7 @@ struct pme_info{
|
||||
struct session_runtime_attribute *session_attribute;
|
||||
//for ssl passthrough reason
|
||||
char ssl_passthrough_reason[KNI_SYMBOL_MAX];
|
||||
struct proxy_metric_value proxy_metric_value;
|
||||
};
|
||||
|
||||
struct wrapped_packet{
|
||||
@@ -247,6 +250,7 @@ struct kni_handle{
|
||||
struct proxy_tcp_option pxy_tcp_option;
|
||||
// int session_attribute_id;
|
||||
int log_level;
|
||||
struct proxy_fieldstat *proxy_fieldstat;
|
||||
};
|
||||
|
||||
struct traceid2pme_search_cb_args{
|
||||
|
||||
75
entry/include/kni_fieldstat.h
Normal file
75
entry/include/kni_fieldstat.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef _KNI_FIELDSTAT_METRIC_H
|
||||
#define _KNI_FIELDSTAT_METRIC_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <MESA/fieldstat.h>
|
||||
|
||||
|
||||
enum proxy_metrics_column
|
||||
{
|
||||
PROXY_METRIC_COLUMN_HIT_COUNT = 0,
|
||||
PROXY_METRIC_COLUMN_IN_BYTES,
|
||||
PROXY_METRIC_COLUMN_OUT_BYTES,
|
||||
PROXY_METRIC_COLUMN_IN_PKTS,
|
||||
PROXY_METRIC_COLUMN_OUT_PKTS,
|
||||
PROXY_METRIC_COLUMN_MAX
|
||||
};
|
||||
|
||||
|
||||
struct proxy_fieldstat
|
||||
{
|
||||
int table_id;
|
||||
int n_thread;
|
||||
unsigned int column_ids[PROXY_METRIC_COLUMN_MAX];
|
||||
struct fieldstat_dynamic_instance *instance;
|
||||
};
|
||||
|
||||
struct proxy_metric_tag
|
||||
{
|
||||
int vsys_id;
|
||||
unsigned long long rule_id;
|
||||
unsigned char action;
|
||||
unsigned char pinning_status;
|
||||
};
|
||||
|
||||
|
||||
struct proxy_metric_value
|
||||
{
|
||||
int hit_count;
|
||||
int in_bytes;
|
||||
int out_bytes;
|
||||
int in_pkts;
|
||||
int out_pkts;
|
||||
};
|
||||
|
||||
|
||||
// struct proxy_fieldstat *proxy_fieldstat_new(char *app_name, int n_thread,
|
||||
// int interval_ms,
|
||||
// const char *telegraf_ip,
|
||||
// unsigned short telegraf_port,
|
||||
// void *local_logger);
|
||||
|
||||
// void proxy_fieldstat_free(struct proxy_fieldstat *pxy_fs);
|
||||
|
||||
void proxy_set_metric_value(struct proxy_fieldstat *pxy_fs,
|
||||
struct proxy_metric_tag *metric_tags,
|
||||
struct proxy_metric_value *metric_value,
|
||||
int thread_id);
|
||||
|
||||
struct proxy_fieldstat *proxy_fieldstat_init(const char *profile,
|
||||
const char *section,
|
||||
int n_thread,
|
||||
void *logger);
|
||||
|
||||
void proxy_fieldstat_destory(struct proxy_fieldstat *pxy_fs, void *logger);
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
235
entry/src/kni_fieldstat.cpp
Normal file
235
entry/src/kni_fieldstat.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
#include <stdlib.h>
|
||||
#include "kni_fieldstat.h"
|
||||
#include "kni_utils.h"
|
||||
|
||||
static int read_fieldstat_tags(struct proxy_metric_tag *metric_tags,
|
||||
struct fieldstat_tag tags[])
|
||||
{
|
||||
int n_tags = 0;
|
||||
|
||||
tags[n_tags].key = "vsys_id";
|
||||
tags[n_tags].value_type = 0;
|
||||
tags[n_tags].value_int = metric_tags->vsys_id;
|
||||
n_tags++;
|
||||
|
||||
tags[n_tags].key = "rule_id";
|
||||
tags[n_tags].value_type = 0;
|
||||
tags[n_tags].value_int = metric_tags->rule_id;
|
||||
n_tags++;
|
||||
|
||||
if(metric_tags->pinning_status == 1)
|
||||
{
|
||||
tags[n_tags].key = "pinning_status";
|
||||
tags[n_tags].value_type = 0;
|
||||
tags[n_tags].value_int = metric_tags->pinning_status;
|
||||
n_tags++;
|
||||
}
|
||||
|
||||
tags[n_tags].key = "action";
|
||||
tags[n_tags].value_type = 0;
|
||||
// tags[n_tags].value_int = (hit_no_intercept == 1 ? 3 : 2);
|
||||
tags[n_tags].value_int = metric_tags->action;
|
||||
n_tags++;
|
||||
|
||||
return n_tags;
|
||||
}
|
||||
|
||||
|
||||
void proxy_set_metric_value(struct proxy_fieldstat *pxy_fs,
|
||||
struct proxy_metric_tag *metric_tags,
|
||||
struct proxy_metric_value *metric_value,
|
||||
int thread_id)
|
||||
{
|
||||
int n_tags = 0;
|
||||
const char *metric_row_name = "proxy_rule_hits";
|
||||
struct fieldstat_tag fieldstat_tags[5];
|
||||
|
||||
n_tags = read_fieldstat_tags(metric_tags, fieldstat_tags);
|
||||
if(metric_value->hit_count > 0)
|
||||
{
|
||||
fieldstat_dynamic_table_metric_value_incrby(
|
||||
pxy_fs->instance,
|
||||
pxy_fs->table_id,
|
||||
pxy_fs->column_ids[PROXY_METRIC_COLUMN_HIT_COUNT],
|
||||
metric_row_name,
|
||||
metric_value->hit_count,
|
||||
fieldstat_tags,
|
||||
(size_t)n_tags,
|
||||
thread_id);
|
||||
}
|
||||
|
||||
if(metric_value->in_bytes > 0)
|
||||
{
|
||||
fieldstat_dynamic_table_metric_value_incrby(
|
||||
pxy_fs->instance,
|
||||
pxy_fs->table_id,
|
||||
pxy_fs->column_ids[PROXY_METRIC_COLUMN_IN_BYTES],
|
||||
metric_row_name,
|
||||
metric_value->in_bytes,
|
||||
fieldstat_tags,
|
||||
(size_t)n_tags,
|
||||
thread_id);
|
||||
}
|
||||
|
||||
if(metric_value->in_pkts > 0)
|
||||
{
|
||||
fieldstat_dynamic_table_metric_value_incrby(
|
||||
pxy_fs->instance,
|
||||
pxy_fs->table_id,
|
||||
pxy_fs->column_ids[PROXY_METRIC_COLUMN_IN_PKTS],
|
||||
metric_row_name,
|
||||
metric_value->in_pkts,
|
||||
fieldstat_tags,
|
||||
(size_t)n_tags,
|
||||
thread_id);
|
||||
}
|
||||
|
||||
if(metric_value->out_bytes > 0)
|
||||
{
|
||||
fieldstat_dynamic_table_metric_value_incrby(
|
||||
pxy_fs->instance,
|
||||
pxy_fs->table_id,
|
||||
pxy_fs->column_ids[PROXY_METRIC_COLUMN_OUT_BYTES],
|
||||
metric_row_name,
|
||||
metric_value->out_bytes,
|
||||
fieldstat_tags,
|
||||
(size_t)n_tags,
|
||||
thread_id);
|
||||
}
|
||||
|
||||
if(metric_value->out_pkts > 0)
|
||||
{
|
||||
fieldstat_dynamic_table_metric_value_incrby(
|
||||
pxy_fs->instance,
|
||||
pxy_fs->table_id,
|
||||
pxy_fs->column_ids[PROXY_METRIC_COLUMN_OUT_PKTS],
|
||||
metric_row_name,
|
||||
metric_value->out_pkts,
|
||||
fieldstat_tags,
|
||||
(size_t)n_tags,
|
||||
thread_id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct proxy_fieldstat *proxy_fieldstat_new(char *app_name, int n_thread,
|
||||
const char *telegraf_ip,
|
||||
unsigned short telegraf_port,
|
||||
int interval_ms,
|
||||
void *local_logger)
|
||||
{
|
||||
struct proxy_fieldstat *pxy_fs = NULL;
|
||||
|
||||
const char *column_field[PROXY_METRIC_COLUMN_MAX] = {
|
||||
"hit_count", "in_bytes","out_bytes", "in_pkts","out_pkts"};
|
||||
enum field_type column_type[PROXY_METRIC_COLUMN_MAX] = {
|
||||
FIELD_TYPE_COUNTER,
|
||||
FIELD_TYPE_COUNTER,
|
||||
FIELD_TYPE_COUNTER,
|
||||
FIELD_TYPE_COUNTER,
|
||||
FIELD_TYPE_COUNTER
|
||||
};
|
||||
|
||||
pxy_fs = (struct proxy_fieldstat *)calloc(1,sizeof(struct proxy_fieldstat));
|
||||
pxy_fs->instance = fieldstat_dynamic_instance_new(app_name, n_thread);
|
||||
|
||||
if(pxy_fs->instance == NULL)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
pxy_fs->n_thread = n_thread;
|
||||
fieldstat_dynamic_set_line_protocol_server(pxy_fs->instance, telegraf_ip,
|
||||
telegraf_port);
|
||||
fieldstat_dynamic_set_output_interval(pxy_fs->instance, interval_ms);
|
||||
|
||||
pxy_fs->table_id = fieldstat_register_dynamic_table(
|
||||
pxy_fs->instance,
|
||||
"proxy_rule_hits",
|
||||
column_field,
|
||||
column_type,
|
||||
(size_t)PROXY_METRIC_COLUMN_MAX,
|
||||
pxy_fs->column_ids);
|
||||
|
||||
if(pxy_fs->table_id < 0)
|
||||
{
|
||||
goto error;
|
||||
}
|
||||
|
||||
fieldstat_dynamic_instance_start(pxy_fs->instance);
|
||||
return pxy_fs;
|
||||
|
||||
error:
|
||||
if(pxy_fs)
|
||||
{
|
||||
free(pxy_fs);
|
||||
pxy_fs = NULL;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void proxy_fieldstat_free(struct proxy_fieldstat *pxy_fs)
|
||||
{
|
||||
if(pxy_fs)
|
||||
{
|
||||
if(pxy_fs->instance)
|
||||
{
|
||||
fieldstat_dynamic_instance_free(pxy_fs->instance);
|
||||
pxy_fs->instance = NULL;
|
||||
}
|
||||
free(pxy_fs);
|
||||
pxy_fs = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct proxy_fieldstat *proxy_fieldstat_init(const char *profile,
|
||||
const char *section,
|
||||
int n_thread,
|
||||
void *logger)
|
||||
{
|
||||
int interval_ms = 0;
|
||||
unsigned short telegraf_port = 0;
|
||||
char telegraf_ip[KNI_ADDR_MAX] = {0};
|
||||
char app_name[KNI_STRING_MAX] = {0};
|
||||
struct proxy_fieldstat *pxy_fs = NULL;
|
||||
|
||||
|
||||
MESA_load_profile_string_def(profile, section, "app_name", app_name,
|
||||
sizeof(app_name), "proxy_rule_hits");
|
||||
|
||||
MESA_load_profile_string_nodef(profile, section, "telegraf_ip",
|
||||
telegraf_ip, sizeof(telegraf_ip));
|
||||
|
||||
MESA_load_profile_short_nodef(profile, section, "telegraf_port",
|
||||
(short *)&(telegraf_port));
|
||||
|
||||
MESA_load_profile_int_def(profile, section, "interval_ms", &interval_ms,
|
||||
1000);
|
||||
|
||||
pxy_fs = proxy_fieldstat_new(app_name, n_thread, telegraf_ip,
|
||||
telegraf_port, interval_ms, logger);
|
||||
if (pxy_fs == NULL)
|
||||
{
|
||||
KNI_LOG_ERROR(logger, "proxy fieldstat init failed, error to create fieldstat metric.");
|
||||
return NULL;
|
||||
}
|
||||
KNI_LOG_ERROR(logger, "proxy fieldstat telegraf_ip : %s", telegraf_ip);
|
||||
KNI_LOG_ERROR(logger, "proxy fieldstat telegraf_port : %d", telegraf_port);
|
||||
KNI_LOG_ERROR(logger, "proxy fieldstat app_name : %s", app_name);
|
||||
KNI_LOG_ERROR(logger, "proxy fieldstat interval_ms : %d", interval_ms);
|
||||
|
||||
return pxy_fs;
|
||||
}
|
||||
|
||||
void proxy_fieldstat_destory(struct proxy_fieldstat *pxy_fs, void *logger)
|
||||
{
|
||||
if(pxy_fs)
|
||||
{
|
||||
proxy_fieldstat_free(pxy_fs);
|
||||
pxy_fs = NULL;
|
||||
}
|
||||
KNI_LOG_ERROR(logger, "Destory proxy fieldstat!");
|
||||
return;
|
||||
}
|
||||
|
||||
4
vendor/CMakeLists.txt
vendored
4
vendor/CMakeLists.txt
vendored
@@ -84,6 +84,10 @@ add_library(MESA_field_stat SHARED IMPORTED GLOBAL)
|
||||
set_property(TARGET MESA_field_stat PROPERTY IMPORTED_LOCATION ${MESA_FRAMEWORK_LIB_DIR}/libMESA_field_stat2.so)
|
||||
set_property(TARGET MESA_field_stat PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MESA_FRAMEWORK_INCLUDE_DIR})
|
||||
|
||||
add_library(fieldstat3 SHARED IMPORTED GLOBAL)
|
||||
set_property(TARGET fieldstat3 PROPERTY IMPORTED_LOCATION ${MESA_FRAMEWORK_LIB_DIR}/libfieldstat3.so)
|
||||
set_property(TARGET fieldstat3 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MESA_FRAMEWORK_INCLUDE_DIR})
|
||||
|
||||
add_library(rdkafka SHARED IMPORTED GLOBAL)
|
||||
set_property(TARGET rdkafka PROPERTY IMPORTED_LOCATION ${MESA_FRAMEWORK_LIB_DIR}/librdkafka.so)
|
||||
set_property(TARGET rdkafka PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MESA_FRAMEWORK_INCLUDE_DIR})
|
||||
|
||||
Reference in New Issue
Block a user