Commit Graph

85 Commits

Author SHA1 Message Date
SuperQ
81c4933986
Update build
* Update to Go 1.18.
* Update minimum Go version to 1.17.
* Update Go modules for 1.17 format.
* Bump Go modules
* Enable dependabot.
* Update Prometheus common files.
* Fixup yamllint.

Signed-off-by: SuperQ <superq@gmail.com>
2022-05-25 11:27:42 +02:00
Angus Dippenaar
be30859417 Remove unit from setting because of Aurora
Signed-off-by: Angus Dippenaar <angusdippenaar@gmail.com>
2022-03-03 15:55:35 +01:00
Joe Adams
9704b9fb2e
Clean up autoDiscoverDatabases in the new collector
Signed-off-by: Joe Adams <github@joeadams.io>
2022-02-25 08:11:22 -05:00
Joe Adams
27d23d02ef
refactor pg_stat_bgwriter metrics into standalone collector
This moves the metrics that are queried from pg_stat_bgwriter into a dedicated collector instead of dynamically generating queries and metrics from a map. It renames some metrics including adding the `_total` suffix on all of the counters to match prometheus standards. This implementation uses QueryRowContext to allow for later addition of context for cancellation. From the Postgres documentation, it states that there is one line per WAL sender process, but it is unclear how to differentiate between them in any meaningful way. When querying the table, there is no column to identify the row, only metrics about bgwriter.

Signed-off-by: Joe Adams <github@joeadams.io>
2022-02-22 21:46:43 -05:00
Joe Adams
c3b0206369
Add collector interface
Uses node_exporter style collector registration

Signed-off-by: Joe Adams <github@joeadams.io>
2022-02-14 21:12:27 -05:00
Joe Adams
21a19ed252
Add pg_database collector
Converts the pg_database metrics from queries.yaml to a built in collector. This is enabled by default because it is not likely to be a performance problem and likely very useful data.

Signed-off-by: Joe Adams <github@joeadams.io>
2022-02-09 21:28:40 -05:00
Joe Adams
3880df4f64
Merge pull request #587 from credativ/azure-ff-fix
Avoid parsing error from bogus Azure Flexible Server custom GUC
2022-02-09 15:30:32 -05:00
pitan
adaa0b5e32
Merge branch 'prometheus-community:master' into fix/pg_stat_archiver-version 2022-01-17 17:04:00 +09:00
Daniel Swarbrick
99f0b4c63c
Fix misspelling of PostgreSQL
Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
2022-01-16 19:55:11 +01:00
SuperQ
fcb2535aff
Release 0.10.1
* [BUGFIX] Fix broken log-level for values other than debug. #560

Signed-off-by: SuperQ <superq@gmail.com>
2022-01-14 17:27:06 +01:00
t-inoue
21c9b0d80d change version for pg_stat_archiver
Signed-off-by: t-inoue <t-inoue@sakura.ad.jp>
2022-01-11 13:48:48 +09:00
Michael Banck
5d6e42935d Avoid parsing error from bogus Azure Flexible Server custom GUC
Signed-off-by: Michael Banck <michael.banck@credativ.de>
2021-11-20 19:37:29 +01:00
Harkishen Singh
c1ab341279 Fix broken log-level for values other than debug.
Signed-off-by: Harkishen Singh <harkishensingh@hotmail.com>
2021-07-14 16:19:00 +05:30
Joe Adams
08fd458df0
Update dependencies and fix tests
Signed-off-by: Joe Adams <github@joeadams.io>
2021-07-07 09:52:56 -04:00
Joe Adams
bc981e66c3 Refactor code into logical files
Moves code into more manageable, logical files to group behavior together. This should help improve a developer's ability to navigate the code.

