Skip to content

Commit 1b182b6

Browse files
committed
Clean up.
2 parents 75a3bcb + 4e804fa commit 1b182b6

File tree

10 files changed

+597
-227
lines changed

10 files changed

+597
-227
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
/.assets-branch
1919
/.metrics.*.added
2020
/.metrics.*.removed
21+
/tools/src

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ docker run --net=host -e DATA_SOURCE_NAME="postgresql://postgres:password@localh
1818

1919
### Flags
2020

21+
* `help`
22+
Show context-sensitive help (also try --help-long and --help-man).
23+
2124
* `web.listen-address`
2225
Address to listen on for web interface and telemetry. Default is `:9187`.
2326

@@ -30,6 +33,9 @@ docker run --net=host -e DATA_SOURCE_NAME="postgresql://postgres:password@localh
3033
* `disable-settings-metrics`
3134
Use the flag if you don't want to scrape `pg_settings`.
3235

36+
* `auto-discover-databases`
37+
Enable discovering databases automatically.
38+
3339
* `extend.query-path`
3440
Path to a YAML file containing custom queries to run. Check out [`queries.yaml`](queries.yaml)
3541
for examples of the format.
@@ -38,16 +44,22 @@ docker run --net=host -e DATA_SOURCE_NAME="postgresql://postgres:password@localh
3844
Do not run - print the internal representation of the metric maps. Useful when debugging a custom
3945
queries file.
4046

47+
* `constantLabels`
48+
Labels to set in all metrics. A list of `label=value` pairs, separated by commas.
49+
50+
* `version`
51+
Show application version.
52+
53+
* `exclude-databases`
54+
A list of databases to remove when autoDiscoverDatabases is enabled.
55+
4156
* `log.level`
4257
Set logging level: one of `debug`, `info`, `warn`, `error`, `fatal`
4358

4459
* `log.format`
4560
Set the log output target and format. e.g. `logger:syslog?appname=bob&local=7` or `logger:stdout?json=true`
4661
Defaults to `logger:stderr`.
4762

48-
* `constantLabels`
49-
Labels to set in all metrics. A list of `label=value` pairs, separated by commas.
50-
5163
### Environment Variables
5264

5365
The following environment variables configure the exporter:
@@ -60,6 +72,9 @@ The following environment variables configure the exporter:
6072
an alternative to `DATA_SOURCE_NAME` which exclusively accepts the raw URI
6173
without a username and password component.
6274

75+
* `DATA_SOURCE_URI_FILE`
76+
The same as above but reads the URI from a file.
77+
6378
* `DATA_SOURCE_USER`
6479
When using `DATA_SOURCE_URI`, this environment variable is used to specify
6580
the username.
@@ -86,13 +101,19 @@ The following environment variables configure the exporter:
86101
* `PG_EXPORTER_DISABLE_SETTINGS_METRICS`
87102
Use the flag if you don't want to scrape `pg_settings`. Value can be `true` or `false`. Defauls is `false`.
88103

104+
* `PG_EXPORTER_AUTO_DISCOVER_DATABASES`
105+
Enable discovering databases automatically. Value can be `true` or `false`. Defauls is `false`.
106+
89107
* `PG_EXPORTER_EXTEND_QUERY_PATH`
90108
Path to a YAML file containing custom queries to run. Check out [`queries.yaml`](queries.yaml)
91109
for examples of the format.
92110

93111
* `PG_EXPORTER_CONSTANT_LABELS`
94112
Labels to set in all metrics. A list of `label=value` pairs, separated by commas.
95113

114+
* `PG_EXPORTER_EXCLUDE_DATABASES`
115+
A comma-separated list of databases to remove when autoDiscoverDatabases is enabled. Default is empty string.
116+
96117
Settings set by environment variables starting with `PG_` will be overwritten by the corresponding CLI flag if given.
97118

98119
### Setting the Postgres server's data source name
@@ -138,9 +159,11 @@ flag. This removes all built-in metrics, and uses only metrics defined by querie
138159

139160
### Automatically discover databases
140161
To scrape metrics from all databases on a database server, the database DSN's can be dynamically discovered via the
141-
`--auto-discover-databases` flag. When true, `SELECT datname FROM pg_database` is run for all configured DSN's. From the
162+
`--auto-discover-databases` flag. When true, `SELECT datname FROM pg_database WHERE datallowconn = true AND datistemplate = false and datname != current_database()` is run for all configured DSN's. From the
142163
result a new set of DSN's is created for which the metrics are scraped.
143164

165+
In addition, the option `--exclude-databases` adds the possibily to filter the result from the auto discovery to discard databases you do not need.
166+
144167
### Running as non-superuser
145168

146169
To be able to collect metrics from `pg_stat_activity` and `pg_stat_replication`
@@ -181,6 +204,7 @@ ALTER USER postgres_exporter SET SEARCH_PATH TO postgres_exporter,pg_catalog;
181204
-- GRANT postgres_exporter TO <MASTER_USER>;
182205
CREATE SCHEMA IF NOT EXISTS postgres_exporter;
183206
GRANT USAGE ON SCHEMA postgres_exporter TO postgres_exporter;
207+
GRANT CONNECT ON DATABASE postgres TO postgres_exporter;
184208

185209
CREATE OR REPLACE FUNCTION get_pg_stat_activity() RETURNS SETOF pg_stat_activity AS
186210
$$ SELECT * FROM pg_catalog.pg_stat_activity; $$
@@ -212,3 +236,10 @@ GRANT SELECT ON postgres_exporter.pg_stat_replication TO postgres_exporter;
212236
> ```
213237
> DATA_SOURCE_NAME=postgresql://postgres_exporter:password@localhost:5432/postgres?sslmode=disable
214238
> ```
239+
240+
# Hacking
241+
* To build a copy for your current architecture run `go run mage.go binary`.
242+
This will create a symlink to the just built binary in the root directory.
243+
* To build release tar balls run `go run mage.go release`.
244+
* Build system is a bit temperamental at the moment since the conversion to mage - I am working on getting it
245+
to be a perfect out of the box experience, but am time-constrained on it at the moment.

0 commit comments

Comments
 (0)