Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New metricbeat module: pgbouncer #41174

Open
wants to merge 64 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
458f523
adds pgbouncer module
manuelsaks Nov 12, 2023
c366ea0
adds pgbouncer module
manuelsaks Oct 8, 2024
9754c9d
add metricsets
manuelsaks Oct 8, 2024
54bbcc7
fix list metricset
manuelsaks Oct 8, 2024
0d688c2
fix
manuelsaks Oct 8, 2024
21a248c
add mem metricset
manuelsaks Oct 8, 2024
4731009
add mem metricset
manuelsaks Oct 8, 2024
ab504d1
add mem metricset
manuelsaks Oct 8, 2024
5cfe4f4
simplify metricsets
manuelsaks Oct 8, 2024
182af1d
simplify metricsets
manuelsaks Oct 8, 2024
ad0a653
add meta
manuelsaks Oct 8, 2024
a7d301a
add tests
manuelsaks Oct 8, 2024
a929b0b
cleanup
manuelsaks Oct 8, 2024
378fcda
formatting
manuelsaks Oct 8, 2024
c6d1a11
Merge branch 'main' into module_pgbouncer
manuelsaks Oct 8, 2024
4f0ea69
Add the license header
manuelsaks Oct 8, 2024
8fa80ea
Merge branch 'module_pgbouncer' of github.com:manuelsaks/beats into m…
manuelsaks Oct 8, 2024
8695678
Add the license header
manuelsaks Oct 8, 2024
be437de
Refactor ParseURL tests with MockModule
manuelsaks Oct 8, 2024
f6523bb
Cleanup unnecessary print
manuelsaks Oct 8, 2024
3030408
Add safe type assertion in Fetch
manuelsaks Oct 8, 2024
58271ac
Cleanup unnecessary print
manuelsaks Oct 8, 2024
56a21a0
Update
manuelsaks Oct 8, 2024
44ea4d4
Add assertion
manuelsaks Oct 8, 2024
c3f2a15
Change formatter
manuelsaks Oct 8, 2024
be37fa1
Remove unnecessary sprintf
manuelsaks Oct 8, 2024
70486b6
Add pgbouncer
manuelsaks Oct 8, 2024
729c222
Update pgbouncer
manuelsaks Oct 8, 2024
c8cb4d8
Fix import order with goimports
manuelsaks Oct 8, 2024
6834bc7
Fix import order with goimports
manuelsaks Oct 8, 2024
0c2195d
Add generated files
manuelsaks Oct 8, 2024
0518669
Add pgbouncer
manuelsaks Oct 8, 2024
ee77e66
Add pgbouncer
manuelsaks Oct 8, 2024
c72880a
Use testing version
manuelsaks Oct 8, 2024
213faf0
Refactor fetch method
manuelsaks Oct 8, 2024
9e63bbf
Refactor error logging
manuelsaks Oct 10, 2024
5e8158d
Copy config files in build instead of mounting
manuelsaks Oct 10, 2024
663b500
Revert "Refactor error logging"
manuelsaks Oct 10, 2024
fdd7d0f
Add build tags and fix convention name
manuelsaks Oct 11, 2024
3d1ce4b
Merge branch 'main' into module_pgbouncer
manuelsaks Oct 11, 2024
044a889
Merge branch 'main' into module_pgbouncer
manuelsaks Oct 14, 2024
ceb5f55
Merge branch 'main' into module_pgbouncer
pierrehilbert Oct 21, 2024
6667c4d
Merge branch 'main' into module_pgbouncer
pierrehilbert Oct 22, 2024
6e7d90d
Merge branch 'main' into module_pgbouncer
pierrehilbert Nov 6, 2024
75b3dde
Merge branch 'main' into module_pgbouncer
pierrehilbert Nov 13, 2024
0a23250
Merge branch 'main' into module_pgbouncer
pierrehilbert Nov 18, 2024
2222740
Refactor: Inline resultMap assignment
manuelsaks Dec 10, 2024
79260f5
Normalize fields to json
manuelsaks Dec 10, 2024
aba1559
Refactor: Use context in Fetch method
manuelsaks Dec 10, 2024
7973937
Refactor: Use context in Fetch method
manuelsaks Dec 10, 2024
0c5ed2d
update normalized data
manuelsaks Dec 10, 2024
2046288
Refactor: Use context in Fetch method
manuelsaks Dec 10, 2024
1123f12
Change to metricset logger
manuelsaks Dec 15, 2024
5971098
Update fields file
manuelsaks Dec 15, 2024
f470c86
Update fields
manuelsaks Dec 15, 2024
42dffe5
Merge branch 'main' into module_pgbouncer
manuelsaks Dec 15, 2024
de66b87
update
manuelsaks Dec 15, 2024
5304c50
implement warn instead of err
manuelsaks Dec 22, 2024
52ed64d
add err check
manuelsaks Dec 22, 2024
b342512
refactor data structures
manuelsaks Dec 22, 2024
15a98ab
update structures
manuelsaks Dec 22, 2024
493e427
remove redundant log settings
manuelsaks Feb 28, 2025
853061d
Merge branch 'main' into module_pgbouncer
manuelsaks Mar 1, 2025
1461206
Update reference to make pipeline working
manuelsaks Mar 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
913 changes: 913 additions & 0 deletions metricbeat/docs/fields.asciidoc

