summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2020-11-12 21:51:38 +0800
committerlijia <[email protected]>2020-11-12 21:51:38 +0800
commitcd822b1e60cb55c65421d97d1ce966efe1a47ad0 (patch)
tree25c7e67c2f8cf64553334315f65fafe2fbbba19e
parentd8bc3078ec8a2c0ae4343d6aa92dc2d67159a1fa (diff)
支持prometheus状态监控.v4.2.6
-rw-r--r--bin/etc/sapp.toml5
-rw-r--r--include/private/sapp_global_val.h8
-rw-r--r--src/config/config_parse.cpp18
-rw-r--r--src/entry/sapp_main.c2
-rw-r--r--src/inner_plug/sapp_assistant.cpp16
5 files changed, 47 insertions, 2 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml
index ffdf87a..3bd26f4 100644
--- a/bin/etc/sapp.toml
+++ b/bin/etc/sapp.toml
@@ -154,6 +154,11 @@ dictator_enable=1
### note, metric_type option value: [default, json]
metric_type = default
app_name=sapp
+
+ [profiling.log.prometheus]
+ prometheus_enabled=1
+ prometheus_port=9273
+ prometheus_url_path="/metrics"
[TOOLS]
[tools.pkt_dump]
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h
index f9216dd..542eaa3 100644
--- a/include/private/sapp_global_val.h
+++ b/include/private/sapp_global_val.h
@@ -169,12 +169,20 @@ typedef struct{
sapp_config_profiling_log_remote_field_stat2_t field_stat2;
}sapp_config_profiling_log_remote_t;
+typedef struct{
+ int enabled;
+ int port; /* host order */
+ char url_path[NAME_MAX];
+}sapp_config_profiling_log_prometheus_t;
+
+
typedef struct{
int level;
int interval;
sapp_config_profiling_log_local_t local;
sapp_config_profiling_log_remote_t remote;
+ sapp_config_profiling_log_prometheus_t prometheus;
}sapp_config_profiling_log_t;
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index 183cc75..b20918e 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -323,10 +323,12 @@ static int parse_vlan_flipping_map_config(void)
ret = sscanf(line_cont, "%u %u %u", &c_router_vlan_id, &i_router_vlan_id, &mac_flip_enable);
if(ret != 3){
sapp_log(30, ~0, ~0, "[Error]parse sapp.toml->vlan_flipping_cfg_file:%s, line:%s error!", filename, line_cont);
+ fclose(fp);
return -1;
}
if(c_router_vlan_id>= 4096 || i_router_vlan_id >= 4096){
sapp_log(30, ~0, ~0, "[Error]parse sapp.toml->vlan_flipping_cfg_file:%s line:%s error, vlan id must in range[1,4095]!", filename, line_cont);
+ fclose(fp);
return -1;
}
vlan_map[c_router_vlan_id].this_vlan_route_location = 'C';
@@ -353,6 +355,7 @@ static int parse_vlan_flipping_map_config(void)
}
}
+ fclose(fp);
return 0;
}
@@ -490,6 +493,7 @@ static int parse_asymmetric_addr_layer_config(void)
sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, inlavid:%s",
sapp_global_val->config.packet_io.packet_io_tunnel.asymmetric_addr_layer_cfg_file,
line_cont);
+ fclose(fp);
return -1;
}
@@ -513,6 +517,7 @@ static int parse_asymmetric_addr_layer_config(void)
debug_layer_index_str);
}
+ fclose(fp);
return 0;
}
@@ -552,6 +557,7 @@ static int parse_asymmetric_presence_layer_config(void)
if(ret != 3){
sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse sapp.toml->asymmetric_presence_layer_cfg_file:%s error, invalid config:%s",
sapp_global_val->config.packet_io.packet_io_tunnel.asymmetric_presence_layer_cfg_file, line_cont);
+ fclose(fp);
return -1;
}
@@ -560,6 +566,7 @@ static int parse_asymmetric_presence_layer_config(void)
sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, inlavid:%s",
sapp_global_val->config.packet_io.packet_io_tunnel.asymmetric_presence_layer_cfg_file,
line_cont);
+ fclose(fp);
return -1;
}
@@ -568,6 +575,7 @@ static int parse_asymmetric_presence_layer_config(void)
sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, inlavid:%s",
sapp_global_val->config.packet_io.packet_io_tunnel.asymmetric_presence_layer_cfg_file,
line_cont);
+ fclose(fp);
return -1;
}
@@ -576,6 +584,7 @@ static int parse_asymmetric_presence_layer_config(void)
sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, inlavid:%s",
sapp_global_val->config.packet_io.packet_io_tunnel.asymmetric_presence_layer_cfg_file,
line_cont);
+ fclose(fp);
return -1;
}
@@ -598,7 +607,7 @@ static int parse_asymmetric_presence_layer_config(void)
}
}
-
+ fclose(fp);
return 0;
}
@@ -1178,6 +1187,13 @@ int sapp_parse_config(void)
tomlc99_wrap_load_int_def(default_config_file, (char *)"profiling.log.remote", (char *)"enabled", (int *)&pconfig->profiling.log.remote.enabled, 0);
tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote", (char *)"server_ip", pconfig->profiling.log.remote.server_ip, INET_ADDRSTRLEN, "#");
tomlc99_wrap_load_int_def(default_config_file, (char *)"profiling.log.remote", (char *)"server_port", (int *)&pconfig->profiling.log.remote.server_port, 0);
+
+ /******************************* PROFILING.LOG.prometheus **********************/
+ tomlc99_wrap_load_int_def(default_config_file, (char *)"profiling.log.prometheus", (char *)"prometheus_enabled", (int *)&pconfig->profiling.log.prometheus.enabled, 1);
+ tomlc99_wrap_load_int_def(default_config_file, (char *)"profiling.log.prometheus", (char *)"prometheus_port", (int *)&pconfig->profiling.log.prometheus.port, 9273);
+ tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.prometheus", (char *)"prometheus_url_path", pconfig->profiling.log.prometheus.url_path, NAME_MAX, "/metrics");
+
+
#if 0
//tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote", (char *)"remote_send_out_type", pconfig->profiling.log.remote.remote_send_out_type, NAME_MAX, "field_stat2");
/******************************* PROFILING.LOG.remote.field_stat2 **********************/
diff --git a/src/entry/sapp_main.c b/src/entry/sapp_main.c
index 4502e06..9835518 100644
--- a/src/entry/sapp_main.c
+++ b/src/entry/sapp_main.c
@@ -5,7 +5,7 @@
extern "C" {
#endif
-const unsigned char MESA_art_log[] =
+static const unsigned char MESA_art_log[] =
{
0x50, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, 0x0D, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x5F, 0x5F, 0x20, 0x20, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F, 0x5F,
diff --git a/src/inner_plug/sapp_assistant.cpp b/src/inner_plug/sapp_assistant.cpp
index dc0ff7b..f6cb7ea 100644
--- a/src/inner_plug/sapp_assistant.cpp
+++ b/src/inner_plug/sapp_assistant.cpp
@@ -910,6 +910,17 @@ static int sapp_fs2_init(void)
return -1;
}
+ if(sapp_global_val->config.profiling.log.prometheus.enabled){
+ FS_library_set_prometheus_port((unsigned short)sapp_global_val->config.profiling.log.prometheus.port);
+ FS_library_set_prometheus_url_path(sapp_global_val->config.profiling.log.prometheus.url_path);
+ if(FS_library_init() < 0){
+ sapp_log(RLOG_LV_FATAL, 30, 30, "FS_library_init() error, port:%d, url:%s\n",
+ sapp_global_val->config.profiling.log.prometheus.port,
+ sapp_global_val->config.profiling.log.prometheus.url_path);
+ return -1;
+ }
+ }
+
fs2_handle = sapp_global_val->individual_fixed.field_stat2_para.field_stat2_handle;
if(fs2_remote_enabled){
sapp_global_val->individual_fixed.profiling_log_remote_handle = fs2_handle;
@@ -944,6 +955,11 @@ static int sapp_fs2_init(void)
}
FS_set_para(fs2_handle, METRIS_FORMAT, &sapp_global_val->config.profiling.log.remote.field_stat2.metrics_type, sizeof(int));
+
+ if(sapp_global_val->config.profiling.log.prometheus.enabled){
+ fs2_opt = 1;
+ FS_set_para(fs2_handle, OUTPUT_PROMETHEUS, &fs2_opt, sizeof(int));
+ }
pfs_para->fs_id_count_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Pkt");
pfs_para->fs_id_length_array[SAPP_STAT_RCV_ETHERNET] = FS_register(fs2_handle, FS_STYLE_FIELD, FS_CALC_CURRENT, "Eth_Bit");