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

metricbeat/module/postgresql: Add PostgreSQL Replication metricset #35562

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
25e6aff
Add PostgresSQL Replication metricset
zxcSora May 24, 2023
a3a716b
Fixes after review
zxcSora May 31, 2023
c098a05
impove docs
zxcSora May 31, 2023
6571445
add Uint parse
zxcSora Jun 1, 2023
55d70a1
Change Uint size, fix comment
zxcSora Jun 6, 2023
1d7027d
Change PG query
zxcSora Jun 6, 2023
9e2c121
Merge branch 'main' into main
shmsr Jul 3, 2023
8d2d0f4
Merge branch 'main' into main
shmsr Jul 5, 2023
93eaee6
Merge branch 'main' into main
shmsr Jul 7, 2023
50e66da
update changelog, fix nitpicks
zxcSora Jul 10, 2023
f3143d8
Fix recovering from invalid output configuration under Elastic-Agent …
belimawr Jul 7, 2023
4838145
chore: Updated to content "" in file "testing/environments/snapshot.y…
apmmachine Jul 10, 2023
eebc5ae
Merge branch 'main' into main
shmsr Jul 11, 2023
300b3e3
Update CHANGELOG.next.asciidoc
zxcSora Jul 11, 2023
beec498
Merge branch 'main' into main
ishleenk17 Jul 14, 2023
ae6cc32
Merge branch 'main' into main
zxcSora Jul 17, 2023
eec0bd2
Merge branch 'main' into main
zxcSora Jul 20, 2023
4a84a0f
Merge branch 'main' into main
zxcSora Jul 21, 2023
9d1e267
Merge branch 'main' into main
zxcSora Jul 26, 2023
f33bc75
Merge branch 'main' into main
zxcSora Jul 27, 2023
0d1c619
Merge branch 'main' into main
zxcSora Jul 28, 2023
ee7ca86
Merge branch 'main' into main
zxcSora Jul 31, 2023
bf6179b
Merge branch 'main' into main
zxcSora Aug 1, 2023
55f3359
Merge branch 'main' into main
zxcSora Aug 1, 2023
dd53fa4
Merge branch 'main' into main
zxcSora Sep 19, 2023
3adfd57
fix panic
zxcSora Sep 19, 2023
659bb76
fix copy-paste misstake
zxcSora Sep 19, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ automatic splitting at root level, if root level element is an array. {pull}3415
- Improve documentation for ActiveMQ module {issue}35113[35113] {pull}35558[35558]
- Fix EC2 host.cpu.usage {pull}35717[35717]
- Resolve statsd module's prematurely halting of metrics parsing upon encountering an invalid packet. {pull}35075[35075]
- Add support for PostgreSQL replication metrics {pull}35562[35562]

*Osquerybeat*

Expand Down
21 changes: 21 additions & 0 deletions libbeat/common/schema/mapstrstr/mapstrstr.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ func Int(key string, opts ...schema.SchemaOption) schema.Conv {
return schema.SetOptions(schema.Conv{Key: key, Func: toInt}, opts)
}

// toUint converts value to uint. In case of error, returns 0
func toUint(key string, data map[string]interface{}) (interface{}, error) {
str, err := getString(key, data)
if err != nil {
return false, err
}

value, err := strconv.ParseUint(str, 10, 64)
if err != nil {
msg := fmt.Sprintf("error converting param to uint: `%s`", str)
return 0, schema.NewWrongFormatError(key, msg)
}

return value, nil
}

// Uint creates a Conv object for parsing integers
func Uint(key string, opts ...schema.SchemaOption) schema.Conv {
return schema.SetOptions(schema.Conv{Key: key, Func: toUint}, opts)
}

