MT#11157 Add separate mysql handler for the stats db

- use separate user,pass,port,db for the stats database connection
    - cosmetic change in the DEFAULT_STATS definition names
    - add db connection info logging for PROV and STATS

Change-Id: I389bed46c634ac973616335581d7a7495d5866a3
changes/95/1095/2
Kirill Solomko 10 years ago
parent 2e2b42262e
commit d66262ccfc

@ -26,8 +26,12 @@ char *config_prov_pass = MEDIATOR_DEFAULT_PROVPASS;
char *config_prov_db = MEDIATOR_DEFAULT_PROVDB;
unsigned int config_prov_port = MEDIATOR_DEFAULT_PROVPORT;
char *config_stats_host = MEDIATOR_DEFAULT_STATSHOST;
char *config_stats_user = MEDIATOR_DEFAULT_STATSUSER;
char *config_stats_pass = MEDIATOR_DEFAULT_STATSPASS;
char *config_stats_db = MEDIATOR_DEFAULT_STATSDB;
med_stats_period_t config_stats_period = MEDIATOR_DEFAULT_STATS_PERIOD;
unsigned int config_stats_port = MEDIATOR_DEFAULT_STATSPORT;
med_stats_period_t config_stats_period = MEDIATOR_DEFAULT_STATSPERIOD;
static u_int8_t config_pid_path_free = 0;
@ -46,6 +50,9 @@ static u_int8_t config_prov_user_free = 0;
static u_int8_t config_prov_pass_free = 0;
static u_int8_t config_prov_db_free = 0;
static u_int8_t config_stats_host_free = 0;
static u_int8_t config_stats_user_free = 0;
static u_int8_t config_stats_pass_free = 0;
static u_int8_t config_stats_db_free = 0;
static void config_help(const char *self)
@ -71,6 +78,10 @@ static void config_help(const char *self)
" -R\tThe prov db user (default = '%s').\n" \
" -A\tThe prov db pass (default = '%s').\n" \
" -N\tThe prov db name (default = '%s').\n" \
" -Z\tThe stats db host (default = '%s').\n" \
" -z\tThe stats db port (default = '%d').\n" \
" -W\tThe stats db user (default = '%s').\n" \
" -w\tThe stats db pass (default = '%s').\n" \
" -X\tThe stats db name (default = '%s').\n" \
" -x\tThe stats db period (default = '%d', 1=hour, 2=day, 3=month).\n" \
" -?\tDisplays this message.\n",
@ -78,14 +89,15 @@ static void config_help(const char *self)
config_med_host, config_med_port, config_med_user, config_med_pass, config_med_db,
config_cdr_host, config_cdr_port, config_cdr_user, config_cdr_pass, config_cdr_db,
config_prov_host, config_prov_port, config_prov_user, config_prov_pass, config_prov_db,
config_stats_db, config_stats_period);
config_stats_host, config_stats_port, config_stats_user, config_stats_pass, config_stats_db,
config_stats_period);
}
int config_parse_cmdopts(int argc, char **argv)
{
int c;
while((c = getopt(argc, argv, "D:i:dl?h:u:p:b:o:H:U:P:B:O:S:T:R:A:N:X:x:")) != -1)
while((c = getopt(argc, argv, "D:i:dl?h:u:p:b:o:H:U:P:B:O:S:T:R:A:N:Z:z:W:w:X:x:")) != -1)
{
if(c == '?')
{
@ -181,6 +193,25 @@ int config_parse_cmdopts(int argc, char **argv)
{
config_prov_port = atoi(optarg);
}
else if(c == 'Z')
{
config_stats_host = (char*)strdup(optarg);
config_stats_host_free = 1;
}
else if(c == 'z')
{
config_stats_port = atoi(optarg);
}
else if(c == 'W')
{
config_stats_user = (char*)strdup(optarg);
config_stats_user_free = 1;
}
else if(c == 'w')
{
config_stats_pass = (char*)strdup(optarg);
config_stats_pass_free = 1;
}
else if(c == 'X')
{
config_stats_db = (char*)strdup(optarg);
@ -249,6 +280,18 @@ void config_cleanup()
{
free(config_prov_db);
}
if(config_stats_host_free)
{
free(config_stats_host);
}
if(config_stats_user_free)
{
free(config_stats_user);
}
if(config_stats_pass_free)
{
free(config_stats_pass);
}
if(config_stats_db_free)
{
free(config_stats_db);

@ -26,6 +26,10 @@ extern char *config_prov_user;
extern char *config_prov_pass;
extern char *config_prov_db;
extern char *config_stats_host;
extern unsigned int config_stats_port;
extern char *config_stats_user;
extern char *config_stats_pass;
extern char *config_stats_db;
extern med_stats_period_t config_stats_period;

@ -17,5 +17,9 @@ PROV_PORT="3306"
PROV_USER="mediator"
PROV_PASS='GimmeAllUr$$$'
PROV_DB="provisioning"
STATS_HOST="localhost"
STATS_PORT="3306"
STATS_USER="mediator"
STATS_PASS='GimmeAllUr$$$'
STATS_DB="sipstats"
STATS_PERIOD=1

@ -59,6 +59,10 @@ OPTIONS=""
[ -z "$PROV_USER" ] || OPTIONS="$OPTIONS -R $PROV_USER"
[ -z "$PROV_PASS" ] || OPTIONS="$OPTIONS -A $PROV_PASS"
[ -z "$PROV_DB" ] || OPTIONS="$OPTIONS -N $PROV_DB"
[ -z "$STATS_HOST" ] || OPTIONS="$OPTIONS -Z $STATS_HOST"
[ -z "$STATS_PORT" ] || OPTIONS="$OPTIONS -z $STATS_PORT"
[ -z "$STATS_USER" ] || OPTIONS="$OPTIONS -W $STATS_USER"
[ -z "$STATS_PASS" ] || OPTIONS="$OPTIONS -w $STATS_PASS"
[ -z "$STATS_DB" ] || OPTIONS="$OPTIONS -X $STATS_DB"
[ -z "$STATS_PERIOD" ] || OPTIONS="$OPTIONS -x $STATS_PERIOD"
if test "$FORK" = "yes" ; then

@ -199,6 +199,10 @@ int main(int argc, char **argv)
config_med_host, config_med_port, config_med_user, config_med_db);
syslog(LOG_INFO, "CDR acc database host='%s', port='%d', user='%s', name='%s'",
config_cdr_host, config_cdr_port, config_cdr_user, config_cdr_db);
syslog(LOG_INFO, "PROV database host='%s', port='%d', user='%s', name='%s'",
config_prov_host, config_prov_port, config_prov_user, config_prov_db);
syslog(LOG_INFO, "STATS database host='%s', port='%d', user='%s', name='%s'",
config_stats_host, config_stats_port, config_stats_user, config_stats_db);
syslog(LOG_DEBUG, "Setting up mysql connections.");
if(medmysql_init() != 0)

@ -38,8 +38,12 @@
#define MEDIATOR_DEFAULT_PROVDB "provisioning"
#define MEDIATOR_DEFAULT_PROVPORT 0
#define MEDIATOR_DEFAULT_STATSDB "sipstats"
#define MEDIATOR_DEFAULT_STATS_PERIOD MED_STATS_HOUR
#define MEDIATOR_DEFAULT_STATSHOST "localhost"
#define MEDIATOR_DEFAULT_STATSUSER "mediator"
#define MEDIATOR_DEFAULT_STATSPASS "GimmeAllUr$$$"
#define MEDIATOR_DEFAULT_STATSDB "sipstats"
#define MEDIATOR_DEFAULT_STATSPORT 0
#define MEDIATOR_DEFAULT_STATSPERIOD MED_STATS_HOUR
#define MED_GW_STRING "gw"
#define MED_AS_STRING "as"

@ -23,6 +23,7 @@
static MYSQL *cdr_handler = NULL;
static MYSQL *med_handler = NULL;
static MYSQL *prov_handler = NULL;
static MYSQL *stats_handler = NULL;
static int medmysql_flush_cdr(struct medmysql_batches *);
static int medmysql_flush_medlist(struct medmysql_str *);
@ -97,6 +98,20 @@ int medmysql_init()
goto err;
}
stats_handler = mysql_init(NULL);
if(!mysql_real_connect(stats_handler,
config_stats_host, config_stats_user, config_stats_pass,
config_stats_db, config_stats_port, NULL, 0))
{
syslog(LOG_CRIT, "Error connecting to STATS db: %s", mysql_error(stats_handler));
goto err;
}
if(mysql_options(stats_handler, MYSQL_OPT_RECONNECT, &recon) != 0)
{
syslog(LOG_CRIT, "Error setting reconnect-option for STATS db: %s", mysql_error(stats_handler));
goto err;
}
return 0;
err:
@ -122,6 +137,11 @@ void medmysql_cleanup()
mysql_close(prov_handler);
prov_handler = NULL;
}
if(stats_handler != NULL)
{
mysql_close(stats_handler);
stats_handler = NULL;
}
}
/**********************************************************************/
@ -637,6 +657,8 @@ int medmysql_batch_start(struct medmysql_batches *batches) {
return -1;
if (mysql_query_wrapper(med_handler, "start transaction", 17))
return -1;
if (mysql_query_wrapper(stats_handler, "start transaction", 17))
return -1;
if (!med_call_stat_info_table)
med_call_stat_info_table = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
@ -711,7 +733,7 @@ static int medmysql_flush_medlist(struct medmysql_str *str) {
}
static int medmysql_flush_call_stat_info() {
if (!med_handler)
if (!stats_handler)
return 0;
if (!med_call_stat_info_table)
return 0;
@ -742,10 +764,10 @@ static int medmysql_flush_call_stat_info() {
//syslog(LOG_DEBUG, "updating call stats info: %s -- %s", period_t->call_code, period_t->period);
//syslog(LOG_DEBUG, "sql: %s", query.str);
if(mysql_query_wrapper(med_handler, query.str, query.len) != 0)
if(mysql_query_wrapper(stats_handler, query.str, query.len) != 0)
{
syslog(LOG_CRIT, "Error executing call info stats query: %s",
mysql_error(med_handler));
mysql_error(stats_handler));
critical("Failed to execute potentially crucial SQL query, check syslog for details");
return -1;
}
@ -773,6 +795,8 @@ int medmysql_batch_end(struct medmysql_batches *batches) {
return -1;
if (mysql_query_wrapper(med_handler, "commit", 6))
return -1;
if (mysql_query_wrapper(stats_handler, "commit", 6))
return -1;
return 0;
}

Loading…
Cancel
Save