Skip to content

Commit edbb5f5

Browse files
committed
[+] add "Command-Line Options & Environment Variables" page
1 parent 8e1029e commit edbb5f5

File tree

9 files changed

+258
-64
lines changed

9 files changed

+258
-64
lines changed

docs/reference/kubernetes.md renamed to docs/concept/kubernetes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ title: Kubernetes
33
---
44

55
A basic Helm chart templates for installing pgwatch to a Kubernetes
6-
cluster are available as a standalone [repository](https://github.com/cybertec-postgresql/pgwatch-charts).
6+
cluster are available as a standalone [repository](https://github.com/cybertec-postgresql/pgwatch-charts).
77

88
!!! notice
99
Charts are not considered as a part of pgwatch and
1010
are not maintained by pgwatch developers.
1111

12-
The corresponding setup can be found in [repository](https://github.com/cybertec-postgresql/pgwatch-charts),
12+
The corresponding setup can be found in [repository](https://github.com/cybertec-postgresql/pgwatch-charts),
1313
whereas installation is done via the following commands:
1414

1515
cd openshift_k8s
1616
helm install -f chart-values.yml pgwatch ./helm-chart
1717

18-
Please have a look at `helm-chart/values.yaml` to get additional information of configurable options.
18+
Please have a look at `helm-chart/values.yaml` to get additional information of configurable options.

docs/reference/security.md renamed to docs/concept/security.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ troubleshooting, which is where the roots of pgwatch lie.
1111

1212
Some points on security:
1313

14-
- The administrative Web UI doesn't have by default any security.
14+
- The administrative Web UI doesn't have by default any security.
1515
Configurable via env. variables.
1616

17-
- Viewing Grafana dashboards by default doesn't require login.
17+
- Viewing Grafana dashboards by default doesn't require login.
1818
Editing needs a password. Configurable via env. variables.
1919

20-
- Dashboards based on the "stat_statements" metric (Stat Statement
20+
- Dashboards based on the "stat_statements" metric (Stat Statement
2121
Overview / Top) expose actual queries.
2222

2323
They should be "mostly" stripped of details though and replaced by
@@ -27,12 +27,12 @@ Some points on security:
2727
`pg_stat_statements_calls` metrics could be used, which don't
2828
store query texts in the first place.
2929

30-
- Safe certificate connections to Postgres are supported. According
30+
- Safe certificate connections to Postgres are supported. According
3131
*sslmode* (verify-ca, verify-full) and cert file paths
32-
need to be specified then in connection string on Web UI "/dbs" page
32+
need to be specified then in connection string on Web UI "/dbs" page
3333
or in the YAML config.
3434

35-
- Note that although pgwatch can handle password security, in many
35+
- Note that although pgwatch can handle password security, in many
3636
cases it's better to still use the standard LibPQ *.pgpass* file to
3737
store passwords.
3838

@@ -42,13 +42,12 @@ Some common sense security is built into default Docker images for all
4242
components but not activated by default. A sample command to launch
4343
pgwatch with following security "checkpoints" enabled:
4444

45-
1. HTTPS for both Grafana and the Web UI with self-signed certificates
46-
1. No anonymous viewing of graphs in Grafana
47-
1. Custom user / password for the Grafana "admin" account
48-
1. No anonymous access / editing over the admin Web UI
49-
1. No viewing of internal logs of components running inside Docker
50-
1. Password encryption for connect strings stored in the Config DB
51-
45+
1. HTTPS for both Grafana and the Web UI with self-signed certificates
46+
1. No anonymous viewing of graphs in Grafana
47+
1. Custom user / password for the Grafana "admin" account
48+
1. No anonymous access / editing over the admin Web UI
49+
1. No viewing of internal logs of components running inside Docker
50+
1. Password encryption for connect strings stored in the Config DB
5251

5352
```properties
5453
docker run --name pw3 -d --restart=unless-stopped \

docs/howto/metrics_db_bootstrap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Bootstrapping the Metrics Measurements Database (Sink)
2+
title: Bootstrapping the Measurements Database (Sink)
33
---
44

55
## Choosing a Database

docs/reference/cli_env.md

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
---
2+
title: Command-Line Options & Environment Variables
3+
---
4+
5+
## General Usage
6+
7+
```terminal
8+
pgwatch [OPTIONS] [config | metric | source]
9+
```
10+
11+
When no command is specified, the default is to start in a monitoring mode. pgwatch will read the
12+
configuration from the specified sources and metrics first, and then will start the measurements collection
13+
from resolved databases.
14+
15+
## Options
16+
17+
### Sources
18+
19+
- `-s`, `--sources=`
20+
21+
Postgres URI, file or folder of YAML files containing info on which DBs to monitor.
22+
ENV: `$PW_SOURCES`
23+
24+
Examples: `postgresql://pgwatch@localhost:5432/pgwatch`,
25+
`/etc/sources.yaml`,
26+
`/etc/pgwatch/sources/`
27+
28+
- `--refresh=`
29+
30+
How frequently to resync sources and metrics (default: 120).
31+
ENV: `$PW_REFRESH`
32+
33+
- `-g`, `--group=`
34+
35+
Groups for filtering which databases to monitor. By default all are monitored.
36+
ENV: `$PW_GROUP`
37+
38+
- `--min-db-size-mb=`
39+
40+
Smaller size databases will be ignored and not monitored until they reach the threshold (default: 0).
41+
ENV: `$PW_MIN_DB_SIZE_MB`
42+
43+
- `--max-parallel-connections-per-db=`
44+
45+
Max parallel metric fetches per monitored database. Note the multiplication effect on multi-DB instances (default: 4).
46+
ENV: `$PW_MAX_PARALLEL_CONNECTIONS_PER_DB`
47+
48+
- `--try-create-listed-exts-if-missing=`
49+
50+
Try creating the listed extensions (comma sep.) on first connect for all monitored DBs when missing. Main usage - pg_stat_statements.
51+
ENV: `$PW_TRY_CREATE_LISTED_EXTS_IF_MISSING`
52+
53+
Example: `pg_stat_statements,pg_hint_plan`
54+
55+
### Metrics
56+
57+
- `-m`, `--metrics=`
58+
59+
Postgres URI, YAML file or folder of YAML files with metrics definitions.
60+
ENV: `$PW_METRICS`
61+
62+
- `--create-helpers`
63+
64+
Create helper database objects from metric definitions.
65+
ENV: `$PW_CREATE_HELPERS`
66+
67+
- `--direct-os-stats`
68+
69+
Extract OS related psutil statistics not via PL/Python wrappers but directly on host.
70+
ENV: `$PW_DIRECT_OS_STATS`
71+
72+
- `--instance-level-cache-max-seconds=`
73+
74+
Max allowed staleness for instance level metric data shared between DBs of an instance. Set to 0 to disable (default: 30).
75+
ENV: `$PW_INSTANCE_LEVEL_CACHE_MAX_SECONDS`
76+
77+
- `--emergency-pause-triggerfile=`
78+
79+
When the file exists no metrics will be temporarily fetched / scraped (default: /tmp/pgwatch-emergency-pause).
80+
ENV: `$PW_EMERGENCY_PAUSE_TRIGGERFILE`
81+
82+
### Sinks
83+
84+
- `--sink=`
85+
86+
URI where metrics will be stored, can be used multiple times.
87+
ENV: `$PW_SINK`
88+
89+
Examples: `postgresql://pgwatch@localhost:5432/metrics`,
90+
`prometheus://localhost:9090`,
91+
`jsonfile:///tmp/metrics.json`,
92+
`rpc://localhost:5000/`
93+
94+
- `--batching-delay=`
95+
96+
Max milliseconds to wait for a batched metrics flush (default: 250ms).
97+
ENV: `$PW_BATCHING_DELAY`
98+
99+
- `--retention=`
100+
101+
If set, metrics older than that will be deleted (default: 14).
102+
ENV: `$PW_RETENTION`
103+
104+
- `--real-dbname-field=`
105+
106+
Tag key for real database name (default: real_dbname).
107+
ENV: `$PW_REAL_DBNAME_FIELD`
108+
109+
- `--system-identifier-field=`
110+
111+
Tag key for system identifier value (default: sys_id).
112+
ENV: `$PW_SYSTEM_IDENTIFIER_FIELD`
113+
114+
### Logging
115+
116+
- `--log-level=[debug|info|error]`
117+
118+
Verbosity level for stdout and log file (default: info)
119+
120+
- `--log-file=`
121+
122+
File name to store logs
123+
124+
- `--log-file-format=[json|text]`
125+
126+
Format of file logs (default: json)
127+
128+
- `--log-file-rotate`
129+
130+
Rotate log files
131+
132+
- `--log-file-size=`
133+
134+
Maximum size in MB of the log file before it gets rotated (default: 100)
135+
136+
- `--log-file-age=`
137+
138+
Number of days to retain old log files, 0 means forever (default: 0)
139+
140+
- `--log-file-number=`
141+
142+
Maximum number of old log files to retain, 0 to retain all (default: 0)
143+
144+
### WebUI
145+
146+
- `--web-disable=[all|ui]`
147+
148+
Disable REST API and/or web UI.
149+
ENV: `$PW_WEBDISABLE`
150+
151+
- `--web-addr=`
152+
153+
TCP address in the form 'host:port' to listen on (default: :8080).
154+
ENV: `$PW_WEBADDR`
155+
156+
- `--web-user=`
157+
158+
Admin login.
159+
ENV: `$PW_WEBUSER`
160+
161+
- `--web-password=`
162+
163+
Admin password.
164+
ENV: `$PW_WEBPASSWORD`
165+
166+
### Help Options
167+
168+
- `-h`, `--help`
169+
170+
Show this help message
171+
172+
## Available commands
173+
174+
### Manage configurations
175+
176+
```terminal
177+
pgwatch [OPTIONS] config <init | upgrade>
178+
```
179+
180+
!!! info
181+
To use `config` command, you need to specify the `-s`, `--sources` and\or `-m`, `--metrics` options.
182+
183+
- `init`
184+
185+
Initialize the configuration database with the required tables and functions. If file is used, it will
186+
be created in the specified location and filled with built-in defaults.
187+
188+
- `upgrade`
189+
190+
Upgrade the database to the latest version. File or folder based configurations are not supported yet.
191+
192+
### Manage metrics
193+
194+
```terminal
195+
pgwatch [OPTIONS] metric <print-init | print-sql>
196+
```
197+
198+
!!! info
199+
To use `config` command, you need to specify the `-m`, `--metrics` option.
200+
201+
- `print-init`
202+
203+
Get and print init SQL for a given metric(s) or preset(s)
204+
205+
Examples: `pgwatch metric print-init bgwriter cpu_load`,
206+
`pgwatch metric print-init exhaustive`
207+
208+
- `print-sql`
209+
210+
Get and print SQL for a given metric. Optional parameter `-v, --version=` specifies
211+
PostgreSQL version to get SQL for.
212+
213+
Examples: `pgwatch metric print-sql bgwriter`,
214+
`pgwatch metric print-sql bgwriter -v 14`
215+
216+
### Manage sources
217+
218+
```terminal
219+
pgwatch [OPTIONS] source <ping | resolve>
220+
```
221+
222+
!!! info
223+
To use `source` command, you need to specify the `-s`, `--sources` option.
224+
225+
- `ping`
226+
227+
Ping the sources (databases, patroni clusters, poolers, etc.) to check if they are reachable.
228+
229+
- `resolve`
230+
231+
Resolve the monitored databases from sources (postgres clusters and patroni clusters) to check
232+
if they are reachableand if the configuration is correct. The output will be a list of the
233+
resolved databases with their connection strings.

docs/reference/env_variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ See `pgwatch --help` output for details.
1616
- **PW_GRAFANAUSER** Administrative user. Default: admin
1717
- **PW_GRAFANAPASSWORD** Administrative user password. Default: pgwatchadmin
1818
- **PW_GRAFANASSL** Use SSL. Default: -
19-
- **PW_GRAFANA_BASEURL** For linking to Grafana "Query details" dashboard from "Stat_stmt. overview". Default: http://0.0.0.0:3000
19+
- **PW_GRAFANA_BASEURL** For linking to Grafana "Query details" dashboard from "Stat_stmt. overview". Default: <http://0.0.0.0:3000>

docs/reference/technical_details.md

Lines changed: 0 additions & 38 deletions
This file was deleted.

internal/metrics/cmdopts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66

77
// CmdOpts specifies metric command-line options
88
type CmdOpts struct {
9-
Metrics string `short:"m" long:"metrics" mapstructure:"metrics" description:"File or folder of YAML files with metrics definitions" env:"PW_METRICS"`
9+
Metrics string `short:"m" long:"metrics" mapstructure:"metrics" description:"Postgres URI, file or folder of YAML files with metrics definitions" env:"PW_METRICS"`
1010
DirectOSStats bool `long:"direct-os-stats" mapstructure:"direct-os-stats" description:"Extract OS related psutil statistics not via PL/Python wrappers but directly on host" env:"PW_DIRECT_OS_STATS"`
1111
InstanceLevelCacheMaxSeconds int64 `long:"instance-level-cache-max-seconds" mapstructure:"instance-level-cache-max-seconds" description:"Max allowed staleness for instance level metric data shared between DBs of an instance. Set to 0 to disable" env:"PW_INSTANCE_LEVEL_CACHE_MAX_SECONDS" default:"30"`
12-
EmergencyPauseTriggerfile string `long:"emergency-pause-triggerfile" mapstructure:"emergency-pause-triggerfile" description:"When the file exists no metrics will be temporarily fetched / scraped" env:"PW_EMERGENCY_PAUSE_TRIGGERFILE" default:"/tmp/pgwatch-emergency-pause"`
12+
EmergencyPauseTriggerfile string `long:"emergency-pause-triggerfile" mapstructure:"emergency-pause-triggerfile" description:"When the file exists no metrics will be temporarily fetched" env:"PW_EMERGENCY_PAUSE_TRIGGERFILE" default:"/tmp/pgwatch-emergency-pause"`
1313
}
1414

1515
func (c CmdOpts) CacheAge() time.Duration {

internal/sinks/cmdopts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "time"
55
// CmdOpts specifies the storage configuration to store metrics measurements
66
type CmdOpts struct {
77
Sinks []string `long:"sink" mapstructure:"sink" description:"URI where metrics will be stored, can be used multiple times" env:"PW_SINK"`
8-
BatchingDelay time.Duration `long:"batching-delay" mapstructure:"batching-delay" description:"Max milliseconds to wait for a batched metrics flush. [Default: 250ms]" default:"250ms" env:"PW_BATCHING_MAX_DELAY"`
8+
BatchingDelay time.Duration `long:"batching-delay" mapstructure:"batching-delay" description:"Max milliseconds to wait for a batched metrics flush" default:"250ms" env:"PW_BATCHING_DELAY"`
99
Retention int `long:"retention" mapstructure:"retention" description:"If set, metrics older than that will be deleted" default:"14" env:"PW_RETENTION"`
1010
RealDbnameField string `long:"real-dbname-field" mapstructure:"real-dbname-field" description:"Tag key for real database name" env:"PW_REAL_DBNAME_FIELD" default:"real_dbname"`
1111
SystemIdentifierField string `long:"system-identifier-field" mapstructure:"system-identifier-field" description:"Tag key for system identifier value" env:"PW_SYSTEM_IDENTIFIER_FIELD" default:"sys_id"`

0 commit comments

Comments
 (0)