// toStr converts value to str. In case of error, returns ""
func toStr(key string, data map[string]interface{}) (interface{}, error) {
return getString(key, data)
Expand Down
197 changes: 197 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -56324,6 +56324,203 @@ type: date

--

[float]
=== replication

One row per replication, showing database replication statistics. Collected by querying pg_stat_replication.



*`postgresql.replication.write_lag`*::
+
--
Elapsed time during committed WALs from primary to the replica.
zxcSora marked this conversation as resolved.
Show resolved Hide resolved


type: long

--

*`postgresql.replication.state`*::
+
--
Current WAL sender state.


type: keyword

--

*`postgresql.replication.sync_priority`*::
+
--
Priority of this standby server for being chosen as the synchronous standby.


type: long

--

*`postgresql.replication.backend_start`*::
+
--
Time when this process was started, i.e., when the client connected to this WAL sender.


type: long

--

*`postgresql.replication.backend_xmin`*::
+
--
This standby's xmin horizon reported by hot_standby_feedback.


type: long

--

*`postgresql.replication.replay_lag`*::
+
--
Elapsed time during committed WALs from primary to the replica. Fully committed to replica node.


type: long

--

*`postgresql.replication.flush_lag`*::
+
--
The elapsed time during committed WALs from primary to the replica. WALs have already been flushed but have not yet been applied.


type: long

--

*`postgresql.replication.pid`*::
+
--
Process ID of a WAL sender process.


type: long

--

*`postgresql.replication.client.address`*::
+
--
IP address of the client connected to this WAL sender. If this field is null, it indicates that the client is connected via a Unix socket on the server machine.


type: long

--

*`postgresql.replication.client.port`*::
+
--
TCP port number that the client is using for communication with this WAL sender, or -1 if a Unix socket is used.


type: long

--

*`postgresql.replication.client.hostname`*::
+
--
Host name of the connected client, as reported by a reverse DNS lookup of client_addr. This field will only be non-null for IP connections, and only when log_hostname is enabled.


type: long

--

*`postgresql.replication.replay_lsn`*::
+
--
Last transaction log position replayed into the database on this standby server.


type: long

--

*`postgresql.replication.user.name`*::
+
--
Name of the user logged into this WAL sender process.


type: keyword

--

*`postgresql.replication.user.id`*::
+
--
OID of the user logged into this WAL sender process.


type: long

--

*`postgresql.replication.sync_state`*::
+
--
Synchronous state of this standby server.


type: keyword

--

*`postgresql.replication.flush_lsn`*::
+
--
Last transaction log position flushed to disk by this standby server.


type: long

--

*`postgresql.replication.application_name`*::
+
--
Name of the application that is connected to this WAL sender.


type: keyword

--

*`postgresql.replication.write_lsn`*::
+
--
Last transaction log position written to disk by this standby server.


type: long

--

*`postgresql.replication.sent_lsn`*::
+
--
Last transaction log position sent on this connection.


type: long

--

[float]
=== statement

Expand Down
7 changes: 7 additions & 0 deletions metricbeat/docs/modules/postgresql.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ metricbeat.modules:
# Stats about every PostgreSQL process
- activity

# Stats about every PostgreSQL replication process
- replication

# Stats about every statement executed in the server. It requires the
# `pg_stats_statement` library to be configured in the server.
#- statement
Expand Down Expand Up @@ -126,6 +129,8 @@ The following metricsets are available:

* <<metricbeat-metricset-postgresql-database,database>>

* <<metricbeat-metricset-postgresql-replication,replication>>

* <<metricbeat-metricset-postgresql-statement,statement>>

include::postgresql/activity.asciidoc[]
Expand All @@ -134,6 +139,8 @@ include::postgresql/bgwriter.asciidoc[]

include::postgresql/database.asciidoc[]

include::postgresql/replication.asciidoc[]

include::postgresql/statement.asciidoc[]

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


[[metricbeat-metricset-postgresql-replication]]
=== PostgreSQL replication metricset

beta[]

include::../../../module/postgresql/replication/_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-postgresql,exported fields>> section.

Here is an example document generated by this metricset:

[source,json]
----
include::../../../module/postgresql/replication/_meta/data.json[]
----
:edit_url!:
3 changes: 2 additions & 1 deletion metricbeat/docs/modules_list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ This file is generated! See scripts/mage/docs_collector.go
.2+| .2+| |<<metricbeat-metricset-php_fpm-pool,pool>>
|<<metricbeat-metricset-php_fpm-process,process>>
|<<metricbeat-module-postgresql,PostgreSQL>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.4+| .4+| |<<metricbeat-metricset-postgresql-activity,activity>>
.5+| .5+| |<<metricbeat-metricset-postgresql-activity,activity>>
|<<metricbeat-metricset-postgresql-bgwriter,bgwriter>>
|<<metricbeat-metricset-postgresql-database,database>>
|<<metricbeat-metricset-postgresql-replication,replication>> beta[]
|<<metricbeat-metricset-postgresql-statement,statement>>
|<<metricbeat-module-prometheus,Prometheus>> |image:./images/icon-yes.png[Prebuilt dashboards are available] |
.3+| .3+| |<<metricbeat-metricset-prometheus-collector,collector>>
Expand Down
1 change: 1 addition & 0 deletions metricbeat/include/list_common.go

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

3 changes: 3 additions & 0 deletions metricbeat/metricbeat.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,9 @@ metricbeat.modules:
# Stats about every PostgreSQL process
- activity

# Stats about every PostgreSQL replication process
- replication

# Stats about every statement executed in the server. It requires the
# `pg_stats_statement` library to be configured in the server.
#- statement
Expand Down
3 changes: 3 additions & 0 deletions metricbeat/module/postgresql/_meta/config.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# Stats about every PostgreSQL process
- activity

# Stats about every PostgreSQL replication process
- replication

# Stats about every statement executed in the server. It requires the
# `pg_stats_statement` library to be configured in the server.
#- statement
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/postgresql/fields.go

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

42 changes: 42 additions & 0 deletions metricbeat/module/postgresql/replication/_meta/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"@timestamp": "2023-05-24T12:22:59.233Z",
"event": {
"dataset": "postgresql.replication",
"duration": 115000,
"module": "postgresql"
},
"metricset": {
"name": "replication",
"period": 10000
},
"postgresql": {
"replication": {
"write_lag": "0",
"state": "streaming",
"sync_priority": 0,
"backend_start": "2023-05-23T17:01:53.697Z",
"replay_lag": "0",
"flush_lag": "0",
"pid": 2516780,
"client": {
"address": "192.168.128.2",
"port": 46594,
"hostname": ""
},
"replay_lsn": "A0/60003558",
"user": {
"name": "replicator",
"id": 16442
},
"sync_state": "async",
"flush_lsn": "A0/60003558",
"application_name": "walreceiver",
"write_lsn": "A0/60003558",
"sent_lsn": "A0/60003558"
}
},
"service": {
"address": "postgres://localhost:5432/postgres?connect_timeout=10",
"type": "postgresql"
}
}
Loading