pgpool2.git / summary / log / commit / refs
commit 22ff25c885fe1f1ac38554cd10c85c31df5945d9
Author: Tatsuo Ishii <ishii at sraoss.co.jp>
Date: Tue Jul 05 09:11:00 2011 +0000
Allow to show all process info using pcp_process_info, show pool_pools.
* it refactor "pcp processes info" related code to return all processes
* info from backend, similar to the "show pool_pools" query
* add pgpool process PID and backend id fields
* add the ability to show all these informations from pcp_proc_info
* command
* no change to the pcp_proc_info command default behavior
* new fields are added as last fields in the proc_info command only with
* the -a switch (both verbose or not)
Patch contributed by Jehan-Guillaume (ioguix) de Rorthais
Makefile.in | 2 -
pcp/libpcp_ext.h | 21 +--
pcp/pcp.c | 40 ++++--
pcp/pcp_proc_info.c | 125 ++++++++++++------
pcp_child.c | 129 ++++++++++---------
pool_process_reporting.c | 326 ++++++++++++++++++++++-------------------------
6 files changed, 342 insertions(+), 301 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index 196fe7962..e384b943f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -361,7 +361,6 @@ EXTRA_DIST = pgpool.8.in sample/pgpool.pam doc/pgpool-ja.html doc/pgpool-en.html
SUBDIRS = parser pcp
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive
- +@echo "All of pgPool-II successfully made. Ready to install."
.SUFFIXES:
.SUFFIXES: .c .l .lo .o .obj
@@ -897,7 +896,6 @@ installdirs-am:
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-recursive
- +@echo "pgPool-II installation complete."
install-exec: install-exec-recursive
install-data: install-data-recursive
uninstall: uninstall-recursive
diff --git a/pcp/libpcp_ext.h b/pcp/libpcp_ext.h
index 3c0ed4998..4c79bebd5 100644
--- a/pcp/libpcp_ext.h
+++ b/pcp/libpcp_ext.h
@@ -69,6 +69,7 @@ typedef struct {
* Connection pool information. Placed on shared memory area.
*/
typedef struct {
+ int backend_id; /* backend id */
char database[SM_DATABASE]; /* Database name */
char user[SM_USER]; /* User name */
int major; /* protocol major version */
@@ -197,18 +198,18 @@ typedef struct {
/* pools reporting struct */
typedef struct {
- char pool_pid[POOLCONFIG_MAXCOUNTLEN+1];
- char start_time[POOLCONFIG_MAXDATELEN+1];
- char pool_id[POOLCONFIG_MAXCOUNTLEN+1];
- char backend_id[POOLCONFIG_MAXCOUNTLEN+1];
+ int pool_pid;
+ time_t start_time;
+ int pool_id;
+ int backend_id;
char database[POOLCONFIG_MAXIDENTLEN+1];
char username[POOLCONFIG_MAXIDENTLEN+1];
- char create_time[POOLCONFIG_MAXDATELEN+1];
- char pool_majorversion[POOLCONFIG_MAXCOUNTLEN+1];
- char pool_minorversion[POOLCONFIG_MAXCOUNTLEN+1];
- char pool_counter[POOLCONFIG_MAXCOUNTLEN+1];
- char pool_backendpid[POOLCONFIG_MAXCOUNTLEN+1];
- char pool_connected[POOLCONFIG_MAXCOUNTLEN+1];
+ time_t create_time;
+ int pool_majorversion;
+ int pool_minorversion;
+ int pool_counter;
+ int pool_backendpid;
+ int pool_connected;
} POOL_REPORT_POOLS;
/* version struct */
diff --git a/pcp/pcp.c b/pcp/pcp.c
index 7ccb07780..62cd755a8 100644
--- a/pcp/pcp.c
+++ b/pcp/pcp.c
@@ -624,6 +624,7 @@ pcp_process_info(int pid, int *array_size)
int rsize;
ProcessInfo *process_info = NULL;
+ ConnectionInfo *conn_info = NULL;
int ci_size = 0;
int offset = 0;
@@ -685,19 +686,20 @@ pcp_process_info(int pid, int *array_size)
ci_size = atoi(index);
*array_size = ci_size;
-
- process_info = (ProcessInfo *)malloc(sizeof(ProcessInfo));
+
+ process_info = (ProcessInfo *)malloc(sizeof(ProcessInfo) * ci_size);
if (process_info == NULL)
{
free(buf);
errorcode = NOMEMERR;
return NULL;
}
- process_info->connection_info = NULL;
- process_info->connection_info = (ConnectionInfo *)malloc(sizeof(ConnectionInfo)*ci_size);
- if (process_info->connection_info == NULL)
+
+ conn_info = (ConnectionInfo *)malloc(sizeof(ConnectionInfo) * ci_size);
+ if (conn_info == NULL)
{
free(buf);
+ free(process_info);
errorcode = NOMEMERR;
return NULL;
}
@@ -706,41 +708,51 @@ pcp_process_info(int pid, int *array_size)
}
else if (strcmp(buf, "ProcessInfo") == 0)
{
+ process_info[offset].connection_info = &conn_info[offset];
+
index = (char *) memchr(buf, '\0', rsize) + 1;
if (index != NULL)
- strcpy(process_info->connection_info[offset].database, index);
+ process_info[offset].pid = atoi(index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- strcpy(process_info->connection_info[offset].user, index);
+ strcpy(process_info[offset].connection_info->database, index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- process_info->start_time = atol(index);
+ strcpy(process_info[offset].connection_info->user, index);
+
+ index = (char *) memchr(index, '\0', rsize) + 1;
+ if (index != NULL)
+ process_info[offset].start_time = atol(index);
+
+ index = (char *) memchr(index, '\0', rsize) + 1;
+ if (index != NULL)
+ process_info[offset].connection_info->create_time = atol(index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- process_info->connection_info[offset].create_time = atol(index);
+ process_info[offset].connection_info->major = atoi(index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- process_info->connection_info[offset].major = atoi(index);
+ process_info[offset].connection_info->minor = atoi(index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- process_info->connection_info[offset].minor = atoi(index);
+ process_info[offset].connection_info->counter = atoi(index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- process_info->connection_info[offset].counter = atoi(index);
+ process_info[offset].connection_info->backend_id = atoi(index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- process_info->connection_info[offset].pid = atoi(index);
+ process_info[offset].connection_info->pid = atoi(index);
index = (char *) memchr(index, '\0', rsize) + 1;
if (index != NULL)
- process_info->connection_info[offset].connected = atoi(index);
+ process_info[offset].connection_info->connected = atoi(index);
offset++;
}
diff --git a/pcp/pcp_proc_info.c b/pcp/pcp_proc_info.c
index 53032b67f..497d48790 100644
--- a/pcp/pcp_proc_info.c
+++ b/pcp/pcp_proc_info.c
@@ -49,7 +49,9 @@ main(int argc, char **argv)
int array_size;
int ch;
int optindex;
- bool verbose = false;
+ char * frmt;
+ bool verbose = false;
+ bool all = false;
static struct option long_options[] = {
{"debug", no_argument, NULL, 'd'},
@@ -58,7 +60,7 @@ main(int argc, char **argv)
{NULL, 0, NULL, 0}
};
- while ((ch = getopt_long(argc, argv, "hdv", long_options, &optindex)) != -1) {
+ while ((ch = getopt_long(argc, argv, "hdva", long_options, &optindex)) != -1) {
switch (ch) {
case 'd':
pcp_enable_debug();
@@ -68,6 +70,10 @@ main(int argc, char **argv)
verbose = true;
break;
+ case 'a':
+ all = true;
+ break;
+
case 'h':
case '?':
default:
@@ -78,7 +84,40 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
- if (argc != 6)
+ if (verbose)
+ {
+ if (all)
+ frmt = "Database : %s\n"
+ "Username : %s\n"
+ "Start time : %s\n"
+ "Creation time: %s\n"
+ "Major : %d\n"
+ "Minor : %d\n"
+ "Counter : %d\n"
+ "Backend PID : %d\n"
+ "Connected : %d\n"
+ "PID : %d\n"
+ "Backend ID : %d\n";
+ else
+ frmt = "Database : %s\n"
+ "Username : %s\n"
+ "Start time : %s\n"
+ "Creation time: %s\n"
+ "Major : %d\n"
+ "Minor : %d\n"
+ "Counter : %d\n"
+ "Backend PID : %d\n"
+ "Connected : %d\n";
+ }
+ else
+ {
+ if (all)
+ frmt = "%s %s %s %s %d %d %d %d %d %d %d\n";
+ else
+ frmt = "%s %s %s %s %d %d %d %d %d\n";
+ }
+
+ if (!(argc == 5 || argc == 6))
{
errorcode = INVALERR;
pcp_errorstr(errorcode);
@@ -123,13 +162,19 @@ main(int argc, char **argv)
myexit(errorcode);
}
strcpy(pass, argv[4]);
+
+ if (argc == 6) {
- processID = atoi(argv[5]);
- if (processID < 0)
- {
- errorcode = INVALERR;
- pcp_errorstr(errorcode);
- myexit(errorcode);
+ processID = atoi(argv[5]);
+ if (processID < 0)
+ {
+ errorcode = INVALERR;
+ pcp_errorstr(errorcode);
+ myexit(errorcode);
+ }
+ }
+ else {
+ processID = 0;
}
pcp_set_timeout(timeout);
@@ -147,40 +192,35 @@ main(int argc, char **argv)
myexit(errorcode);
} else {
int i;
- char strcreatetime[128];
- char strstarttime[128];
- strftime(strstarttime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info->start_time));
+ char strcreatetime[128];
+ char strstarttime[128];
+
for (i = 0; i < array_size; i++)
{
- if (process_info->connection_info[i].database[0] == '\0')
+ if ((!all) && (process_info[i].connection_info->database[0] == '\0'))
continue;
-
- strftime(strcreatetime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info->connection_info[i].create_time));
- if (verbose)
- {
- printf("Database : %s\nUsername : %s\nStart time : %s\nCreation time: %s\nMajor : %d\nMinor : %d\nCounter : %d\nPID : %d\nConnected : %d\n",
- process_info->connection_info[i].database,
- process_info->connection_info[i].user,
- strstarttime,
- strcreatetime,
- process_info->connection_info[i].major,
- process_info->connection_info[i].minor,
- process_info->connection_info[i].counter,
- process_info->connection_info[i].pid,
- process_info->connection_info[i].connected);
- } else {
- printf("%s %s %s %s %d %d %d %d %d\n",
- process_info->connection_info[i].database,
- process_info->connection_info[i].user,
- strstarttime,
- strcreatetime,
- process_info->connection_info[i].major,
- process_info->connection_info[i].minor,
- process_info->connection_info[i].counter,
- process_info->connection_info[i].pid,
- process_info->connection_info[i].connected);
- }
+
+ *strcreatetime = *strstarttime = '\0';
+
+ if (process_info[i].start_time)
+ strftime(strstarttime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info[i].start_time));
+ if (process_info[i].connection_info->create_time)
+ strftime(strcreatetime, 128, "%Y-%m-%d %H:%M:%S", localtime(&process_info[i].connection_info->create_time));
+
+ printf(frmt,
+ process_info[i].connection_info->database,
+ process_info[i].connection_info->user,
+ strstarttime,
+ strcreatetime,
+ process_info[i].connection_info->major,
+ process_info[i].connection_info->minor,
+ process_info[i].connection_info->counter,
+ process_info[i].connection_info->pid,
+ process_info[i].connection_info->connected,
+ process_info[i].pid,
+ process_info[i].connection_info->backend_id);
}
+ free(process_info->connection_info);
free(process_info);
}
@@ -193,18 +233,19 @@ static void
usage(void)
{
fprintf(stderr, "pcp_proc_info - display a pgpool-II child process' information\n\n");
- fprintf(stderr, "Usage: pcp_proc_info [-d] timeout hostname port# username password PID\n");
+ fprintf(stderr, "Usage: pcp_proc_info [-d] timeout hostname port# username password [PID]\n");
fprintf(stderr, " -d, --debug : enable debug message (optional)\n");
fprintf(stderr, " timeout : connection timeout value in seconds. command exits on timeout\n");
fprintf(stderr, " hostname : pgpool-II hostname\n");
fprintf(stderr, " port# : PCP port number\n");
fprintf(stderr, " username : username for PCP authentication\n");
fprintf(stderr, " password : password for PCP authentication\n");
- fprintf(stderr, " PID : PID of a child process to get information for\n\n");
+ fprintf(stderr, " PID : if given, PID of the only child process to get information for\n\n");
fprintf(stderr, "Usage: pcp_proc_info [options]\n");
- fprintf(stderr, " Options available are:\n");
+ fprintf(stderr, " Options available are:\n");
fprintf(stderr, " -h, --help : print this help\n");
fprintf(stderr, " -v, --verbose : display one line per information with a header\n");
+ fprintf(stderr, " -a, --all : display all child processes and their available connection slots.\n");
}
static void
diff --git a/pcp_child.c b/pcp_child.c
index 2841c0737..44f11adb7 100644
--- a/pcp_child.c
+++ b/pcp_child.c
@@ -410,13 +410,12 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file)
{
int proc_id;
int wsize;
-
- ProcessInfo *pi = NULL;
+ int num_proc = pool_config->num_init_children;
+ int i;
proc_id = atoi(buf);
- pi = pool_get_process_info(proc_id);
- if (pi == NULL)
+ if ((proc_id != 0) && (pool_get_process_info(proc_id) == NULL))
{
char code[] = "InvalidProcessID";
@@ -440,7 +439,16 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file)
/* Finally, indicate that all data is sent */
char fin_code[] = "CommandComplete";
- snprintf(con_info_size, sizeof(con_info_size), "%d", pool_config->max_pool*NUM_BACKENDS);
+ POOL_REPORT_POOLS *pools = get_pools(&num_proc);
+
+ if (proc_id == 0)
+ {
+ snprintf(con_info_size, sizeof(con_info_size), "%d", num_proc);
+ }
+ else
+ {
+ snprintf(con_info_size, sizeof(con_info_size), "%d", pool_config->max_pool * NUM_BACKENDS);
+ }
pcp_write(frontend, "p", 1);
wsize = htonl(sizeof(arr_code) +
@@ -452,65 +460,68 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file)
if (pcp_flush(frontend) < 0)
{
pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
+ free(pools);
exit(1);
}
/* Second, send process information for all connection_info */
- for (i = 0; i < pool_config->max_pool; i++)
+ for (i=0; i<num_proc; i++)
{
- int j;
-
- for (j=0;j<NUM_BACKENDS;j++)
+ char code[] = "ProcessInfo";
+ char proc_pid[16];
+ char proc_start_time[20];
+ char proc_create_time[20];
+ char majorversion[5];
+ char minorversion[5];
+ char pool_counter[16];
+ char backend_id[16];
+ char backend_pid[16];
+ char connected[2];
+
+ if (proc_id != 0 && proc_id != pools[i].pool_pid) continue;
+
+ snprintf(proc_pid, sizeof(proc_pid), "%d", pools[i].pool_pid);
+ snprintf(proc_start_time, sizeof(proc_start_time), "%ld", pools[i].start_time);
+ snprintf(proc_create_time, sizeof(proc_create_time), "%ld", pools[i].create_time);
+ snprintf(majorversion, sizeof(majorversion), "%d", pools[i].pool_majorversion);
+ snprintf(minorversion, sizeof(minorversion), "%d", pools[i].pool_minorversion);
+ snprintf(pool_counter, sizeof(pool_counter), "%d", pools[i].pool_counter);
+ snprintf(backend_id, sizeof(backend_pid), "%d", pools[i].backend_id);
+ snprintf(backend_pid, sizeof(backend_pid), "%d", pools[i].pool_backendpid);
+ snprintf(connected, sizeof(connected), "%d", pools[i].pool_connected);
+
+ pcp_write(frontend, "p", 1);
+ wsize = htonl( sizeof(code) +
+ strlen(proc_pid)+1 +
+ strlen(pools[i].database)+1 +
+ strlen(pools[i].username)+1 +
+ strlen(proc_start_time)+1 +
+ strlen(proc_create_time)+1 +
+ strlen(majorversion)+1 +
+ strlen(minorversion)+1 +
+ strlen(pool_counter)+1 +
+ strlen(backend_id)+1 +
+ strlen(backend_pid)+1 +
+ strlen(connected)+1 +
+ sizeof(int));
+ pcp_write(frontend, &wsize, sizeof(int));
+ pcp_write(frontend, code, sizeof(code));
+ pcp_write(frontend, proc_pid, strlen(proc_pid)+1);
+ pcp_write(frontend, pools[i].database, strlen(pools[i].database)+1);
+ pcp_write(frontend, pools[i].username, strlen(pools[i].username)+1);
+ pcp_write(frontend, proc_start_time, strlen(proc_start_time)+1);
+ pcp_write(frontend, proc_create_time, strlen(proc_create_time)+1);
+ pcp_write(frontend, majorversion, strlen(majorversion)+1);
+ pcp_write(frontend, minorversion, strlen(minorversion)+1);
+ pcp_write(frontend, pool_counter, strlen(pool_counter)+1);
+ pcp_write(frontend, backend_id, strlen(backend_id)+1);
+ pcp_write(frontend, backend_pid, strlen(backend_pid)+1);
+ pcp_write(frontend, connected, strlen(connected)+1);
+ if (pcp_flush(frontend) < 0)
{
- char code[] = "ProcessInfo";
- char proc_start_time[20];
- char proc_create_time[20];
- char majorversion[5];
- char minorversion[5];
- char pool_counter[16];
- char backend_pid[16];
- char connected[2];
-
- ConnectionInfo *connection_info;
-
- connection_info = pool_coninfo_pid(proc_id, i, j);
-
- snprintf(proc_start_time, sizeof(proc_start_time), "%ld", pi->start_time);
- snprintf(proc_create_time, sizeof(proc_create_time), "%ld", connection_info->create_time);
- snprintf(majorversion, sizeof(majorversion), "%d", connection_info->major);
- snprintf(minorversion, sizeof(minorversion), "%d", connection_info->minor);
- snprintf(pool_counter, sizeof(pool_counter), "%d", connection_info->counter);
- snprintf(backend_pid, sizeof(backend_pid), "%d", ntohl(connection_info->pid));
- snprintf(connected, sizeof(connected), "%d", connection_info->connected);
-
- pcp_write(frontend, "p", 1);
- wsize = htonl(sizeof(code) +
- strlen(connection_info->database)+1 +
- strlen(connection_info->user)+1 +
- strlen(proc_start_time)+1 +
- strlen(proc_create_time)+1 +
- strlen(majorversion)+1 +
- strlen(minorversion)+1 +
- strlen(pool_counter)+1 +
- strlen(backend_pid)+1 +
- strlen(connected)+1 +
- sizeof(int));
- pcp_write(frontend, &wsize, sizeof(int));
- pcp_write(frontend, code, sizeof(code));
- pcp_write(frontend, connection_info->database, strlen(connection_info->database)+1);
- pcp_write(frontend, connection_info->user, strlen(connection_info->user)+1);
- pcp_write(frontend, proc_start_time, strlen(proc_start_time)+1);
- pcp_write(frontend, proc_create_time, strlen(proc_create_time)+1);
- pcp_write(frontend, majorversion, strlen(majorversion)+1);
- pcp_write(frontend, minorversion, strlen(minorversion)+1);
- pcp_write(frontend, pool_counter, strlen(pool_counter)+1);
- pcp_write(frontend, backend_pid, strlen(backend_pid)+1);
- pcp_write(frontend, connected, strlen(connected)+1);
- if (pcp_flush(frontend) < 0)
- {
- pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
- exit(1);
- }
+ pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
+ free(pools);
+ exit(1);
}
}
@@ -522,10 +533,12 @@ pcp_do_child(int unix_fd, int inet_fd, char *pcp_conf_file)
if (pcp_flush(frontend) < 0)
{
pool_error("pcp_child: pcp_flush() failed. reason: %s", strerror(errno));
+ free(pools);
exit(1);
}
pool_debug("pcp_child: retrieved process information from shared memory");
+ free(pools);
}
break;
}
diff --git a/pool_process_reporting.c b/pool_process_reporting.c
index eb6538f7e..c10769472 100644
--- a/pool_process_reporting.c
+++ b/pool_process_reporting.c
@@ -760,210 +760,186 @@ POOL_REPORT_POOLS* get_pools(int *nrows)
);
for (child = 0; child < pool_config->num_init_children; child++)
- {
+ {
proc_id = process_info[child].pid;
- pi = pool_get_process_info(proc_id);
+ pi = pool_get_process_info(proc_id);
- for (pool = 0; pool < pool_config->max_pool; pool++)
- {
+ for (pool = 0; pool < pool_config->max_pool; pool++)
+ {
for (backend_id = 0; backend_id < NUM_BACKENDS; backend_id++)
{
- poolBE = pool*MAX_NUM_BACKENDS+backend_id;
- snprintf(pools[lines].pool_pid, POOLCONFIG_MAXCOUNTLEN, "%d", proc_id);
- strftime(pools[lines].start_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pi->start_time));
- snprintf(pools[lines].pool_id, POOLCONFIG_MAXCOUNTLEN, "%d", pool);
- snprintf(pools[lines].backend_id, POOLCONFIG_MAXCOUNTLEN, "%d", backend_id);
- if (strlen(pi->connection_info[poolBE].database) == 0)
- {
- strncpy(pools[lines].database, "", POOLCONFIG_MAXIDENTLEN);
- strncpy(pools[lines].username, "", POOLCONFIG_MAXIDENTLEN);
- strncpy(pools[lines].create_time, "", POOLCONFIG_MAXDATELEN);
- strncpy(pools[lines].pool_majorversion, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_minorversion, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_counter, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_backendpid, "", POOLCONFIG_MAXCOUNTLEN);
- strncpy(pools[lines].pool_connected, "", POOLCONFIG_MAXCOUNTLEN);
- }
- else
- {
- strncpy(pools[lines].database, pi->connection_info[poolBE].database, POOLCONFIG_MAXIDENTLEN);
- strncpy(pools[lines].username, pi->connection_info[poolBE].user, POOLCONFIG_MAXIDENTLEN);
- strftime(pools[lines].create_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pi->connection_info[poolBE].create_time));
- snprintf(pools[lines].pool_majorversion, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].major);
- snprintf(pools[lines].pool_minorversion, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].minor);
- snprintf(pools[lines].pool_counter, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].counter);
- snprintf(pools[lines].pool_backendpid, POOLCONFIG_MAXCOUNTLEN, "%d", ntohl(pi->connection_info[poolBE].pid));
- snprintf(pools[lines].pool_connected, POOLCONFIG_MAXCOUNTLEN, "%d", pi->connection_info[poolBE].connected);
- }
- lines++;
- }
- }
+ poolBE = pool*MAX_NUM_BACKENDS+backend_id;
+ pools[lines].pool_pid = proc_id;
+ pools[lines].start_time = pi->start_time;
+ pools[lines].pool_id = pool;
+ pools[lines].backend_id = backend_id;
+ if (strlen(pi->connection_info[poolBE].database) == 0)
+ {
+ strncpy(pools[lines].database, "", POOLCONFIG_MAXIDENTLEN);
+ strncpy(pools[lines].username, "", POOLCONFIG_MAXIDENTLEN);
+ pools[lines].create_time = 0;
+ pools[lines].pool_majorversion = 0;
+ pools[lines].pool_minorversion = 0;
+ }
+ else
+ {
+ strncpy(pools[lines].database, pi->connection_info[poolBE].database, POOLCONFIG_MAXIDENTLEN);
+ strncpy(pools[lines].username, pi->connection_info[poolBE].user, POOLCONFIG_MAXIDENTLEN);
+ pools[lines].create_time = pi->connection_info[poolBE].create_time;
+ pools[lines].pool_majorversion = pi->connection_info[poolBE].major;
+ pools[lines].pool_minorversion = pi->connection_info[poolBE].minor;
+ }
+ pools[lines].pool_counter = pi->connection_info[poolBE].counter;
+ pools[lines].pool_backendpid = ntohl(pi->connection_info[poolBE].pid);
+ pools[lines].pool_connected = pi->connection_info[poolBE].connected;
+ lines++;
+ }
+ }
}
*nrows = lines;
return pools;
- }
+}
void pools_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend)
- {
+{
static short num_fields = 12;
static char *field_names[] = {"pool_pid", "start_time", "pool_id", "backend_id", "database", "username", "create_time",
"majorversion", "minorversion", "pool_counter", "pool_backendpid", "pool_connected"};
short s;
int len;
- int i;
+ int i;
static unsigned char nullmap[2] = {0xff, 0xff};
int nbytes = (num_fields + 7)/8;
int nrows;
int size;
int hsize;
+ char proc_pid[16];
+ char pool_id[16];
+ char proc_start_time[20];
+ char proc_create_time[20];
+ char majorversion[5];
+ char minorversion[5];
+ char pool_counter[16];
+ char backend_id[16];
+ char backend_pid[16];
+ char connected[2];
POOL_REPORT_POOLS *pools = get_pools(&nrows);
send_row_description(frontend, backend, num_fields, field_names);
- if (MAJOR(backend) == PROTO_MAJOR_V2)
- {
- /* ascii row */
- for (i=0;i<nrows;i++)
- {
- pool_write(frontend, "D", 1);
- pool_write_and_flush(frontend, nullmap, nbytes);
-
- size = strlen(pools[i].pool_pid);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_pid, size);
-
- size = strlen(pools[i].start_time);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].start_time, size);
-
- size = strlen(pools[i].pool_id);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_id, size);
-
- size = strlen(pools[i].backend_id);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].backend_id, size);
-
- size = strlen(pools[i].database);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].database, size);
-
- size = strlen(pools[i].username);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].username, size);
-
- size = strlen(pools[i].create_time);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].create_time, size);
-
- size = strlen(pools[i].pool_majorversion);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_majorversion, size);
-
- size = strlen(pools[i].pool_minorversion);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_minorversion, size);
-
- size = strlen(pools[i].pool_counter);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_counter, size);
-
- size = strlen(pools[i].pool_backendpid);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_backendpid, size);
+ if (MAJOR(backend) == PROTO_MAJOR_V2) hsize = 4;
+ else hsize = 0;
- size = strlen(pools[i].pool_connected);
- hsize = htonl(size+4);
- pool_write(frontend, &hsize, sizeof(hsize));
- pool_write(frontend, pools[i].pool_connected, size);
- }
- }
- else
- {
- /* data row */
+ /* ascii row */
for (i=0;i<nrows;i++)
{
- pool_write(frontend, "D", 1);
- len = 6; /* int32 + int16; */
- len += 4 + strlen(pools[i].pool_pid); /* int32 + data */
- len += 4 + strlen(pools[i].start_time); /* int32 + data */
- len += 4 + strlen(pools[i].pool_id); /* int32 + data */
- len += 4 + strlen(pools[i].backend_id); /* int32 + data */
- len += 4 + strlen(pools[i].database); /* int32 + data */
- len += 4 + strlen(pools[i].username); /* int32 + data */
- len += 4 + strlen(pools[i].create_time); /* int32 + data */
- len += 4 + strlen(pools[i].pool_majorversion); /* int32 + data */
- len += 4 + strlen(pools[i].pool_minorversion); /* int32 + data */
- len += 4 + strlen(pools[i].pool_counter); /* int32 + data */
- len += 4 + strlen(pools[i].pool_backendpid); /* int32 + data */
- len += 4 + strlen(pools[i].pool_connected); /* int32 + data */
- len = htonl(len);
- pool_write(frontend, &len, sizeof(len));
- s = htons(num_fields);
- pool_write(frontend, &s, sizeof(s));
-
- len = htonl(strlen(pools[i].pool_pid));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_pid, strlen(pools[i].pool_pid));
-
- len = htonl(strlen(pools[i].start_time));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].start_time, strlen(pools[i].start_time));
-
- len = htonl(strlen(pools[i].pool_id));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_id, strlen(pools[i].pool_id));
-
- len = htonl(strlen(pools[i].backend_id));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].backend_id, strlen(pools[i].backend_id));
-
- len = htonl(strlen(pools[i].database));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].database, strlen(pools[i].database));
-
- len = htonl(strlen(pools[i].username));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].username, strlen(pools[i].username));
-
- len = htonl(strlen(pools[i].create_time));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].create_time, strlen(pools[i].create_time));
-
- len = htonl(strlen(pools[i].pool_majorversion));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_majorversion, strlen(pools[i].pool_majorversion));
-
- len = htonl(strlen(pools[i].pool_minorversion));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_minorversion, strlen(pools[i].pool_minorversion));
-
- len = htonl(strlen(pools[i].pool_counter));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_counter, strlen(pools[i].pool_counter));
-
- len = htonl(strlen(pools[i].pool_backendpid));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_backendpid, strlen(pools[i].pool_backendpid));
-
- len = htonl(strlen(pools[i].pool_connected));
- pool_write(frontend, &len, sizeof(len));
- pool_write(frontend, pools[i].pool_connected, strlen(pools[i].pool_connected));
+ snprintf(proc_pid, sizeof(proc_pid), "%d", pools[i].pool_pid);
+ snprintf(pool_id, sizeof(pool_id), "%d", pools[i].pool_id);
+ if (pools[i].start_time)
+ strftime(proc_start_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pools[i].start_time));
+ else
+ *proc_start_time = '\0';
+ if (pools[i].create_time)
+ strftime(proc_create_time, POOLCONFIG_MAXDATELEN, "%Y-%m-%d %H:%M:%S", localtime(&pools[i].create_time));
+ else
+ *proc_create_time = '\0';
+ snprintf(majorversion, sizeof(majorversion), "%d", pools[i].pool_majorversion);
+ snprintf(minorversion, sizeof(minorversion), "%d", pools[i].pool_minorversion);
+ snprintf(pool_counter, sizeof(pool_counter), "%d", pools[i].pool_counter);
+ snprintf(backend_id, sizeof(backend_pid), "%d", pools[i].backend_id);
+ snprintf(backend_pid, sizeof(backend_pid), "%d", pools[i].pool_backendpid);
+ snprintf(connected, sizeof(connected), "%d", pools[i].pool_connected);
+
+ if (MAJOR(backend) == PROTO_MAJOR_V2)
+ {
+ pool_write(frontend, "D", 1);
+ pool_write_and_flush(frontend, nullmap, nbytes);
+ }
+ else
+ {
+ pool_write(frontend, "D", 1);
+ len = 6; /* int32 + int16; */
+ len += 4 + strlen(proc_pid); /* int32 + data */
+ len += 4 + strlen(proc_start_time); /* int32 + data */
+ len += 4 + strlen(pool_id); /* int32 + data */
+ len += 4 + strlen(backend_id); /* int32 + data */
+ len += 4 + strlen(pools[i].database); /* int32 + data */
+ len += 4 + strlen(pools[i].username); /* int32 + data */
+ len += 4 + strlen(proc_create_time); /* int32 + data */
+ len += 4 + strlen(majorversion); /* int32 + data */
+ len += 4 + strlen(minorversion); /* int32 + data */
+ len += 4 + strlen(pool_counter); /* int32 + data */
+ len += 4 + strlen(backend_pid); /* int32 + data */
+ len += 4 + strlen(connected); /* int32 + data */
+
+ len = htonl(len);
+ pool_write(frontend, &len, sizeof(len));
+ s = htons(num_fields);
+ pool_write(frontend, &s, sizeof(s));
+ }
+
+ len = strlen(proc_pid);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, proc_pid, len);
+
+ len = strlen(proc_start_time);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, proc_start_time, len);
+
+ len = strlen(pool_id);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pool_id, len);
+
+ len = strlen(backend_id);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, backend_id, len);
+
+ len = strlen(pools[i].database);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pools[i].database, len);
+
+ len = strlen(pools[i].username);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pools[i].username, len);
+
+ len = strlen(proc_create_time);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, proc_create_time, len);
+
+ len = strlen(majorversion);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, majorversion, len);
+
+ len = strlen(minorversion);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, minorversion, len);
+
+ len = strlen(pool_counter);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, pool_counter, len);
+
+ len = strlen(backend_pid);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, backend_pid, len);
+
+ len = strlen(connected);
+ size = htonl(len+hsize);
+ pool_write(frontend, &size, sizeof(size));
+ pool_write(frontend, connected, len);
}
- }
send_complete_and_ready(frontend, backend, nrows);
[parent: 3682cd1629e7]