#44 tfe和cache的FieldStat2输出到statsd server.

This commit is contained in:
zhengchao
2018-11-23 09:40:42 +08:00
parent 369bdebbad
commit 88849c9890
2 changed files with 34 additions and 6 deletions

View File

@@ -279,8 +279,15 @@ int tfe_stat_init(struct tfe_proxy * proxy, const char * profile)
int value = 0, i = 0;
screen_stat_handle_t fs_handle = NULL;
char statsd_server_ip[TFE_SYMBOL_MAX];
char histogram_bins[TFE_SYMBOL_MAX];
int statsd_server_port=0;
MESA_load_profile_string_def(profile, "STAT", "statsd_server", statsd_server_ip,
sizeof(statsd_server_ip), "");
MESA_load_profile_int_def(profile, "STAT", "statsd_port", &(statsd_server_port), 0);
MESA_load_profile_string_def(profile, "STAT", "histogram_bins",
histogram_bins, sizeof(histogram_bins), "0.5,0.8,0.9,0.95");
/* TODO: Read Stat-D server and port from profile */
fs_handle = FS_create_handle();
FS_set_para(fs_handle, OUTPUT_DEVICE, fieldstat_output, (int)strlen(fieldstat_output) + 1);
FS_set_para(fs_handle, APP_NAME, app_name, (int)strlen(app_name) + 1);
@@ -289,6 +296,12 @@ int tfe_stat_init(struct tfe_proxy * proxy, const char * profile)
FS_set_para(fs_handle, PRINT_MODE, &value, sizeof(value));
value = 0;
FS_set_para(fs_handle, CREATE_THREAD, &value, sizeof(value));
if(strlen(statsd_server_ip)>0 && statsd_server_port!=0)
{
FS_set_para(fs_handle, STATS_SERVER_IP, statsd_server_ip, strlen(statsd_server_ip)+1);
FS_set_para(fs_handle, STATS_SERVER_PORT, &(statsd_server_port), sizeof(statsd_server_port));
}
FS_set_para(fs_handle, HISTOGRAM_GLOBAL_BINS, histogram_bins, strlen(histogram_bins)+1);
for (i = 0; i < TFE_STAT_MAX; i++)
{

View File

@@ -186,11 +186,11 @@ static void set_stat_spec(struct cache_stat_sepc* spec, const char* name, enum f
spec->calc_type=calc_type;
return;
}
void cache_stat_init(struct cache_handle* cache)
void cache_stat_init(struct cache_handle* cache,
const char* statsd_server_ip, int statsd_server_port, const char*histogram_bins)
{
const char* fieldstat_output="./cache.fieldstat";
const char* app_name="tango_cache";
const char* obj_size_bins_KB="0.5,0.8,0.9,0.95";
const char* app_name="tfe_cache";
int value=0, i=0;
screen_stat_handle_t fs_handle=NULL;
@@ -201,7 +201,12 @@ void cache_stat_init(struct cache_handle* cache)
value=0;
FS_set_para(fs_handle, CREATE_THREAD, &value, sizeof(value));
FS_set_para(fs_handle, APP_NAME, app_name, strlen(app_name)+1);
FS_set_para(fs_handle, HISTOGRAM_GLOBAL_BINS, obj_size_bins_KB, strlen(obj_size_bins_KB)+1);
FS_set_para(fs_handle, HISTOGRAM_GLOBAL_BINS, histogram_bins, strlen(histogram_bins)+1);
if(strlen(statsd_server_ip)>0 && statsd_server_port!=0)
{
FS_set_para(fs_handle, STATS_SERVER_IP, statsd_server_ip, strlen(statsd_server_ip)+1);
FS_set_para(fs_handle, STATS_SERVER_PORT, &(statsd_server_port), sizeof(statsd_server_port));
}
cache->fs_handle=fs_handle;
@@ -693,7 +698,17 @@ struct cache_handle* create_web_cache_handle(const char* profile_path, const cha
0, cache);
cache->ref_feather=feather;
}
cache_stat_init(cache);
char statsd_server_ip[TFE_SYMBOL_MAX];
char histogram_bins[TFE_SYMBOL_MAX];
int statsd_server_port=0;
MESA_load_profile_string_def(profile_path, section, "statsd_server", statsd_server_ip,
sizeof(statsd_server_ip), "");
MESA_load_profile_int_def(profile_path, section, "statsd_port", &(statsd_server_port), 0);
MESA_load_profile_string_def(profile_path, section, "histogram_bins",
histogram_bins, sizeof(histogram_bins), "0.5,0.8,0.9,0.95");
cache_stat_init(cache, statsd_server_ip, statsd_server_port, histogram_bins);
return cache;
error_out:
free(cache);