-
Notifications
You must be signed in to change notification settings - Fork 131
WIP: 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
Draft
pashagolub
wants to merge
27
commits into
master
Choose a base branch
from
prom-sources
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
ba24a0c
add spec for prometheus sources
pashagolub 0eecb70
update spec with a simpler metric definitions
pashagolub 16ceca8
add spec to refactor SourceConn as interface
pashagolub 1b8bae2
rebase specs on batch metric fetching
pashagolub f67df2e
add `NewFakeExporter()` to `testutil`
pashagolub bdd38b3
extract `SourceConn` interface and `DbConn` struct
pashagolub e7a2c40
add `prometheus` source kind
pashagolub 59357be
implement `PromConn.Connect()`, `Ping()`, `FetchRuntimeInfo()`
pashagolub 57373c7
use `Ping()` call in ping command
pashagolub 01c515b
implement `ScrapeAll` and extend `MeasurementEnvelope` with `SourceKind`
pashagolub ff27861
make `Reaper` an interface and `reaper` a struct implementing it
pashagolub a69f44e
remove `sourceReapers`, use `cancelFuncs` only
pashagolub ec19b72
rename `SourceReaper` to `DbConnReaper`
pashagolub b26eaef
implement `PromReaper`
pashagolub f312d55
move `DbConnReaper` into `database.go`
pashagolub 6d88585
rename `prom_reaper.go` to `prometheus.go`
pashagolub 7d0a5cd
make `NewReaper` return an interface, while `newReaper` return struct
pashagolub ad99c89
support prom-sourced envelopes in `PrometheusWriter`
pashagolub 39ab05b
add `postgres-exporter-basic` preset and prometheus source example
pashagolub ea8e0c6
add "Monitoring a Prometheus Exporter" howto
pashagolub 12d0d76
add `prometheus` source kind to webui
pashagolub 249cf74
add `prometheus` source kind migration for postgres sink schema
pashagolub 00930c1
use `GET` request in `PromConn.Ping()`
pashagolub 31753a1
fix `ResolveDatabases()` for Prometheus sources
pashagolub 5c68a8a
add Prometheus sources to docker compose test instance
pashagolub 4f468ec
add "Patroni Cluster Overview" dashboards
pashagolub 392a91c
fix schema migration tests
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! :)