You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-4Lines changed: 25 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,6 +43,9 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
43
43
44
44
### Flags
45
45
46
+
*`help`
47
+
Show context-sensitive help (also try --help-long and --help-man).
48
+
46
49
*`web.listen-address`
47
50
Address to listen on for web interface and telemetry. Default is `:9187`.
48
51
@@ -55,6 +58,9 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
55
58
*`disable-settings-metrics`
56
59
Use the flag if you don't want to scrape `pg_settings`.
57
60
61
+
*`auto-discover-databases`
62
+
Whether to discover the databases on a server dynamically.
63
+
58
64
*`extend.query-path`
59
65
Path to a YAML file containing custom queries to run. Check out [`queries.yaml`](queries.yaml)
60
66
for examples of the format.
@@ -63,16 +69,22 @@ Package vendoring is handled with [`govendor`](https://github.com/kardianos/gove
63
69
Do not run - print the internal representation of the metric maps. Useful when debugging a custom
64
70
queries file.
65
71
72
+
*`constantLabels`
73
+
Labels to set in all metrics. A list of `label=value` pairs, separated by commas.
74
+
75
+
*`version`
76
+
Show application version.
77
+
78
+
*`exclude-databases`
79
+
A list of databases to remove when autoDiscoverDatabases is enabled.
80
+
66
81
*`log.level`
67
82
Set logging level: one of `debug`, `info`, `warn`, `error`, `fatal`
68
83
69
84
*`log.format`
70
85
Set the log output target and format. e.g. `logger:syslog?appname=bob&local=7` or `logger:stdout?json=true`
71
86
Defaults to `logger:stderr`.
72
87
73
-
*`constantLabels`
74
-
Labels to set in all metrics. A list of `label=value` pairs, separated by commas.
75
-
76
88
### Environment Variables
77
89
78
90
The following environment variables configure the exporter:
@@ -85,6 +97,9 @@ The following environment variables configure the exporter:
85
97
an alternative to `DATA_SOURCE_NAME` which exclusively accepts the raw URI
86
98
without a username and password component.
87
99
100
+
*`DATA_SOURCE_URI_FILE`
101
+
The same as above but reads the URI from a file.
102
+
88
103
*`DATA_SOURCE_USER`
89
104
When using `DATA_SOURCE_URI`, this environment variable is used to specify
90
105
the username.
@@ -111,13 +126,19 @@ The following environment variables configure the exporter:
111
126
*`PG_EXPORTER_DISABLE_SETTINGS_METRICS`
112
127
Use the flag if you don't want to scrape `pg_settings`. Value can be `true` or `false`. Defauls is `false`.
113
128
129
+
*`PG_EXPORTER_AUTO_DISCOVER_DATABASES`
130
+
Whether to discover the databases on a server dynamically. Value can be `true` or `false`. Defauls is `false`.
131
+
114
132
*`PG_EXPORTER_EXTEND_QUERY_PATH`
115
133
Path to a YAML file containing custom queries to run. Check out [`queries.yaml`](queries.yaml)
116
134
for examples of the format.
117
135
118
136
*`PG_EXPORTER_CONSTANT_LABELS`
119
137
Labels to set in all metrics. A list of `label=value` pairs, separated by commas.
120
138
139
+
*`PG_EXPORTER_EXCLUDE_DATABASES`
140
+
A comma-separated list of databases to remove when autoDiscoverDatabases is enabled. Default is empty string.
141
+
121
142
Settings set by environment variables starting with `PG_` will be overwritten by the corresponding CLI flag if given.
122
143
123
144
### Setting the Postgres server's data source name
@@ -163,7 +184,7 @@ flag. This removes all built-in metrics, and uses only metrics defined by querie
163
184
164
185
### Automatically discover databases
165
186
To scrape metrics from all databases on a database server, the database DSN's can be dynamically discovered via the
166
-
`--auto-discover-databases` flag. When true, `SELECT datname FROM pg_database WHERE datallowconn = true AND datistemplate = false` is run for all configured DSN's. From the
187
+
`--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
167
188
result a new set of DSN's is created for which the metrics are scraped.
168
189
169
190
In addition, the option `--exclude-databases` adds the possibily to filter the result from the auto discovery to discard databases you do not need.
// BuildDate is set during build to the ISO-8601 date and time.
35
+
varBuildDatestring
36
+
37
+
// Revision is set during build to the git commit revision.
38
+
varRevisionstring
39
+
30
40
// Version is set during build to the git describe version
31
41
// (semantic version)-(commitish) form.
32
-
varVersion="0.0.1"
42
+
varVersion="0.0.1-rev"
43
+
44
+
// VersionShort is set during build to the semantic version.
45
+
varVersionShort="0.0.1"
33
46
34
47
var (
35
48
listenAddress=kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
@@ -101,6 +114,7 @@ type Mapping map[string]MappingOptions
101
114
typeUserQuerystruct {
102
115
Querystring`yaml:"query"`
103
116
Metrics []Mapping`yaml:"metrics"`
117
+
Masterbool`yaml:"master"`// Querying only for master database
104
118
CacheSecondsuint64`yaml:"cache_seconds"`// Number of seconds to cache the namespace result metrics for.
"checkpoints_timed": {COUNTER, "Number of scheduled checkpoints that have been performed", nil, nil},
212
+
"checkpoints_req": {COUNTER, "Number of requested checkpoints that have been performed", nil, nil},
213
+
"checkpoint_write_time": {COUNTER, "Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds", nil, nil},
214
+
"checkpoint_sync_time": {COUNTER, "Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds", nil, nil},
215
+
"buffers_checkpoint": {COUNTER, "Number of buffers written during checkpoints", nil, nil},
216
+
"buffers_clean": {COUNTER, "Number of buffers written by the background writer", nil, nil},
217
+
"maxwritten_clean": {COUNTER, "Number of times the background writer stopped a cleaning scan because it had written too many buffers", nil, nil},
218
+
"buffers_backend": {COUNTER, "Number of buffers written directly by a backend", nil, nil},
219
+
"buffers_backend_fsync": {COUNTER, "Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)", nil, nil},
220
+
"buffers_alloc": {COUNTER, "Number of buffers allocated", nil, nil},
221
+
"stats_reset": {COUNTER, "Time at which these statistics were last reset", nil, nil},
222
+
},
223
+
true,
224
+
0,
225
+
},
193
226
"pg_stat_database": {
194
227
map[string]ColumnMapping{
195
228
"datid": {LABEL, "OID of a database", nil, nil},
@@ -212,6 +245,7 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
212
245
"blk_write_time": {COUNTER, "Time spent writing data file blocks by backends in this database, in milliseconds", nil, nil},
213
246
"stats_reset": {COUNTER, "Time at which these statistics were last reset", nil, nil},
214
247
},
248
+
true,
215
249
0,
216
250
},
217
251
"pg_stat_database_conflicts": {
@@ -224,6 +258,7 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
224
258
"confl_bufferpin": {COUNTER, "Number of queries in this database that have been canceled due to pinned buffers", nil, nil},
225
259
"confl_deadlock": {COUNTER, "Number of queries in this database that have been canceled due to deadlocks", nil, nil},
226
260
},
261
+
true,
227
262
0,
228
263
},
229
264
"pg_locks": {
@@ -232,6 +267,7 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
232
267
"mode": {LABEL, "Type of Lock", nil, nil},
233
268
"count": {GAUGE, "Number of locks", nil, nil},
234
269
},
270
+
true,
235
271
0,
236
272
},
237
273
"pg_stat_replication": {
@@ -277,6 +313,21 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
277
313
"flush_lag": {DISCARD, "Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written and flushed it (but not yet applied it). This can be used to gauge the delay that synchronous_commit level remote_flush incurred while committing if this server was configured as a synchronous standby.", nil, semver.MustParseRange(">=10.0.0")},
278
314
"replay_lag": {DISCARD, "Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written, flushed and applied it. This can be used to gauge the delay that synchronous_commit level remote_apply incurred while committing if this server was configured as a synchronous standby.", nil, semver.MustParseRange(">=10.0.0")},
279
315
},
316
+
true,
317
+
0,
318
+
},
319
+
"pg_stat_archiver": {
320
+
map[string]ColumnMapping{
321
+
"archived_count": {COUNTER, "Number of WAL files that have been successfully archived", nil, nil},
322
+
"last_archived_wal": {DISCARD, "Name of the last WAL file successfully archived", nil, nil},
323
+
"last_archived_time": {DISCARD, "Time of the last successful archive operation", nil, nil},
324
+
"failed_count": {COUNTER, "Number of failed attempts for archiving WAL files", nil, nil},
325
+
"last_failed_wal": {DISCARD, "Name of the WAL file of the last failed archival operation", nil, nil},
326
+
"last_failed_time": {DISCARD, "Time of the last failed archival operation", nil, nil},
327
+
"stats_reset": {DISCARD, "Time at which these statistics were last reset", nil, nil},
328
+
"last_archive_age": {GAUGE, "Time in seconds since last WAL segment was successfully archived", nil, nil},
329
+
},
330
+
true,
280
331
0,
281
332
},
282
333
"pg_stat_activity": {
@@ -286,6 +337,7 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
286
337
"count": {GAUGE, "number of connections in this state", nil, nil},
287
338
"max_tx_duration": {GAUGE, "max duration in seconds any active transaction has been running", nil, nil},
288
339
},
340
+
true,
289
341
0,
290
342
},
291
343
}
@@ -356,6 +408,17 @@ var queryOverrides = map[string][]OverrideQuery{
356
408
},
357
409
},
358
410
411
+
"pg_stat_archiver": {
412
+
{
413
+
semver.MustParseRange(">=0.0.0"),
414
+
`
415
+
SELECT *,
416
+
extract(epoch from now() - last_archived_time) AS last_archive_age
0 commit comments