bool admin_database_stats(PgSocket *client, struct StatList *pool_list) { PgPool *pool; struct List *item; PgDatabase *cur_db = NULL; PgStats st_total, st_db, old_db, old_total; int rows = 0; PktBuf *buf; reset_stats(&st_total); reset_stats(&st_db); reset_stats(&old_db); reset_stats(&old_total); buf = pktbuf_dynamic(512); if (!buf) { admin_error(client, "no mem"); return true; } pktbuf_write_RowDescription(buf, "sqqqqqqqqqqqqqq", "database", "total_xact_count", "total_query_count", "total_received", "total_sent", "total_xact_time", "total_query_time", "total_wait_time", "avg_xact_count", "avg_query_count", "avg_recv", "avg_sent", "avg_xact_time", "avg_query_time", "avg_wait_time"); statlist_for_each(item, pool_list) { pool = container_of(item, PgPool, head); if (!cur_db) cur_db = pool->db; if (pool->db != cur_db) { write_stats(buf, &st_db, &old_db, cur_db->name); rows ++; cur_db = pool->db; stat_add(&st_total, &st_db); stat_add(&old_total, &old_db); reset_stats(&st_db); reset_stats(&old_db); } stat_add(&st_db, &pool->stats); stat_add(&old_db, &pool->older_stats); }
static void start_auth_request(PgSocket *client, const char *username) { int res; PktBuf *buf; client->auth_user = client->db->auth_user; /* have to fetch user info from db */ client->pool = get_pool(client->db, client->db->auth_user); if (!find_server(client)) { client->wait_for_user_conn = true; return; } slog_noise(client, "Doing auth_conn query"); client->wait_for_user_conn = false; client->wait_for_user = true; if (!sbuf_pause(&client->sbuf)) { release_server(client->link); disconnect_client(client, true, "pause failed"); return; } client->link->ready = 0; res = 0; buf = pktbuf_dynamic(512); if (buf) { pktbuf_write_ExtQuery(buf, cf_auth_query, 1, username); res = pktbuf_send_immediate(buf, client->link); pktbuf_free(buf); /* * Should do instead: * res = pktbuf_send_queued(buf, client->link); * but that needs better integration with SBuf. */ } if (!res) disconnect_server(client->link, false, "unable to send login query"); }