添加sender_scm开关

This commit is contained in:
崔一鸣
2019-06-02 16:15:31 +08:00
committed by luqiuwen
parent cc126a73a1
commit e4f490fcd3
3 changed files with 29 additions and 4 deletions

View File

@@ -43,5 +43,6 @@ statsd_port=8126
histogram_bins=0.50,0.80,0.9,0.95
[sender_scm]
switch = 1
kni_ip = 192.168.10.37
kni_port = 8888

View File

@@ -1,4 +1,4 @@
struct sender_scm;
struct sender_scm* sender_scm_init(const char *profile, void *logger);
void send_scm_destroy(struct sender_scm *sender);
int sender_scm_cmsg_send(struct sender_scm *sender, struct tfe_cmsg *cmsg);
struct sender_scm* sender_scm_init(const char *profile, const char *section, void *logger);

View File

@@ -9,6 +9,7 @@ struct sender_scm
{
int sockfd;
struct sockaddr_in server_addr;
int send_switch;
void *logger;
};
@@ -24,16 +25,29 @@ void send_scm_destroy(struct sender_scm *sender)
FREE(&sender);
}
struct sender_scm* sender_scm_init(const char *profile, void *logger)
/* TODO:
0: switch
1. no_blocking + eagain
2. libevent
3. field_stat: success/failed
*/
struct sender_scm* sender_scm_init(const char *profile, const char *section, void *logger)
{
const char *section = "sender_scm";
char kni_ip[INET_ADDRSTRLEN] = "";
int send_switch = -1;
int kni_port = -1;
int sockfd = -1;
struct sockaddr_in server_addr;
struct sender_scm *sender = ALLOC(struct sender_scm, 1);
sender->logger = logger;
int ret = MESA_load_profile_string_nodef(profile, section, "kni_ip", kni_ip, sizeof(kni_ip));
int ret = MESA_load_profile_int_nodef(profile, section, "send_switch", &send_switch);
if(ret < 0)
{
TFE_LOG_ERROR(logger, "MESA_prof_load: send_switch not set, profile is %s, section is %s", profile, section);
goto error_out;
}
ret = MESA_load_profile_string_nodef(profile, section, "kni_ip", kni_ip, sizeof(kni_ip));
if(ret < 0)
{
TFE_LOG_ERROR(logger, "MESA_prof_load: kni_ip not set, profile is %s, section is %s", profile, section);
@@ -47,6 +61,11 @@ struct sender_scm* sender_scm_init(const char *profile, void *logger)
}
TFE_LOG_INFO(logger, "MESA_prof_load, [%s]:\n kni_ip: %s\n kni_port: %d",
section, kni_ip, kni_port);
sender->send_switch = send_switch;
if(send_switch == 0)
{
return sender;
}
//create socket
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockfd < 0)
@@ -71,6 +90,11 @@ error_out:
int sender_scm_cmsg_send(struct sender_scm *sender, struct tfe_cmsg *cmsg)
{
void *logger = sender->logger;
int send_switch = sender->send_switch;
if(send_switch == 0)
{
return 0;
}
uint16_t bufflen = tfe_cmsg_serialize_size_get(cmsg);
unsigned char *buff = ALLOC(unsigned char, bufflen);
uint16_t serialize_len = 0;