-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pg_exporter: predicate queries feature (WIP)
**WIP**: * has a TODO about adding name of failing predicate query to metric set * defines the TTL field but does not implement it * lacks test cover Add "predicate queries" to decide whether a given metric query should be scraped at runtime. Fixes #41. These can be used to express complex conditions that may change over time, such as "collect this metric set if the foo extension is installed and is at least version 2.1", "collect this metric only when running on (some specific vendor postgres flavour)" or "only try to collect this if this specific table exists and has this specific column". This helps with maintaining a single configuration to support multiple postgres versions, vendor flavours, access privilege levels, installed extensions and extension versions, etc. E.g. you can selectively query `pg_stat_statements` only if the extension is installed in the current DB. The new syntax is added at query level in the configuration and looks like this: rowcount_in_foo_table: predicate_queries: - name: foo_table exists predicate_query: | SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'foo') query: | SELECT count(1) FROM public.foo;
- Loading branch information
Showing
6 changed files
with
169 additions
and
16 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -335,6 +335,20 @@ Config files are using YAML format, there are lots of examples in the [conf](htt | |
#┃ * '<tag>' means this query WILL be executed when exporter is tagged with '<tag>' | ||
#┃ ( <tag> could not be cluster,primary,standby,master,replica,etc...) | ||
#┃ | ||
#┃ # One or more "predicate queries" may be defined for a metric query. These | ||
#┃ # are run before the main metric query (after any cache hit check). If all | ||
#┃ # of them, when run sequentially, return a single row with a single column | ||
#┃ # boolean true result, the main metric query is executed. If any of them | ||
#┃ # return false or return zero rows, the main query is skipped. If any | ||
#┃ # predicate query returns more than one row, a non-boolean result, or fails | ||
#┃ # with an error the whole query is marked failed. Predicate queries can be | ||
#┃ # used to check for the presence of specific functions, tables, extensions, | ||
#┃ # settings, vendor-specific postgres features etc before running the main | ||
#┃ # query. | ||
#┃ predicate_queries: | ||
#┃ - name: predicate query name | ||
#┃ predicate_query: | | ||
#┃ SELECT EXISTS (SELECT 1 FROM information_schema.routines WHERE routine_schema = 'pg_catalog' AND routine_name = 'pg_backup_start_time'); | ||
#┃ | ||
#┃ metrics: <---- List of returned columns, each column must have a `name` and `usage`, `rename` and `description` are optional | ||
#┃ - timestamp: <---- Column name, should be exactly the same as returned column name | ||
|
@@ -473,4 +487,4 @@ Author: [Vonng](https://vonng.com/en) ([[email protected]](mailto:[email protected])) | |
|
||
License: [Apache Apache License Version 2.0](LICENSE) | ||
|
||
Copyright: 2018-2023 [email protected] | ||
Copyright: 2018-2023 [email protected] |
This file contains 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 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 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 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 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