Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[*] update environment variables documentation, closes #424 #428

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions docker/bootstrap/init_dbs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 1 addition & 29 deletions docs/ENV_VARIABLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 10 additions & 4 deletions src/config/cmdoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading