-
Notifications
You must be signed in to change notification settings - Fork 137
[!] add Prometheus exporter as a pgwatch source #1405
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
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
5a60a35
add spec for prometheus sources
pashagolub c5d7482
update spec with a simpler metric definitions
pashagolub bbd78d4
add spec to refactor SourceConn as interface
pashagolub 118440c
rebase specs on batch metric fetching
pashagolub 599ea15
add `NewFakeExporter()` to `testutil`
pashagolub 5bb2f03
extract `SourceConn` interface and `DbConn` struct
pashagolub 867c3ed
add `prometheus` source kind
pashagolub f811f4a
implement `PromConn.Connect()`, `Ping()`, `FetchRuntimeInfo()`
pashagolub 27a304d
use `Ping()` call in ping command
pashagolub 15efc0d
implement `ScrapeAll` and extend `MeasurementEnvelope` with `SourceKind`
pashagolub 869350d
make `Reaper` an interface and `reaper` a struct implementing it
pashagolub fc414ab
remove `sourceReapers`, use `cancelFuncs` only
pashagolub 8cab1c8
rename `SourceReaper` to `DbConnReaper`
pashagolub 716464f
implement `PromReaper`
pashagolub 93f14c3
move `DbConnReaper` into `database.go`
pashagolub 967ffdc
rename `prom_reaper.go` to `prometheus.go`
pashagolub 7138fef
make `NewReaper` return an interface, while `newReaper` return struct
pashagolub d076391
support prom-sourced envelopes in `PrometheusWriter`
pashagolub 021b593
add `postgres-exporter-basic` preset and prometheus source example
pashagolub b8ff922
add "Monitoring a Prometheus Exporter" howto
pashagolub d3114d9
add `prometheus` source kind to webui
pashagolub f221d8e
add `prometheus` source kind migration for postgres sink schema
pashagolub e9ed463
use `GET` request in `PromConn.Ping()`
pashagolub ee08943
fix `ResolveDatabases()` for Prometheus sources
pashagolub 78bc2b9
add Prometheus sources to docker compose test instance
pashagolub 4dfc61c
add "Patroni Cluster Overview" dashboards
pashagolub 9e2501f
fix schema migration tests
pashagolub 1734b55
rename `batchEntry.name` to `batchEntry.metricName` to match master
pashagolub 4882b36
fix errcheck warning: discard `executeBatch` error in integration test
pashagolub 7628ff3
migrate patroni dashboards to v13
pashagolub 7d64596
add all Patroni metrics to patroni preset
pashagolub b661947
add panels for all Patroni metrics
pashagolub e5f40d6
chore
pashagolub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| --- | ||
| title: Monitoring a Prometheus Exporter | ||
| --- | ||
|
|
||
| pgwatch's native strength is collecting metrics from PostgreSQL via SQL queries. For metrics that | ||
| cannot be expressed as SQL — such as HA cluster state, node roles, replication lag as seen by the | ||
| cluster manager, or OS-level metrics like CPU, memory, and I/O that are not accessible to Postgres | ||
| without special extensions — pgwatch can scrape any HTTP endpoint that exposes data in the | ||
| [Prometheus text exposition format](https://prometheus.io/docs/instrumenting/exposition_formats/). | ||
|
|
||
| A typical use case is [Patroni](https://patroni.readthedocs.io/), which exposes cluster health | ||
| metrics (node role, WAL position, DCS connectivity, …) through its `GET /metrics` endpoint. These | ||
| metrics complement the SQL-based metrics already collected from the PostgreSQL instances themselves. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| Add a source with `kind: prometheus`, point `conn_str` at Patroni's `/metrics` endpoint, and choose | ||
| the built-in `patroni` preset: | ||
|
|
||
| ```yaml | ||
| - name: patroni-prod-node1 | ||
| kind: prometheus | ||
| conn_str: "http://patroni-node1:8008/metrics" | ||
| preset_metrics: patroni | ||
| is_enabled: true | ||
| ``` | ||
|
|
||
| pgwatch periodically fetches the URL, parses the Prometheus text format, and forwards each metric | ||
| family to the configured sink. | ||
|
|
||
| ## Connection String Format | ||
|
|
||
| The `conn_str` field is a plain HTTP or HTTPS URL. Optional query parameters control TLS | ||
| validation and are stripped before the request is sent to the exporter: | ||
|
|
||
| | Query parameter | Description | | ||
| |---|---| | ||
| | `tlsskipverify=true` | Disable TLS certificate verification (use with caution). | | ||
| | `tlsrootcert=<path>` | Absolute path to a PEM-encoded CA certificate file used to verify the server certificate. | | ||
|
|
||
| Basic Auth credentials are embedded in the URL in the standard `user:password@host` form. | ||
|
|
||
| ### Examples | ||
|
|
||
| ```yaml | ||
| # Plain HTTP – no auth | ||
| conn_str: "http://patroni-node1:8008/metrics" | ||
|
|
||
| # HTTPS with a custom CA certificate | ||
| conn_str: "https://patroni-node1:8008/metrics?tlsrootcert=/etc/ssl/certs/my-ca.pem" | ||
|
|
||
| # HTTPS with Basic Auth and TLS certificate verification disabled | ||
| conn_str: "https://user:secret@patroni-node1:8008/metrics?tlsskipverify=true" | ||
| ``` | ||
|
|
||
| ## Presets | ||
|
|
||
| ### `patroni` | ||
|
|
||
| Covers the key metric families emitted by Patroni's `GET /metrics` endpoint (default port **8008**): | ||
|
|
||
| | Metric family | What it measures | Interval | | ||
| |---|---|---| | ||
| | `patroni_postgres_running` | 1 if Postgres is running | 30 s | | ||
| | `patroni_primary` | 1 if this node is the primary | 30 s | | ||
| | `patroni_replica` | 1 if this node is a replica | 30 s | | ||
| | `patroni_standby_leader` | 1 if this node is standby leader | 30 s | | ||
| | `patroni_cluster_unlocked` | 1 if the cluster has no leader lock | 30 s | | ||
| | `patroni_xlog_location` | WAL location on primary | 30 s | | ||
| | `patroni_xlog_received_location` | received WAL on replica | 30 s | | ||
| | `patroni_xlog_replayed_location` | replayed WAL on replica | 30 s | | ||
| | `patroni_dcs_last_seen` | seconds since DCS last contacted | 30 s | | ||
| | `patroni_pending_restart` | 1 if node needs a restart | 60 s | | ||
| | `patroni_is_paused` | 1 if auto-failover is disabled | 60 s | | ||
| | `patroni_postgres_timeline` | Postgres timeline | 60 s | | ||
|
|
||
| ### `postgres-exporter-basic` | ||
|
|
||
| Covers the most important metric families emitted by | ||
| [postgres_exporter](https://github.com/prometheus-community/postgres_exporter): | ||
|
|
||
| | Metric family | Interval | | ||
| |---|---| | ||
| | `pg_stat_activity_count` | 30 s | | ||
| | `pg_stat_bgwriter_checkpoints_timed` | 60 s | | ||
| | `pg_stat_replication_pg_wal_lsn_diff` | 30 s | | ||
|
|
||
| ## Custom Metrics | ||
|
|
||
| You can specify individual metric families and their intervals with `custom_metrics`: | ||
|
|
||
| ```yaml | ||
| - name: patroni-prod-node1 | ||
| kind: prometheus | ||
| conn_str: "http://patroni-node1:8008/metrics" | ||
| custom_metrics: | ||
| patroni_primary: 30 | ||
| patroni_cluster_unlocked: 30 | ||
| patroni_dcs_last_seen: 30 | ||
| is_enabled: true | ||
| ``` | ||
|
|
||
| ## Custom Tags | ||
|
|
||
| Use `custom_tags` to attach arbitrary key-value pairs to every stored data point. This is | ||
| useful when multiple nodes feed the same sink and you need to distinguish them: | ||
|
|
||
| ```yaml | ||
| - name: patroni-prod-node1 | ||
| kind: prometheus | ||
| conn_str: "http://patroni-node1:8008/metrics" | ||
| preset_metrics: patroni | ||
| custom_tags: | ||
| cluster: prod | ||
| node: node1 | ||
| is_enabled: true | ||
| ``` | ||
|
|
||
| ## Full Example | ||
|
|
||
| The following snippet monitors all three nodes of a Patroni HA cluster. Each node's metrics are | ||
| tagged with the cluster name and node identifier so they can be queried independently: | ||
|
|
||
| ```yaml | ||
| - name: patroni-prod-node1 | ||
| kind: prometheus | ||
| conn_str: "http://patroni-node1:8008/metrics" | ||
| preset_metrics: patroni | ||
| custom_tags: | ||
| cluster: prod | ||
| node: node1 | ||
| is_enabled: true | ||
|
|
||
| - name: patroni-prod-node2 | ||
| kind: prometheus | ||
| conn_str: "http://patroni-node2:8008/metrics" | ||
| preset_metrics: patroni | ||
| custom_tags: | ||
| cluster: prod | ||
| node: node2 | ||
| is_enabled: true | ||
|
|
||
| - name: patroni-prod-node3 | ||
| kind: prometheus | ||
| conn_str: "http://patroni-node3:8008/metrics" | ||
| preset_metrics: patroni | ||
| custom_tags: | ||
| cluster: prod | ||
| node: node3 | ||
| is_enabled: true | ||
| ``` | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xgouda check this out! :)