]> granicus.if.org Git - pgbouncer/commitdiff
Add option to disable printing stats to log
authorPeter Eisentraut <peter@eisentraut.org>
Sat, 3 Aug 2019 21:24:36 +0000 (23:24 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Sat, 3 Aug 2019 21:24:36 +0000 (23:24 +0200)
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

doc/config.md
doc/usage.md
include/bouncer.h
src/main.c
src/stats.c

index 311f15e7456aaeaa1a428f9bd7ea49a877f04048..0fcd3d4d52c9209c441f401aaeb279160f1915f9 100644 (file)
@@ -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
 
index a52899835da2e32e42d7e7104ce5994b7af06de9..9da2ffe885812a090a60f0cfb2578d4f56fccc98 100644 (file)
@@ -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.
index 8aba41f0000238356843bdece685664749482eb1..d52d397ef709589dd30842b013ec3a2dde13e6a3 100644 (file)
@@ -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;
index 49a87e4ffd50779219f7f1ee432d57870c3e92d6..dba18736cecaf5a1797fe0ad3546693a6182aeae 100644 (file)
@@ -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"),
index 8fed6b7cf1252c81ec5127f99735565e68e34f28..a9a9de86b0b731e9a3231abbb8ee11f6bedfb01d 100644 (file)
@@ -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);
 }