From 39354ac3a59df48c36c4f89eab3d3a0478b4de2c Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Fri, 11 Jan 2008 14:20:11 +0000 Subject: [PATCH] SHOW TOTALS command to give stats summary --- include/stats.h | 1 + src/admin.c | 12 ++++++++++++ src/stats.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/include/stats.h b/include/stats.h index 3180be6..b7c723d 100644 --- a/include/stats.h +++ b/include/stats.h @@ -19,4 +19,5 @@ void stats_setup(void); bool admin_database_stats(PgSocket *client, StatList *pool_list) _MUSTCHECK; +bool show_stat_totals(PgSocket *client, StatList *pool_list) _MUSTCHECK; diff --git a/src/admin.c b/src/admin.c index f40bae7..3e05320 100644 --- a/src/admin.c +++ b/src/admin.c @@ -714,8 +714,14 @@ static bool admin_cmd_shutdown(PgSocket *admin, const char *arg) if (!admin->admin_user) return admin_error(admin, "admin access needed"); + /* + * note: new pooler expects unix socket file gone when it gets + * event from fd. currently atexit() cleanup should be called + * before closing open sockets. + */ log_info("SHUTDOWN command issued"); exit(0); + return true; } @@ -878,6 +884,11 @@ static bool admin_show_stats(PgSocket *admin, const char *arg) return admin_database_stats(admin, &pool_list); } +static bool admin_show_totals(PgSocket *admin, const char *arg) +{ + return show_stat_totals(admin, &pool_list); +} + static struct cmd_lookup show_map [] = { {"clients", admin_show_clients}, @@ -892,6 +903,7 @@ static struct cmd_lookup show_map [] = { {"stats", admin_show_stats}, {"users", admin_show_users}, {"version", admin_show_version}, + {"totals", admin_show_totals}, {NULL, NULL} }; diff --git a/src/stats.c b/src/stats.c index 2ade3db..cb83581 100644 --- a/src/stats.c +++ b/src/stats.c @@ -122,6 +122,49 @@ bool admin_database_stats(PgSocket *client, StatList *pool_list) return true; } +bool show_stat_totals(PgSocket *client, StatList *pool_list) +{ + PgPool *pool; + List *item; + PgStats st_total, old_total, avg; + PktBuf *buf; + + reset_stats(&st_total); + reset_stats(&old_total); + + buf = pktbuf_dynamic(512); + if (!buf) { + admin_error(client, "no mem"); + return true; + } + + + statlist_for_each(item, pool_list) { + pool = container_of(item, PgPool, head); + stat_add(&st_total, &pool->stats); + stat_add(&old_total, &pool->older_stats); + } + + calc_average(&avg, &st_total, &old_total); + + pktbuf_write_RowDescription(buf, "sq", "name", "value"); + +#define WTOTAL(name) pktbuf_write_DataRow(buf, "sq", "total_" #name, st_total.name) +#define WAVG(name) pktbuf_write_DataRow(buf, "sq", "avg_" #name, avg.name) + + WTOTAL(request_count); + WTOTAL(client_bytes); + WTOTAL(server_bytes); + WTOTAL(query_time); + WAVG(request_count); + WAVG(client_bytes); + WAVG(server_bytes); + WAVG(query_time); + + admin_flush(client, buf, "SHOW"); + return true; +} + static void refresh_stats(int s, short flags, void *arg) { List *item; -- 2.40.0