Signed-off-by: Joe Adams <github@joeadams.io>
2021-07-01 16:49:08 -04:00
Dmitry F
29f6fa1891 Fix replication_slot query all supported versions
Signed-off-by: Филатов Дмитрий <d.filatov@2gis.ru>
2021-06-01 18:59:35 +07:00
Paul van der Linden
bc97291103 basic integration test
Signed-off-by: Paul van der Linden <mail@paultjuh.org>
2021-04-19 15:20:53 +02:00
Paul van der Linden
ffa6782e41 fix parsing include databases
Signed-off-by: Paul van der Linden <mail@paultjuh.org>
2021-04-17 12:05:28 +02:00
Pavel Sapezhko
2850ac800a
Add ability to set allow DBs list
Signed-off-by: Pavel Sapezhko <me@weastur.com>
2021-03-11 16:43:13 +03:00
Ben Kochie
a7e88ab430
Fix version flag
Use Prometheus common/version to print --version output.
* Add `-h` short help flag.

Fixes: https://github.com/prometheus-community/postgres_exporter/issues/492

Signed-off-by: Ben Kochie <superq@gmail.com>
2021-03-03 13:51:44 +01:00
Julien Pivotto
be790e12ff Switch to go-kit log and enable TLS/basic auth
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2021-03-02 15:31:55 +01:00
Ben Kochie
b67b69acd3
Update for Prometheus Community
Add standard Prometheus build setup
* CircleCI config
* Makefile
* Go modules
* Golang-CI Lint
* promu config
* Remove /vendor
* Remove mage build
* Update READMEs

https://github.com/prometheus-community/postgres_exporter/issues/478

