]> granicus.if.org Git - pgbouncer/commitdiff
SHOW TOTALS command to give stats summary
authorMarko Kreen <markokr@gmail.com>
Fri, 11 Jan 2008 14:20:11 +0000 (14:20 +0000)
committerMarko Kreen <markokr@gmail.com>
Fri, 11 Jan 2008 14:20:11 +0000 (14:20 +0000)
include/stats.h
src/admin.c
src/stats.c

index 3180be6b273e7dbb87c97fc78107285d14a9891e..b7c723d364dcb43e58e8c5cc78f0bde2bedf85ad 100644 (file)
@@ -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;
 
index f40bae722d9663b432131dc353ce2033ab47b698..3e0532087446e454ef193d36d420476830573eb3 100644 (file)
@@ -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}
 };
 
index 2ade3db77555ea25e9acb962a6a755196f85f7e4..cb83581155f023134e57c05bdf3e1ecce9056a23 100644 (file)
@@ -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;