Skip to content

Feature: add option to export multiple pgbouncer instances#182

Closed
maikelpoot wants to merge 7 commits intoprometheus-community:masterfrom
maikelpoot:feature/multiple_scrape_endpoints
Closed

Feature: add option to export multiple pgbouncer instances#182
maikelpoot wants to merge 7 commits intoprometheus-community:masterfrom
maikelpoot:feature/multiple_scrape_endpoints

Conversation

@maikelpoot
Copy link
Copy Markdown

Why this PR

We TCP load balance our connections over multiple (4+) pgbouncer instances/processes to increase stability and performance. We would like to switch from our own exporter to the prometheus-community exporter but would like to run only one exporter instance instead of an exporter per pgbouncer instance.

What does the PR do

This PR will add the option to export multiple pgbouncer instances with one exporter instance using a yaml config file.
All the options are documented within the example config.yaml within this repo.
This config file also add the option to start the exporter even if the connection fails on startup.

Extra labels

To differentiate the metrics for each pgbouncer instances, you MUST configure a unique label/value set for each instance.
As shown in the example, this can be as simple as setting a unique pgbouncer_instance value for each instance.

The extra labels per instance are merged with the common extra_labels where the instance value has precedence over the common value

Requirements:

  • Every instance must define the same labels
  • Every instance must define at least have one label with an unique value.

If there requirements are not met the exporter will fail startup.

Example

When using the config file:

must_connect_on_startup: false
extra_labels:
  environment: prod
pgbouncers:
  - dsn: postgresql://user:pass@localhost:6432/pgbouncer?sslmode=disable
    extra_labels:
      pgbouncer_instance: set1-0
  - dsn: postgresql://user:pass@localhost:6433/pgbouncer?sslmode=disable
    extra_labels:
      pgbouncer_instance: set1-1
  - dsn: postgresql://user:pass@localhost:6434/pgbouncer?sslmode=disable
    extra_labels:
      pgbouncer_instance: set1-2

you now get 3 pgbouncer_up metrics:

% curl -s http://localhost:9127/metrics | grep "_up"
# HELP pgbouncer_up The pgbouncer scrape succeeded
# TYPE pgbouncer_up gauge
pgbouncer_up{environment="prod",pgbouncer_instance="set1-0"} 1
pgbouncer_up{environment="prod",pgbouncer_instance="set1-1"} 1
pgbouncer_up{environment="prod",pgbouncer_instance="set1-2"} 0

…one exporter instance.

Signed-off-by: Maikel Poot <maikel.poot@topicus.nl>
@maikelpoot maikelpoot force-pushed the feature/multiple_scrape_endpoints branch from af1f42f to dba0cb1 Compare November 1, 2024 10:51
@maikelpoot
Copy link
Copy Markdown
Author

Force-push was to add sign-off to the commit

@maikelpoot maikelpoot changed the title Feat(config): add option to export multiple pgbouncer instances Feature: add option to export multiple pgbouncer instances Nov 1, 2024
@maikelpoot
Copy link
Copy Markdown
Author

@SuperQ Can i do something to add some progress the review process?

@garima-trivedi
Copy link
Copy Markdown

@SuperQ : This is definitely a useful and most wanted feature.
Or is there any other PR which is going to provide same feature. i.e. "Support to export metrics from multiple pgbouncer instances"
Please, can we expedite support for this feature?

@maikelpoot
Copy link
Copy Markdown
Author

Hello @SuperQ and/or @stanhu ,

Any update about this PR and if it going to be merged?
Would love to see this merged instead of releasing and maintaining a fork

@SuperQ SuperQ self-requested a review January 13, 2025 08:37
@SuperQ
Copy link
Copy Markdown
Contributor

SuperQ commented Jan 13, 2025

Sorry, but this is not the correct way to implement multi-target support. I would be happy to support multiple pgbouncer instances from one exporter, but it needs to follow exporter design conventions.

Please read the multi-target exporter pattern guide.

For an example, here is how we added it to the postgres_exporter:

Copy link
Copy Markdown
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement multi-target support.

Signed-off-by: Maikel Poot <maikel.poot@topicus.nl>
Signed-off-by: Maikel Poot <maikel.poot@topicus.nl>
Signed-off-by: Maikel Poot <maikel.poot@topicus.nl>
@maikelpoot maikelpoot force-pushed the feature/multiple_scrape_endpoints branch from 078ba2b to 29a805e Compare February 7, 2025 13:21
@maikelpoot
Copy link
Copy Markdown
Author

due to some rebase problems getting old commits to be signed-off,
i decide to start a new branch with all the changes in one commit and open a new PR (#198).

@maikelpoot maikelpoot closed this Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants