Skip to content

Commit

Permalink
Update postgres exporter (#6780)
Browse files Browse the repository at this point in the history
* Update postgres exporter
* Make collector work with first DSN
* Enhance docs and test
* Update depcheck
  • Loading branch information
thampiotr authored Apr 3, 2024
1 parent 1a035e4 commit 2f0ac73
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/depcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ github_repos:
- github.com/google/dnsmasq_exporter v0.2.0
- github.com/ncabatoff/process-exporter v0.7.5
- github.com/prometheus/mysqld_exporter v0.13.0
- github.com/prometheus-community/postgres_exporter v0.10.0
- github.com/prometheus-community/postgres_exporter v0.15.0
- github.com/prometheus-community/windows_exporter v0.16.0
- github.com/percona/mongodb_exporter v0.20.7
- project: github.com/prometheus/prometheus
Expand Down
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,21 @@ Main (unreleased)
4317 to 55678 to align with upstream. (@rfratto)

- The default sync interval for `mimir.rules.kubernetes` has changed from `30s`
to `5m` to reduce load on Mimir. (@56quarters)
to `5m` to reduce load on Mimir. (@56quarters)

- `prometheus.exporter.postgres` has been updated to the latest upstream
version which changes the set of exported metrics. The following metrics were
removed: `pg_stat_database_session_time`, `pg_stat_database_sessions`,
`pg_stat_database_sessions_abandoned`, `pg_stat_database_sessions_fatal`,
`pg_stat_database_sessions_killed`, `pg_stat_database_idle_in_transaction_time`,
`pg_stat_database_checksum_failures`, `pg_stat_database_checksum_last_failure`,
`pg_stat_database_active_time`. The following metrics were
renamed: `pg_stat_bgwriter_buffers_alloc`, `pg_stat_bgwriter_buffers_backend`,
`pg_stat_bgwriter_buffers_backend_fsync`, `pg_stat_bgwriter_buffers_checkpoint`,
`pg_stat_bgwriter_buffers_clean`, `pg_stat_bgwriter_checkpoint_sync_time`,
`pg_stat_bgwriter_checkpoint_write_time`, `pg_stat_bgwriter_checkpoints_req`,
`pg_stat_bgwriter_checkpoints_timed`, `pg_stat_bgwriter_maxwritten_clean`,
`pg_stat_bgwriter_stats_reset` - the new names include the `_total` suffix. (@thampiotr)

### Enhancements

Expand Down Expand Up @@ -59,6 +73,9 @@ Main (unreleased)

- The `import.git` config block did not work with branches or tags this now fixes that behavior. (@mattdurham)

- Fixed an issue where creating a `prometheus.exporter.postgres` component with
multiple `data_source_names` would result in an error. (@thampiotr)

### Other changes

- Clustering for Grafana Agent in Flow mode has graduated from beta to stable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,35 @@ prometheus.exporter.postgres "LABEL" {
The following arguments are supported:

| Name | Type | Description | Default | Required |
| ---------------------------- | -------------- | ----------------------------------------------------------------------------- | ------- | -------- |
|------------------------------|----------------|-------------------------------------------------------------------------------|---------|----------|
| `data_source_names` | `list(secret)` | Specifies the Postgres server(s) to connect to. | | yes |
| `disable_settings_metrics` | `bool` | Disables collection of metrics from pg_settings. | `false` | no |
| `disable_default_metrics` | `bool` | When `true`, only exposes metrics supplied from `custom_queries_config_path`. | `false` | no |
| `custom_queries_config_path` | `string` | Path to YAML file containing custom queries to expose as metrics. | "" | no |
| `enabled_collectors` | `list(string)` | List of collectors to enable. See below for more detail. | [] | no |

The format for connection strings in `data_source_names` can be found in the [official postgresql documentation](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING).

See examples for the `custom_queries_config_path` file in the [postgres_exporter repository](https://github.com/prometheus-community/postgres_exporter/blob/master/queries.yaml).

**NOTE**: There are a number of environment variables that are not recommended for use, as they will affect _all_ `prometheus.exporter.postgres` components. A full list can be found in the [postgres_exporter repository](https://github.com/prometheus-community/postgres_exporter#environment-variables).

By default, the same set of metrics is enabled as in the upstream [postgres_exporter](https://github.com/prometheus-community/postgres_exporter/). If `custom_queries_config_path` is set, additional metrics defined in the given config file will be exposed.
If `disable_default_metrics` is set to `true`, only the metrics defined in the `custom_queries_config_path` file will be exposed.

A subset of metrics collectors can be controlled by setting the `enabled_collectors` argument. The following collectors are available for selection:
`database`, `database_wraparound`, `locks`, `long_running_transactions`, `postmaster`, `process_idle`,
`replication`, `replication_slot`, `stat_activity_autovacuum`, `stat_bgwriter`, `stat_database`,
`stat_statements`, `stat_user_tables`, `stat_wal_receiver`, `statio_user_indexes`, `statio_user_tables`,
`wal`, `xlog_location`.

By default, the following collectors are enabled: `database`, `locks`, `replication`, `replication_slot`, `stat_bgwriter`, `stat_database`,
`stat_user_tables`, `statio_user_tables`, `wal`.

{{< admonition type="note" >}}
Due to a limitation of the upstream exporter, when multiple `data_source_names` are used, the collectors that are controlled via the `enabled_collectors` argument will only be applied to the first data source in the list.
{{< /admonition >}}

## Blocks

The following blocks are supported:
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ require (
github.com/aws/smithy-go v1.20.1 // indirect
github.com/beevik/ntp v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver v3.5.2-0.20180723201105-3c1074078d32+incompatible // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/boynux/squid-exporter v1.10.5-0.20230618153315-c1fae094e18e
github.com/c2h5oh/datasize v0.0.0-20220606134207-859f65c6625b // indirect
Expand Down Expand Up @@ -752,7 +751,7 @@ replace (
// https://github.com/grafana/cadvisor/tree/grafana-v0.47-noglobals
github.com/google/cadvisor => github.com/grafana/cadvisor v0.0.0-20231110094609-5f7917925dea

github.com/prometheus-community/postgres_exporter => github.com/grafana/postgres_exporter v0.8.1-0.20210722175051-db35d7c2f520
github.com/prometheus-community/postgres_exporter => github.com/grafana/postgres_exporter v0.15.1-0.20240402092333-fad5f95ea113 // exporter-package-v0.15.0 branch

// TODO(marctc): remove once this PR is merged upstream: https://github.com/prometheus/mysqld_exporter/pull/774
github.com/prometheus/mysqld_exporter => github.com/grafana/mysqld_exporter v0.12.2-0.20231005125903-364b9c41e595
Expand Down
Loading

0 comments on commit 2f0ac73

Please sign in to comment.