Large diffs are not rendered by default.

130 changes: 130 additions & 0 deletions metricbeat/docs/modules/pgbouncer.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
////
This file is generated! See scripts/mage/docs_collector.go
////

:modulename: pgbouncer
:edit_url: https://github.com/elastic/beats/edit/main/metricbeat/module/pgbouncer/_meta/docs.asciidoc


[[metricbeat-module-pgbouncer]]
== PGBouncer module

include::{libbeat-dir}/shared/integration-link.asciidoc[]

:modulename!:

PgBouncer is a popular, lightweight connection pooler for PostgreSQL. This module allows you to monitor PgBouncer using Metricbeat, gathering metrics that help optimize performance and maintain stability.

This module periodically fetches metrics from the PgBouncer poolers available at https://www.pgbouncer.org/.

Default metricsets include:
- `lists`: Provides a list of databases and users currently connected to PgBouncer.
- `mem`: Monitors memory usage details within PgBouncer, helping detect memory leaks or spikes.
- `pools`: Tracks the status of connection pools, including active and idle connections.
- `stats`: Collects comprehensive statistics on database connections and queries processed.

[float]
=== Module-specific configuration notes

When configuring the `hosts` option, you must use PostgreSQL URLs of the following format with PgBouncer database name included:

[source,yaml]
-----------------------------------
[postgres://][user:pass@]host[:port]/pgbouncer[?options]
-----------------------------------

The URL can be as simple as:

[source,yaml]
----------------------------------------------------------------------
- module: pgbouncer
hosts: ["postgres://localhost/pgbouncer"]
----------------------------------------------------------------------

Or more complex like:

[source,yaml]
----------------------------------------------------------------------
- module: pgbouncer
hosts: ["postgres://localhost/pgbouncer:40001?sslmode=disable", "postgres://otherhost/pgbouncer:40001"]
----------------------------------------------------------------------

Usernames and passwords specified in the URL take precedence over those specified in the `username` and `password` configuration options.
For security best practices, consider using environment variables to pass sensitive information securely.

[source,yaml]
----
- module: postgresql
metricsets: ["pools"]
hosts: ["postgres://localhost/pgbouncer:6432"]
username: root
password: test
----

:edit_url:

[float]
=== Example configuration

The PGBouncer module supports the standard configuration options that are described
in <<configuration-metricbeat>>. Here is an example configuration:

[source,yaml]
----
metricbeat.modules:
- module: pgbouncer
enabled: true
metricsets:
# Monitors the current state of the connection pools including metrics like active connections, idle connections, waiting connections, and max allowed connections
# Essential for assessing load and capacity
- pools

# Provides comprehensive data on connections, pools, and queries including total queries, average query duration, and query rates
# Useful for performance tuning and identifying bottlenecks
- stats

# Details current activity of the PgBouncer service showing lists of databases and users
# Helps in auditing access and understanding user distribution
- lists

# Reports on the sizes of internal memory allocations to track memory usage and potential leaks, critical for maintaining system stability
- memory

period: 10s

# The host must be passed as PostgreSQL URL. Example:
# postgres://localhost/pgbouncer:6432?sslmode=disable
# The available parameters are documented here:
# https://godoc.org/github.com/lib/pq#hdr-Connection_String_Parameters
# You have to specify the pgbouncer as the database name.
hosts: ["postgres://localhost/pgbouncer:6432"]

# Username to use when connecting to PostgreSQL. Empty by default.
#username: user

# Password to use when connecting to PostgreSQL. Empty by default.
#password: pass
----

[float]
=== Metricsets

The following metricsets are available:

* <<metricbeat-metricset-pgbouncer-lists,lists>>

* <<metricbeat-metricset-pgbouncer-mem,mem>>

* <<metricbeat-metricset-pgbouncer-pools,pools>>

* <<metricbeat-metricset-pgbouncer-stats,stats>>

include::pgbouncer/lists.asciidoc[]

include::pgbouncer/mem.asciidoc[]

include::pgbouncer/pools.asciidoc[]

include::pgbouncer/stats.asciidoc[]

:edit_url!:
27 changes: 27 additions & 0 deletions metricbeat/docs/modules/pgbouncer/lists.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
////
This file is generated! See scripts/mage/docs_collector.go
////
:edit_url: https://github.com/elastic/beats/edit/main/metricbeat/module/pgbouncer/lists/_meta/docs.asciidoc


[[metricbeat-metricset-pgbouncer-lists]]
=== PGBouncer lists metricset

include::../../../module/pgbouncer/lists/_meta/docs.asciidoc[]

This is a default metricset. If the host module is unconfigured, this metricset is enabled by default.

:edit_url:

==== Fields

For a description of each field in the metricset, see the
<<exported-fields-pgbouncer,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/pgbouncer/lists/_meta/data.json[]
----
:edit_url!:
27 changes: 27 additions & 0 deletions metricbeat/docs/modules/pgbouncer/mem.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
////
This file is generated! See scripts/mage/docs_collector.go
////
:edit_url: https://github.com/elastic/beats/edit/main/metricbeat/module/pgbouncer/mem/_meta/docs.asciidoc


[[metricbeat-metricset-pgbouncer-mem]]
=== PGBouncer mem metricset

include::../../../module/pgbouncer/mem/_meta/docs.asciidoc[]

This is a default metricset. If the host module is unconfigured, this metricset is enabled by default.

:edit_url:

==== Fields

For a description of each field in the metricset, see the
<<exported-fields-pgbouncer,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/pgbouncer/mem/_meta/data.json[]
----
:edit_url!:
27 changes: 27 additions & 0 deletions metricbeat/docs/modules/pgbouncer/pools.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
////
This file is generated! See scripts/mage/docs_collector.go
////
:edit_url: https://github.com/elastic/beats/edit/main/metricbeat/module/pgbouncer/pools/_meta/docs.asciidoc


[[metricbeat-metricset-pgbouncer-pools]]
=== PGBouncer pools metricset

include::../../../module/pgbouncer/pools/_meta/docs.asciidoc[]

This is a default metricset. If the host module is unconfigured, this metricset is enabled by default.

:edit_url:

==== Fields

For a description of each field in the metricset, see the
<<exported-fields-pgbouncer,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/pgbouncer/pools/_meta/data.json[]
----
:edit_url!:
27 changes: 27 additions & 0 deletions metricbeat/docs/modules/pgbouncer/stats.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
////
This file is generated! See scripts/mage/docs_collector.go
////
:edit_url: https://github.com/elastic/beats/edit/main/metricbeat/module/pgbouncer/stats/_meta/docs.asciidoc


[[metricbeat-metricset-pgbouncer-stats]]
=== PGBouncer stats metricset

include::../../../module/pgbouncer/stats/_meta/docs.asciidoc[]

This is a default metricset. If the host module is unconfigured, this metricset is enabled by default.

:edit_url:

==== Fields

For a description of each field in the metricset, see the
<<exported-fields-pgbouncer,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/pgbouncer/stats/_meta/data.json[]
----
:edit_url!:
6 changes: 6 additions & 0 deletions metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ This file is generated! See scripts/mage/docs_collector.go
|<<metricbeat-metricset-panw-routing,routing>> beta[]
|<<metricbeat-metricset-panw-system,system>> beta[]
|<<metricbeat-metricset-panw-vpn,vpn>> beta[]
|<<metricbeat-module-pgbouncer,PGBouncer>> |image:./images/icon-no.png[No prebuilt dashboards] |
.4+| .4+| |<<metricbeat-metricset-pgbouncer-lists,lists>>
|<<metricbeat-metricset-pgbouncer-mem,mem>>
|<<metricbeat-metricset-pgbouncer-pools,pools>>
|<<metricbeat-metricset-pgbouncer-stats,stats>>
|<<metricbeat-module-php_fpm,PHP_FPM>> |image:./images/icon-no.png[No prebuilt dashboards] |
.2+| .2+| |<<metricbeat-metricset-php_fpm-pool,pool>>
|<<metricbeat-metricset-php_fpm-process,process>>
Expand Down Expand Up @@ -384,6 +389,7 @@ include::modules/nginx.asciidoc[]
include::modules/openmetrics.asciidoc[]
include::modules/oracle.asciidoc[]
include::modules/panw.asciidoc[]
include::modules/pgbouncer.asciidoc[]
include::modules/php_fpm.asciidoc[]
include::modules/postgresql.asciidoc[]
include::modules/prometheus.asciidoc[]
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/include/list_common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,40 @@ metricbeat.modules:
include: []
exclude: []

#------------------------------ PGBouncer Module ------------------------------
- module: pgbouncer
enabled: true
metricsets:
# Monitors the current state of the connection pools including metrics like active connections, idle connections, waiting connections, and max allowed connections
# Essential for assessing load and capacity
- pools

# Provides comprehensive data on connections, pools, and queries including total queries, average query duration, and query rates
# Useful for performance tuning and identifying bottlenecks
- stats

# Details current activity of the PgBouncer service showing lists of databases and users
# Helps in auditing access and understanding user distribution
- lists

# Reports on the sizes of internal memory allocations to track memory usage and potential leaks, critical for maintaining system stability
- memory

period: 10s

# The host must be passed as PostgreSQL URL. Example:
# postgres://localhost/pgbouncer:6432?sslmode=disable
# The available parameters are documented here:
# https://godoc.org/github.com/lib/pq#hdr-Connection_String_Parameters
# You have to specify the pgbouncer as the database name.
hosts: ["postgres://localhost/pgbouncer:6432"]

# Username to use when connecting to PostgreSQL. Empty by default.
#username: user

# Password to use when connecting to PostgreSQL. Empty by default.
#password: pass

#------------------------------- PHP_FPM Module -------------------------------
- module: php_fpm
metricsets:
Expand Down
5 changes: 5 additions & 0 deletions metricbeat/module/pgbouncer/_meta/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM edoburu/pgbouncer
COPY ./pgbouncer.ini /etc/pgbouncer/pgbouncer.ini
COPY ./userlist.txt /etc/pgbouncer/userlist.txt
ENTRYPOINT ["/entrypoint.sh"]
CMD ["/usr/bin/pgbouncer", "/etc/pgbouncer/pgbouncer.ini"]
32 changes: 32 additions & 0 deletions metricbeat/module/pgbouncer/_meta/config.reference.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- module: pgbouncer
enabled: true
metricsets:
# Monitors the current state of the connection pools including metrics like active connections, idle connections, waiting connections, and max allowed connections
# Essential for assessing load and capacity
- pools

# Provides comprehensive data on connections, pools, and queries including total queries, average query duration, and query rates
# Useful for performance tuning and identifying bottlenecks
- stats

# Details current activity of the PgBouncer service showing lists of databases and users
# Helps in auditing access and understanding user distribution
- lists

# Reports on the sizes of internal memory allocations to track memory usage and potential leaks, critical for maintaining system stability
- memory

period: 10s

# The host must be passed as PostgreSQL URL. Example:
# postgres://localhost/pgbouncer:6432?sslmode=disable
# The available parameters are documented here:
# https://godoc.org/github.com/lib/pq#hdr-Connection_String_Parameters
# You have to specify the pgbouncer as the database name.
hosts: ["postgres://localhost/pgbouncer:6432"]

# Username to use when connecting to PostgreSQL. Empty by default.
#username: user

# Password to use when connecting to PostgreSQL. Empty by default.
#password: pass
11 changes: 11 additions & 0 deletions metricbeat/module/pgbouncer/_meta/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
metricbeat.modules:
- module: pgbouncer
# metricsets:
# - stats
# - lists
# - pools
# - mem
period: 10s
hosts: ["postgresql://localhost:6432/pgbouncer?sslmode=disable"]
# username: test
# password: password
17 changes: 17 additions & 0 deletions metricbeat/module/pgbouncer/_meta/config_local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
metricbeat.modules:
- module: pgbouncer
metricsets:
- mem
- lists
- stats
- pools
period: 10s
hosts: ["postgresql://localhost:6432/pgbouncer?sslmode=disable"]
username: test
password: password
output.elasticsearch:
hosts: ["http://localhost:9200"]
username: elastic
password: xxxx
indices:
- index: "test"
Loading
Loading