Signed-off-by: Ben Kochie <superq@gmail.com>
2021-02-23 10:51:33 +01:00
Neel Patel
8531abac46
User defined configuration to run the query for different database server version from single yml file (#428)
* Run the query for specific database version if provided from yml file.
By default query will run on all the databases if "runonserver" is not provided.

If user want the query to be run on multiple database versions, use below string.
  runonserver: "9.5, 9.6"

Example yml file as below. ( e.g. below query will run only on database version 9.5 )

pg_replication:
  query: "SELECT EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) as lag"
  master: true
  runonserver: "9.5"
  metrics:
    - lag:
        usage: "GAUGE"
        description: "Replication lag behind master in seconds"

* Fixed the below review comments given by Ashesh Vashi

    Instead of having db version string from yml file, user can define the range of
    database server version where query is to be executed.

    If user want to run the query on database version greater than 10.0.0, use below format.
      runonserver: ">=10.0.0"

      Below are the example of db version range user can defined in yml file.
            <=10.1.0
            >=12.1.0
            =11.0.0
            <9.6.0 || >=11.0.0

* Remove the call from unused places where 'runOnServer' is not required.
Only Server type hold that value.

* Fix compilation issues.

* Fix the issue with Debugln to print the database server version
2021-02-18 01:04:12 +11:00
Ollie Charles
301976c218
Detect SIReadLock locks in the pg_locks metric (#421)
Co-authored-by: Will Rouesnel <wrouesnel@wrouesnel.com>
2021-01-31 22:22:18 +11:00
Ivan Shapovalov
1ba1100a72
Support connstring syntax when discovering databases (#473)
* Support connstring syntax when discovering databases

Support connstring DSNs (`host=... user=... password=... dbname=...`) in
addition to URIs (`postgresql://user:pass@host/dbname`) for purposes of
database discovery.

Connstring syntax is needed to support accessing PostgreSQL via Unix
domain sockets (`host=/run/postgres`), which is not really possible with
URI syntax.

* Appease gometalinter, don't shadow namespace
2021-01-31 22:21:38 +11:00
Yann Soubeyrand
aea6fae7d6
Recover when connection cannot be established straight at startup (#415)
When the connection to the PostgreSQL instance cannot be established straight
at startup, a race condition can happen when autoDiscoverDatabases is true. If
discoverDatabaseDSNs fails, no dsn is set as the master database, and, if
scrapeDSN succeeds, checkMapVersions will have omitted the default metrics in
the server metric map. The metric map won't be updated unless the version
returned by the PostgreSQL instance changes. With this patch, scrapeDSN won't
be run unless discoverDatabaseDSNs succeeded and thus the race condition is
eliminated.

Signed-off-by: Yann Soubeyrand <yann.soubeyrand@camptocamp.com>
2020-12-25 02:41:05 +11:00
alexey-gavrilov-flant
bfd0707e37
Fixed "Scrape Duration" if psql down (#426)
Co-authored-by: Will Rouesnel <wrouesnel@wrouesnel.com>
2020-12-25 02:39:07 +11:00
Yann Soubeyrand
8c27e97b77
Do not try to return metric descriptors in Describe (#416)
Since we cannot know in advance the metrics which the exporter will generate,
the workaround is to run a Collect and return the metric descriptors. This is
problematic when the connection to the PostgreSQL instance cannot be
established straight from the start. This patch makes Describe return no
descriptors, effectively turning the collector in an unchecked one, which we're
in the typical use case here:
https://pkg.go.dev/github.com/prometheus/client_golang/prometheus?tab=doc#hdr-Custom_Collectors_and_constant_Metrics.

Signed-off-by: Yann Soubeyrand <yann.soubeyrand@camptocamp.com>
2020-12-25 02:37:31 +11:00
Ajay Bhat
c55a3b3c5b
Fixes (#364) (#387)
Have a custom prefix for each of the default metrics created by postgres_exporter

Co-authored-by: Will Rouesnel <wrouesnel@wrouesnel.com>
2020-12-25 02:36:18 +11:00
Corin Lawson
3fd1c2c0eb
Introduce histogram support (#435)
* Introduce histogram support

Prior to this change, the custom queries were restricted to counters and
gauges.

This change introduces a new ColumnUsage, namely HISTOGRAM, that expects
the column to contain an array of upper inclusive bounds for each
observation bucket in the emitted metric.  It also expects three more
columns to be present with the suffixes:
- `_bucket`, containing an array of cumulative counters for the
  observation buckets;
- `_sum`, the total sum of all observed values; and
- `_count`, the count of events that have been observed.

A flag has been added to the MetricMap struct to easily identify metrics
that should emit a histogram and the construction of a histogram metric
is aided by the pg.Array function and a new helper dbToUint64 function.

Finally, and example of usage is given in queries.yaml.

fixes #402

Signed-off-by: Corin Lawson <corin@responsight.com>

* Introduces tests for histogram support

Prior to this change, the histogram support was untested.

This change introduces a new integration test that reads a user query
containing a number of histogram metrics.  Also, additional checks have
been added to TestBooleanConversionToValueAndString to test dbToUint64.

Signed-off-by: Corin Lawson <corin@responsight.com>
2020-12-25 02:34:26 +11:00
Yann Hamon
b32e34a425
Do not panic on incorrect env (#457)
* do not panic when envs are set incorrectly

* do not panic when envs are set incorrectly - fix tests

Co-authored-by: Will Rouesnel <wrouesnel@wrouesnel.com>
2020-12-25 02:22:37 +11:00
Kevin Pullin
6354b0c7e7
Add query for 'pg_replication_slots' (#465)
The existing 'pg_stat_replication' data does not
include stats for inactive replication slots. This
commit adds a minimal amount of metrics from
'pg_replication_slots' to know if a slot is
active and its lag.

This is helpful to detect if an inactive slot
is causing the server to run out of storage due
to an inactive slot blocking WAL flushing.
2020-12-25 02:21:40 +11:00
Don Petersen
f870f9591b
Don't ignore errors in parseUserQueries (#362)
Failures in parsing the user's queries are just being swallowed, which
makes troubleshooting YAML issues frustrating/impossible. I'm presuming
this was not intentional, since there is error handling code in the
function that calls this one, though it is unreachable as far as I can
tell without this change.

Co-authored-by: Will Rouesnel <wrouesnel@wrouesnel.com>
2020-02-25 22:56:49 +11:00
Ben Kochie
aeec47ead4 Add a build info metric (#323)
* Add a build info metric

Add a standard Prometheus build info metric to make monitoring rollouts
easier.

* Update prometheus vendoring.

* Fix build error

Fix missing bool in builtinMetricMaps.

Signed-off-by: Ben Kochie <superq@gmail.com>
2019-11-26 00:16:23 +11:00
Will Rouesnel
03013dea2e
Re-add pg_stat_bgwriter metrics which were accidentally removed.
During a refactor the pg_stat_bgwriter metrics were accidentally removed
and not re-added by 34fdb69ee2.

This commit restores these metrics. Resolves #336.
2019-11-26 00:01:36 +11:00
Will Rouesnel
54a0cf0e63
Fix build error introduced by pg_archiver metrics bad merge.
2772da8dbe was missing an additional
parameter. This fixes the build.
2019-11-25 23:50:43 +11:00
Russ Garrett
2772da8dbe Export pg_stat_archiver metrics
These are useful for knowing if WAL archiving is working successfully.
2019-11-20 10:21:50 +11:00
sfalkon
c4508ff430 Refactoring: fix error 2019-11-20 10:18:20 +11:00
sfalkon
d74818ccac fix integration test 2019-11-20 10:18:20 +11:00
sfalkon
deac1c37db fix master database behavior 2019-11-20 10:18:20 +11:00
Benjamin P. Jung
9b13f5ec57 Add support for 'DATA_SOURCE_URI_FILE' envvar.
Closes #326 as is provides a viable solution to use a K8S init container
to fully contruct the PostgreSQL URI and 'hand it over' to the postgres_exporter
process.
2019-11-20 10:17:31 +11:00
Will Rouesnel
34fdb69ee2
Add support for optional namespace caching. (#319)
In the user queries.yml file, the created namespaces can now be optionally
cached by setting cache_seconds, which will prevent the query being re-run
within that timeframe if previous results are available.

Supercedes #211, credit to @SamSaffron for the original PR.
2019-11-01 00:17:31 +11:00
sfalkon
1385b4f658 Fix some autodiscovery problems (#314)
* Fix problem: If autodiscovery is enable exporter make connection twice to database from connetion string (exclude current database from SQL-query);

* Fix problem: don't get default metrics and settings if autodiscovery is enabled. Now you can use --disable-default-metrics and --disable-settings-metrics with --auto-discover-databases and
2019-10-31 22:09:30 +11:00
Alexis Sellier
ececfdeab7 Yaml parsing refactor (#299)
* Use struct instead of interface{} when parsing query user

* Use MappingOptions

* Split function to be more testable

* Rename function to parseUserQueries

* Start to add test about query parsing
2019-10-31 22:07:59 +11:00
Daniel Pintara
e1428a8330 Don't stop generating fingerprint while encountering value with "=" sign (#318) 2019-10-31 22:02:27 +11:00
Michael Kaye
d6f7ff1641 Expose pg_current_wal_lsn_bytes (#307) 2019-10-30 14:57:54 +11:00
Leo Antunes
e362f444aa [minor] fix landing page content-type (#305) 2019-10-30 14:57:12 +11:00
Dan Molik
043e68e067 Add retries to getServer() (#316)
Some backstory
==============

I was attempting to use postgres_exporter with the official Docker
container (https://hub.docker.com/_/postgres) In a Kubernetes
StatefulSet, with a side-car configuration, but found that I wasn't able
to connect even with sharing the Postgres Unix listening socket, between
both containers. After copying the container over to an Alpine base I
quickly found out that the postgres_exporter was actually starting
before the main Postres container had dropped the unix socket onto the
file system, a quick work around is to write a bash for loop checking
for the existence of a unix socket, however this would require
maintaining a container, besides other users may find retries useful on
startup.

Implementation
==============

All changes are made to the getServer function and variables are
local, I was unsure if it was worth adding command line switches but
this would allow for a more sophisticated backOff loop in the future.

Hope this help, and let me know if you would like me to changes
anything.
2019-10-30 14:54:18 +11:00
Dmitry Ulyanov
238f5c099a Fix pg_up metric returns last calculated value without explicit resetting (#291)
If exporter is scraped by multiple Prometheuses (as we do) - Collect() could be called concurrently. In result in some cases one of Prometheuses could get pg_up = 0, because it was explicitly set to zero on first Collect call.
2019-08-12 13:35:58 +10:00
Alexis Sellier
1ab8d2bbc8 Discover only databases that are not templates and allow connections (#297)
* Discover only databases that are not templates and allow connections

* Update readme
2019-08-12 11:40:58 +10:00