优化fieldstat3句柄创建
This commit is contained in:
@@ -6,6 +6,7 @@ enum RESOURCE_TYPE
|
|||||||
KAFKA_LOGGER,
|
KAFKA_LOGGER,
|
||||||
DEVICE_ID,
|
DEVICE_ID,
|
||||||
EFFECTIVE_DEVICE_TAG,
|
EFFECTIVE_DEVICE_TAG,
|
||||||
|
DYNAMIC_FIELDSTAT,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TABLE_TYPE
|
enum TABLE_TYPE
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#include <MESA/maat.h>
|
#include <MESA/maat.h>
|
||||||
#include <cjson/cJSON.h>
|
#include <cjson/cJSON.h>
|
||||||
#include <tfe_kafka_logger.h>
|
#include <tfe_kafka_logger.h>
|
||||||
|
#include <tfe_fieldstat.h>
|
||||||
#include <tfe_proxy.h>
|
#include <tfe_proxy.h>
|
||||||
#include <tfe_resource.h>
|
#include <tfe_resource.h>
|
||||||
|
|
||||||
@@ -17,9 +18,37 @@ struct maat_table_info
|
|||||||
|
|
||||||
static struct maat *static_maat = NULL;
|
static struct maat *static_maat = NULL;
|
||||||
static tfe_kafka_logger_t *kafka_logger = NULL;
|
static tfe_kafka_logger_t *kafka_logger = NULL;
|
||||||
|
static struct tfe_fieldstat_metric_t *dynamic_fieldstat = NULL;
|
||||||
static char *device_id = NULL;
|
static char *device_id = NULL;
|
||||||
static char *effective_device_tag=NULL;
|
static char *effective_device_tag=NULL;
|
||||||
|
|
||||||
|
static struct tfe_fieldstat_metric_t *create_fieldstat_instance(const char *profile, const char *section, int max_thread, void *logger)
|
||||||
|
{
|
||||||
|
int cycle=0;
|
||||||
|
unsigned short telegraf_port=0;
|
||||||
|
char telegraf_ip[TFE_STRING_MAX]={0};
|
||||||
|
char app_name[TFE_STRING_MAX]={0};
|
||||||
|
struct tfe_fieldstat_metric_t *dynamic_fieldstat=NULL;
|
||||||
|
|
||||||
|
MESA_load_profile_short_nodef(profile, section, "telegraf_port", (short *)&(telegraf_port));
|
||||||
|
MESA_load_profile_string_nodef(profile, section, "telegraf_ip", telegraf_ip, sizeof(telegraf_ip));
|
||||||
|
MESA_load_profile_string_def(profile, section, "app_name", app_name, sizeof(app_name), "metric");
|
||||||
|
MESA_load_profile_int_def(profile, section, "cycle", &cycle, 1000);
|
||||||
|
|
||||||
|
dynamic_fieldstat = tfe_fieldstat_metric_create(telegraf_ip, telegraf_port, app_name, cycle, max_thread, logger);
|
||||||
|
if (dynamic_fieldstat == NULL)
|
||||||
|
{
|
||||||
|
TFE_LOG_ERROR(logger, "tfe fieldstat init failed, error to create fieldstat metric.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
TFE_LOG_INFO(logger, "tfe fieldstat telegraf_ip : %s", telegraf_ip);
|
||||||
|
TFE_LOG_INFO(logger, "tfe fieldstat telegraf_port : %d", telegraf_port);
|
||||||
|
TFE_LOG_INFO(logger, "tfe fieldstat app_name : %s", app_name);
|
||||||
|
TFE_LOG_INFO(logger, "tfe fieldstat cycle : %d", cycle);
|
||||||
|
|
||||||
|
return dynamic_fieldstat;
|
||||||
|
}
|
||||||
|
|
||||||
static struct maat *create_maat_feather(const char *instance_name, const char *profile, const char *section, int max_thread, void *logger)
|
static struct maat *create_maat_feather(const char *instance_name, const char *profile, const char *section, int max_thread, void *logger)
|
||||||
{
|
{
|
||||||
struct maat *target=NULL;
|
struct maat *target=NULL;
|
||||||
@@ -311,6 +340,12 @@ int tfe_bussiness_resouce_init()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dynamic_fieldstat = create_fieldstat_instance(profile_path, "proxy_hits", thread_num, g_default_logger);
|
||||||
|
if(!dynamic_fieldstat)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
device_id = cerate_device_id(profile_path, "kafka", g_default_logger);
|
device_id = cerate_device_id(profile_path, "kafka", g_default_logger);
|
||||||
|
|
||||||
effective_device_tag = create_effective_device_tag(profile_path, "MAAT", g_default_logger);
|
effective_device_tag = create_effective_device_tag(profile_path, "MAAT", g_default_logger);
|
||||||
@@ -335,6 +370,8 @@ void *tfe_bussiness_resouce_get(enum RESOURCE_TYPE type)
|
|||||||
return device_id;
|
return device_id;
|
||||||
case EFFECTIVE_DEVICE_TAG:
|
case EFFECTIVE_DEVICE_TAG:
|
||||||
return effective_device_tag;
|
return effective_device_tag;
|
||||||
|
case DYNAMIC_FIELDSTAT:
|
||||||
|
return dynamic_fieldstat;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
[doh]
|
[doh]
|
||||||
enable=1
|
enable=1
|
||||||
|
|
||||||
[proxy_hits]
|
|
||||||
cycle=1000
|
|
||||||
telegraf_port=8400
|
|
||||||
telegraf_ip=127.0.0.1
|
|
||||||
app_name="proxy_rule_hits"
|
|
||||||
|
|
||||||
[maat]
|
[maat]
|
||||||
table_appid=TSG_OBJ_APP_ID
|
table_appid=TSG_OBJ_APP_ID
|
||||||
table_addr=TSG_SECURITY_ADDR
|
table_addr=TSG_SECURITY_ADDR
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
[debug]
|
[debug]
|
||||||
enable_plugin=1
|
enable_plugin=1
|
||||||
|
|
||||||
[proxy_hits]
|
|
||||||
cycle=1000
|
|
||||||
telegraf_port=8400
|
|
||||||
telegraf_ip=127.0.0.1
|
|
||||||
app_name="proxy_rule_hits"
|
|
||||||
|
|
||||||
[log]
|
[log]
|
||||||
entrance_id=0
|
entrance_id=0
|
||||||
# default 1, if enable "en_sendlog", the iterm "tfe.conf [kafka] enable" must set 1
|
# default 1, if enable "en_sendlog", the iterm "tfe.conf [kafka] enable" must set 1
|
||||||
|
|||||||
@@ -215,3 +215,9 @@ maat_redis_db_index=4
|
|||||||
# iris mode conf iterm
|
# iris mode conf iterm
|
||||||
full_cfg_dir=pangu_policy/full/index/
|
full_cfg_dir=pangu_policy/full/index/
|
||||||
inc_cfg_dir=pangu_policy/inc/index/
|
inc_cfg_dir=pangu_policy/inc/index/
|
||||||
|
|
||||||
|
[proxy_hits]
|
||||||
|
cycle=1000
|
||||||
|
telegraf_port=8400
|
||||||
|
telegraf_ip=127.0.0.1
|
||||||
|
app_name="proxy_rule_hits"
|
||||||
@@ -662,21 +662,6 @@ static void doh_process_req(const struct tfe_stream *stream, const struct tfe_ht
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tfe_fieldstat_metric_t *doh_fieldstat_init(const char* profile, const char *section, int max_thread)
|
|
||||||
{
|
|
||||||
int cycle=0;
|
|
||||||
unsigned short telegraf_port=0;
|
|
||||||
char telegraf_ip[TFE_STRING_MAX]={0};
|
|
||||||
char app_name[TFE_STRING_MAX]={0};
|
|
||||||
|
|
||||||
MESA_load_profile_short_nodef(profile, section, "telegraf_port", (short *)&(telegraf_port));
|
|
||||||
MESA_load_profile_string_nodef(profile, section, "telegraf_ip", telegraf_ip, sizeof(telegraf_ip));
|
|
||||||
MESA_load_profile_string_def(profile, section, "app_name", app_name, sizeof(app_name), "metric");
|
|
||||||
MESA_load_profile_int_def(profile, section, "cycle", &cycle, 1000);
|
|
||||||
|
|
||||||
return tfe_fieldstat_metric_create(telegraf_ip, telegraf_port, app_name, cycle, max_thread, g_doh_conf->local_logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
int doh_on_init(struct tfe_proxy *proxy)
|
int doh_on_init(struct tfe_proxy *proxy)
|
||||||
{
|
{
|
||||||
const char *profile = "./conf/doh/doh.conf";
|
const char *profile = "./conf/doh/doh.conf";
|
||||||
@@ -695,7 +680,6 @@ int doh_on_init(struct tfe_proxy *proxy)
|
|||||||
|
|
||||||
g_doh_conf->thread_num = tfe_proxy_get_work_thread_count();
|
g_doh_conf->thread_num = tfe_proxy_get_work_thread_count();
|
||||||
g_doh_conf->local_logger = MESA_create_runtime_log_handle("doh", RLOG_LV_DEBUG);
|
g_doh_conf->local_logger = MESA_create_runtime_log_handle("doh", RLOG_LV_DEBUG);
|
||||||
g_doh_conf->fieldstat = doh_fieldstat_init(profile, "proxy_hits", g_doh_conf->thread_num);
|
|
||||||
|
|
||||||
g_doh_conf->gc_evbase = tfe_proxy_get_gc_evbase();
|
g_doh_conf->gc_evbase = tfe_proxy_get_gc_evbase();
|
||||||
g_doh_conf->fs_handle = tfe_proxy_get_fs_handle();
|
g_doh_conf->fs_handle = tfe_proxy_get_fs_handle();
|
||||||
@@ -876,7 +860,7 @@ int doh_on_data(const struct tfe_stream *stream, const struct tfe_http_session *
|
|||||||
void doh_send_metric_log(const struct tfe_stream * stream, struct doh_ctx *ctx, unsigned int thread_id)
|
void doh_send_metric_log(const struct tfe_stream * stream, struct doh_ctx *ctx, unsigned int thread_id)
|
||||||
{
|
{
|
||||||
size_t c2s_byte_num = 0, s2c_byte_num =0;
|
size_t c2s_byte_num = 0, s2c_byte_num =0;
|
||||||
struct tfe_fieldstat_metric_t *fieldstat = g_doh_conf->fieldstat;
|
struct tfe_fieldstat_metric_t *fieldstat = (struct tfe_fieldstat_metric_t *)tfe_bussiness_resouce_get(DYNAMIC_FIELDSTAT);
|
||||||
|
|
||||||
fieldstat->tags[thread_id][TAG_RULE_ID].value_int = ctx->result->config_id;
|
fieldstat->tags[thread_id][TAG_RULE_ID].value_int = ctx->result->config_id;
|
||||||
fieldstat->tags[thread_id][TAG_ACTION].value_int = 48;
|
fieldstat->tags[thread_id][TAG_ACTION].value_int = 48;
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ struct doh_conf
|
|||||||
struct event *gcev;
|
struct event *gcev;
|
||||||
struct event_base *gc_evbase;
|
struct event_base *gc_evbase;
|
||||||
screen_stat_handle_t fs_handle;
|
screen_stat_handle_t fs_handle;
|
||||||
struct tfe_fieldstat_metric_t *fieldstat;
|
|
||||||
|
|
||||||
struct maat *maat;
|
struct maat *maat;
|
||||||
struct maat_table tables[TYPE_MAX];
|
struct maat_table tables[TYPE_MAX];
|
||||||
|
|||||||
@@ -170,7 +170,6 @@ struct tsg_proxy_rt
|
|||||||
struct event_base* gc_evbase;
|
struct event_base* gc_evbase;
|
||||||
struct event* gcev;
|
struct event* gcev;
|
||||||
|
|
||||||
struct tfe_fieldstat_metric_t *fieldstat;
|
|
||||||
struct tsg_lua_script lua_script;
|
struct tsg_lua_script lua_script;
|
||||||
Ratelimiter_handle_t ratelimiter;
|
Ratelimiter_handle_t ratelimiter;
|
||||||
int enable_rate;
|
int enable_rate;
|
||||||
@@ -192,21 +191,6 @@ static void proxy_http_gc_cb(evutil_socket_t fd, short what, void * arg)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tfe_fieldstat_metric_t *proxy_fieldstat_init(const char* profile_path, const char *section, int max_thread)
|
|
||||||
{
|
|
||||||
int cycle=0;
|
|
||||||
unsigned short telegraf_port=0;
|
|
||||||
char telegraf_ip[TFE_STRING_MAX]={0};
|
|
||||||
char app_name[TFE_STRING_MAX]={0};
|
|
||||||
|
|
||||||
MESA_load_profile_short_nodef(profile_path, section, "telegraf_port", (short *)&(telegraf_port));
|
|
||||||
MESA_load_profile_string_nodef(profile_path, section, "telegraf_ip", telegraf_ip, sizeof(telegraf_ip));
|
|
||||||
MESA_load_profile_string_def(profile_path, section, "app_name", app_name, sizeof(app_name), "metric");
|
|
||||||
MESA_load_profile_int_def(profile_path, section, "cycle", &cycle, 1000);
|
|
||||||
|
|
||||||
return tfe_fieldstat_metric_create(telegraf_ip, telegraf_port, app_name, cycle, max_thread, g_proxy_rt->local_logger);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void proxy_http_stat_init(struct tsg_proxy_rt * pangu_runtime)
|
static void proxy_http_stat_init(struct tsg_proxy_rt * pangu_runtime)
|
||||||
{
|
{
|
||||||
int i=0;
|
int i=0;
|
||||||
@@ -1188,8 +1172,6 @@ int proxy_http_init(struct tfe_proxy * proxy)
|
|||||||
proxy_http_stat_init(g_proxy_rt);
|
proxy_http_stat_init(g_proxy_rt);
|
||||||
|
|
||||||
g_proxy_rt->ratelimiter=ratelimit_handle_create(profile_path, "ratelimit");
|
g_proxy_rt->ratelimiter=ratelimit_handle_create(profile_path, "ratelimit");
|
||||||
g_proxy_rt->fieldstat=proxy_fieldstat_init(profile_path, "proxy_hits", g_proxy_rt->thread_num);
|
|
||||||
|
|
||||||
if(http_lua_handle_create(&g_proxy_rt->lua_script, g_proxy_rt->thread_num, "tfe") <0)
|
if(http_lua_handle_create(&g_proxy_rt->lua_script, g_proxy_rt->thread_num, "tfe") <0)
|
||||||
{
|
{
|
||||||
goto error_out;
|
goto error_out;
|
||||||
@@ -3284,7 +3266,7 @@ void proxy_send_metric_log(const struct tfe_stream * stream, struct proxy_http_c
|
|||||||
proxy_action_map[PX_ACTION_REJECT]="deny";
|
proxy_action_map[PX_ACTION_REJECT]="deny";
|
||||||
proxy_action_map[PX_ACTION_WHITELIST]="allow";
|
proxy_action_map[PX_ACTION_WHITELIST]="allow";
|
||||||
const char *manipulate_action_map[]= {"redirect","block","replace","hijack","insert","edit_element","run_script"};
|
const char *manipulate_action_map[]= {"redirect","block","replace","hijack","insert","edit_element","run_script"};
|
||||||
struct tfe_fieldstat_metric_t *fieldstat = g_proxy_rt->fieldstat;
|
struct tfe_fieldstat_metric_t *fieldstat = (struct tfe_fieldstat_metric_t *)tfe_bussiness_resouce_get(DYNAMIC_FIELDSTAT);
|
||||||
|
|
||||||
for(i=0; i< ctx->n_enforce; i++)
|
for(i=0; i< ctx->n_enforce; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user