From 8fb76d095221ffd92797114d739a0a46328d687e Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Fri, 19 Apr 2024 17:14:35 +0200 Subject: [PATCH 1/3] [-] update environment variables documentation, closes #424 --- docs/ENV_VARIABLES.md | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/docs/ENV_VARIABLES.md b/docs/ENV_VARIABLES.md index 611d700244..0c700cc4bd 100644 --- a/docs/ENV_VARIABLES.md +++ b/docs/ENV_VARIABLES.md @@ -5,38 +5,10 @@ Some variables influence multiple components. Command line parameters override e ## Docker image specific - **PW3_TESTDB** When set, the config DB itself will be added to monitoring as "test". Default: - -- **PW3_PG_SCHEMA_TYPE** Enables to choose different metric storage models for the "pgwatch3" image - [metric-time|metric-dbname-time]. Default: metric-time ## Gatherer daemon -- **PW3_GROUP** Logical grouping/sharding key to monitor a subset of configured hosts. Default: - -- **PW3_PG_METRIC_STORE_CONN_STR** Postgres metric store connection string. Default: - -- **PW3_JSON_STORAGE_FILE** File to store metric values. Default: - -- **PW3_PG_RETENTION_DAYS** Effective when PW3_DATASTORE=postgres. Default: 14 -- **PW3_CONFIG** Connection string (`postgresql://user:pwd@host/db`), file or folder of YAML (.yaml/.yml) files containing info on which DBs to monitor and where to store metrics -- **PW3_METRICS_FOLDER** File mode. Folder of metrics definitions -- **PW3_BATCHING_MAX_DELAY_MS** Max milliseconds to wait for a batched metrics flush. Default: 250 -- **PW3_INTERNAL_STATS_PORT** Port for inquiring monitoring status in JSON format. Default: 8081 -- **PW3_CONN_POOLING** Enable re-use of metrics fetching connections. "off" means reconnect every time. Default: off -- **PW3_AES_GCM_KEYPHRASE** Keyphrase for encryption/decpyption of connect string passwords. -- **PW3_AES_GCM_KEYPHRASE_FILE** File containing a keyphrase for encryption/decpyption of connect string passwords. -- **PW3_AES_GCM_PASSWORD_TO_ENCRYPT** A special mode, returns the encrypted plain-text string and quits. Keyphrase(file) must be set -- **PW3_PROMETHEUS_PORT** Prometheus port. Effective with --datastore=prometheus. Default: 9187 -- **PW3_PROMETHEUS_LISTEN_ADDR** Network interface to listen on. Default: "0.0.0.0" -- **PW3_PROMETHEUS_NAMESPACE** Prefix for all non-process (thus Postgres) metrics. Default: "pgwatch3" -- **PW3_PROMETHEUS_ASYNC_MODE** Gather in background as with other storages and cache last fetch results for each metric in memory. Default: false -- **PW3_ADD_SYSTEM_IDENTIFIER** Add system identifier to each captured metric (PG10+). Default: false -- **PW3_SYSTEM_IDENTIFIER_FIELD** Control name of the "system identifier" field. Default: sys_id -- **PW3_SERVERS_REFRESH_LOOP_SECONDS** Sleep time for the main loop. Default: 120 -- **PW3_VERSION** Show Git build version and exit. -- **PW3_PING** Try to connect to all configured DB-s, report errors and then exit. -- **PW3_INSTANCE_LEVEL_CACHE_MAX_SECONDS** Max allowed staleness for instance level metric data shared between DBs of an instance. Affects 'continuous' host types only. Set to 0 to disable. Default: 30 -- **PW3_DIRECT_OS_STATS** Extract OS related psutil statistics not via PL/Python wrappers but directly on host, i.e. assumes "push" setup. Default: off. -- **PW3_MIN_DB_SIZE_MB** Smaller size DBs will be ignored and not monitored until they reach the threshold. Default: 0 (no size-based limiting). -- **PW3_MAX_PARALLEL_CONNECTIONS_PER_DB** Max parallel metric fetches per DB. Note the multiplication effect on multi-DB instances. Default: 2 -- **PW3_EMERGENCY_PAUSE_TRIGGERFILE** When the file exists no metrics will be temporarily fetched / scraped. Default: /tmp/pgwatch3-emergency-pause -- **PW3_NO_HELPER_FUNCTIONS** Ignore metric definitions using helper functions (in form get_smth()) and don't also roll out any helpers automatically. Default: false -- **PW3_TRY_CREATE_LISTED_EXTS_IF_MISSING** Try creating the listed extensions (comma sep.) on first connect for all monitored DBs when missing. Main usage - pg_stat_statements. Default: "" +See `pgwatch3 --help` output for details. ## Grafana From e678494519014e0245115b4a1355bfad86749527 Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Fri, 19 Apr 2024 17:16:11 +0200 Subject: [PATCH 2/3] [-] remove deprecated `PW3_PG_SCHEMA_TYPE` env var from Docker bootstrap --- docker/bootstrap/init_dbs.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/docker/bootstrap/init_dbs.sh b/docker/bootstrap/init_dbs.sh index 2e1d4a0bc4..b3c03083e8 100644 --- a/docker/bootstrap/init_dbs.sh +++ b/docker/bootstrap/init_dbs.sh @@ -20,9 +20,3 @@ GRANT EXECUTE ON FUNCTION get_load_average() TO pgwatch3; COMMENT ON FUNCTION get_load_average() is 'created for pgwatch3'; COMMIT; EOSQL - -if [ "$PW3_PG_SCHEMA_TYPE" == "timescale" ] ; then - psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "pgwatch3_metrics" <<-EOSQL - CREATE EXTENSION timescaledb; -EOSQL -fi From e45ce761176aa50ce67dbe0d6604cde5cb2ceb52 Mon Sep 17 00:00:00 2001 From: Pavlo Golub Date: Fri, 19 Apr 2024 17:17:35 +0200 Subject: [PATCH 3/3] [*] make sure help is printed for all kind of config errors --- src/config/cmdoptions.go | 14 ++++++++++---- src/main.go | 8 +++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/config/cmdoptions.go b/src/config/cmdoptions.go index 99fbaef0ec..105bdbff89 100644 --- a/src/config/cmdoptions.go +++ b/src/config/cmdoptions.go @@ -74,6 +74,7 @@ type Options struct { WebUI WebUIOpts `group:"WebUI"` Version bool `long:"version" mapstructure:"version" description:"Show Git build version and exit" env:"PW3_VERSION"` Ping bool `long:"ping" mapstructure:"ping" description:"Try to connect to all configured DB-s, report errors and then exit" env:"PW3_PING"` + Help bool } // New returns a new instance of CmdOptions @@ -82,12 +83,17 @@ func New(writer io.Writer) (*Options, error) { parser := flags.NewParser(cmdOpts, flags.HelpFlag) var err error if _, err = parser.Parse(); err != nil { - if !flags.WroteHelp(err) { - parser.WriteHelp(writer) - return cmdOpts, err + if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { + cmdOpts.Help = true } } - return cmdOpts, validateConfig(cmdOpts) + if err == nil { + err = validateConfig(cmdOpts) + } + if !flags.WroteHelp(err) { + parser.WriteHelp(writer) + } + return cmdOpts, err } // Verbose returns true if the debug log is enabled diff --git a/src/main.go b/src/main.go index ca86746478..8821913ff6 100644 --- a/src/main.go +++ b/src/main.go @@ -192,11 +192,13 @@ func main() { defer cancel() if opts, err = config.New(os.Stdout); err != nil { - exitCode.Store(ExitCodeConfigError) - fmt.Print(err) + if !opts.Help { + exitCode.Store(ExitCodeConfigError) + } + fmt.Println(err) return } - if opts.VersionOnly() { + if opts.VersionOnly() || opts.Help { printVersion() return }