From: Peter Eisentraut Date: Sat, 3 Aug 2019 21:24:36 +0000 (+0200) Subject: Add option to disable printing stats to log X-Git-Tag: pgbouncer_1_11_0~17 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=466e48e059a5c36eb90432c8a15bc3463340bc31;p=pgbouncer Add option to disable printing stats to log Add option log_stats that can be used to disable printing stats to log. Stats are still updated every stats_period, for SHOW commands. Author: @weastur fixes #287 --- diff --git a/doc/config.md b/doc/config.md index 311f15e..0fcd3d4 100644 --- a/doc/config.md +++ b/doc/config.md @@ -281,6 +281,14 @@ Default: pgbouncer Alias for `service_name`. +### stats_period + +Sets how often the averages shown in various `SHOW` commands are +updated and how often aggregated statistics are written to the log +(but see `log_stats`). [seconds] + +Default: 60 + ## Log settings @@ -322,11 +330,13 @@ Log error messages pooler sends to clients. Default: 1 -### stats_period +### log_stats -Period for writing aggregated stats into log. +Write aggregated statistics into the log, every `stats_period`. This +can be disabled if external monitoring tools are used to grab the same +data from `SHOW` commands. -Default: 60 +Default: 1 ### verbose diff --git a/doc/usage.md b/doc/usage.md index a528998..9da2ffe 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -163,7 +163,8 @@ The **SHOW** commands output information. Each command is described below. #### SHOW STATS -Shows statistics. +Shows statistics. In this and related commands, the total figures are +since process start, the averages are updated every `stats_period`. database : Statistics are presented per database. diff --git a/include/bouncer.h b/include/bouncer.h index 8aba41f..d52d397 100644 --- a/include/bouncer.h +++ b/include/bouncer.h @@ -461,6 +461,7 @@ extern char *cf_ignore_startup_params; extern char *cf_admin_users; extern char *cf_stats_users; extern int cf_stats_period; +extern int cf_log_stats; extern int cf_pause_mode; extern int cf_shutdown; diff --git a/src/main.c b/src/main.c index 49a87e4..dba1873 100644 --- a/src/main.c +++ b/src/main.c @@ -138,6 +138,7 @@ char *cf_jobname; char *cf_admin_users; char *cf_stats_users; int cf_stats_period; +int cf_log_stats; int cf_log_connections; int cf_log_disconnections; @@ -270,6 +271,7 @@ CF_ABS("verbose", CF_INT, cf_verbose, 0, NULL), CF_ABS("admin_users", CF_STR, cf_admin_users, 0, ""), CF_ABS("stats_users", CF_STR, cf_stats_users, 0, ""), CF_ABS("stats_period", CF_INT, cf_stats_period, 0, "60"), +CF_ABS("log_stats", CF_INT, cf_log_stats, 0, "1"), CF_ABS("log_connections", CF_INT, cf_log_connections, 0, "1"), CF_ABS("log_disconnections", CF_INT, cf_log_disconnections, 0, "1"), CF_ABS("log_pooler_errors", CF_INT, cf_log_pooler_errors, 0, "1"), diff --git a/src/stats.c b/src/stats.c index 8fed6b7..a9a9de8 100644 --- a/src/stats.c +++ b/src/stats.c @@ -336,7 +336,7 @@ static void refresh_stats(int s, short flags, void *arg) struct List *item; PgPool *pool; struct timeval period = { cf_stats_period, 0 }; - PgStats old_total, cur_total, avg; + PgStats old_total, cur_total; reset_stats(&old_total); reset_stats(&cur_total); @@ -349,22 +349,29 @@ static void refresh_stats(int s, short flags, void *arg) pool->older_stats = pool->newer_stats; pool->newer_stats = pool->stats; - stat_add(&cur_total, &pool->stats); - stat_add(&old_total, &pool->older_stats); + if (cf_log_stats) { + stat_add(&cur_total, &pool->stats); + stat_add(&old_total, &pool->older_stats); + } + } + + if (cf_log_stats) { + PgStats avg; + + calc_average(&avg, &cur_total, &old_total); + + log_info("stats: %" PRIu64 " xacts/s," + " %" PRIu64 " queries/s," + " in %" PRIu64 " B/s," + " out %" PRIu64 " B/s," + " xact %" PRIu64 " us," + " query %" PRIu64 " us," + " wait %" PRIu64 " us", + avg.xact_count, avg.query_count, + avg.client_bytes, avg.server_bytes, + avg.xact_time, avg.query_time, + avg.wait_time); } - calc_average(&avg, &cur_total, &old_total); - /* send totals to logfile */ - log_info("stats: %" PRIu64 " xacts/s," - " %" PRIu64 " queries/s," - " in %" PRIu64 " B/s," - " out %" PRIu64 " B/s," - " xact %" PRIu64 " us," - " query %" PRIu64 " us," - " wait %" PRIu64 " us", - avg.xact_count, avg.query_count, - avg.client_bytes, avg.server_bytes, - avg.xact_time, avg.query_time, - avg.wait_time); safe_evtimer_add(&ev_stats, &period); }