pgpool2.git / summary / log / commit / refs

commit    a6963976c4673f110a642e5b3435c332b18ecb77
Author:   Toshihiro Kitagawa <kitagawa at sraoss.co.jp>
Date:     Mon Apr 25 11:33:37 2011 +0000

    Forgot to add pool_process_reporting.h, pcp/pcp_pool_status.c.


pcp/pcp_pool_status.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++ pool_process_reporting.h | 43 ++++++++++++ 2 files changed, 209 insertions(+) diff --git a/pcp/pcp_pool_status.c b/pcp/pcp_pool_status.c new file mode 100644 index 000000000..d90d98869 --- /dev/null +++ b/pcp/pcp_pool_status.c @@ -0,0 +1,166 @@ +/* + * $Header$ + * + * pgpool: a language independent connection pool server for PostgreSQL + * written by Tatsuo Ishii + * + * Copyright (c) 2003-2011 PgPool Global Development Group + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that the above copyright notice appear in all + * copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of the + * author not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The author makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * Client program to send "pool status" command. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#ifdef HAVE_GETOPT_H +#include <getopt.h> +#else +#include "getopt_long.h" +#endif + +#include "pcp.h" + +static void usage(void); +static void myexit(ErrorCode e); + +int +main(int argc, char **argv) +{ + long timeout; + char host[MAX_DB_HOST_NAMELEN]; + int port; + char user[MAX_USER_PASSWD_LEN]; + char pass[MAX_USER_PASSWD_LEN]; + POOL_REPORT_CONFIG *status; + int ch; + int i; + int optindex; + int array_size = 0; + + static struct option long_options[] = { + {"debug", no_argument, NULL, 'd'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0} + }; + + while ((ch = getopt_long(argc, argv, "hd", long_options, &optindex)) != -1) { + switch (ch) { + case 'd': + pcp_enable_debug(); + break; + + case 'h': + case '?': + default: + usage(); + exit(0); + } + } + argc -= optind; + argv += optind; + + if (argc != 5) { + errorcode = INVALERR; + pcp_errorstr(errorcode); + myexit(errorcode); + } + + timeout = atol(argv[0]); + if (timeout < 0) { + errorcode = INVALERR; + pcp_errorstr(errorcode); + myexit(errorcode); + } + + if (strlen(argv[1]) >= MAX_DB_HOST_NAMELEN) { + errorcode = INVALERR; + pcp_errorstr(errorcode); + myexit(errorcode); + } + strcpy(host, argv[1]); + + port = atoi(argv[2]); + if (port <= 1024 || port > 65535) { + errorcode = INVALERR; + pcp_errorstr(errorcode); + myexit(errorcode); + } + + if (strlen(argv[3]) >= MAX_USER_PASSWD_LEN) { + errorcode = INVALERR; + pcp_errorstr(errorcode); + myexit(errorcode); + } + strcpy(user, argv[3]); + + if (strlen(argv[4]) >= MAX_USER_PASSWD_LEN) { + errorcode = INVALERR; + pcp_errorstr(errorcode); + myexit(errorcode); + } + strcpy(pass, argv[4]); + + pcp_set_timeout(timeout); + + if (pcp_connect(host, port, user, pass)) + { + pcp_errorstr(errorcode); + myexit(errorcode); + } + + if ((status = pcp_pool_status(&array_size)) == NULL) + { + pcp_errorstr(errorcode); + pcp_disconnect(); + myexit(errorcode); + } else { + + for (i=0; i<array_size; i++) { + printf("name : %s\nvalue: %s\ndesc : %s\n\n", status[i].name, status[i].value, status[i].desc); + } + free(status); + } + + pcp_disconnect(); + + return 0; +} + +static void +usage(void) +{ + fprintf(stderr, "pcp_pool_status - display pgpool configuration and status\n\n"); + fprintf(stderr, "Usage: pcp_pool_status [-d] timeout hostname port# username password\n"); + fprintf(stderr, "Usage: pcp_pool_status -h\n\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, " -h, --help : print this help\n"); +} + +static void +myexit(ErrorCode e) +{ + if (e == INVALERR) + { + usage(); + exit(e); + } + + exit(e); +} diff --git a/pool_process_reporting.h b/pool_process_reporting.h new file mode 100644 index 000000000..bc451c2a6 --- /dev/null +++ b/pool_process_reporting.h @@ -0,0 +1,43 @@ +/* -*-pgsql-c-*- */ +/* + * + * $Header$ + * + * pgpool: a language independent connection pool server for PostgreSQL + * written by Tatsuo Ishii + * + * Copyright (c) 2003-2011 PgPool Global Development Group + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that the above copyright notice appear in all + * copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of the + * author not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The author makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * pool_process_reporting.h.: header file for pool_process_reporting.c + * + */ + +#ifndef POOL_PROCESS_REPORTING_H +#define POOL_PROCESS_REPORTING_H + +extern void send_row_description(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, + short num_fields, char **field_names); +extern void send_complete_and_ready(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend, const int num_rows); +extern POOL_REPORT_CONFIG* get_config(int *nrows); +extern POOL_REPORT_POOLS* get_pools(int *nrows); +extern POOL_REPORT_PROCESSES* get_processes(int *nrows); +extern POOL_REPORT_NODES* get_nodes(int *nrows); +extern POOL_REPORT_VERSION* get_version(void); +extern void config_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend); +extern void pools_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend); +extern void processes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend); +extern void nodes_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend); +extern void version_reporting(POOL_CONNECTION *frontend, POOL_CONNECTION_POOL *backend); + +#endif [parent: d1c93dc40869]