Closes#326 as is provides a viable solution to use a K8S init container
to fully contruct the PostgreSQL URI and 'hand it over' to the postgres_exporter
process.
In the user queries.yml file, the created namespaces can now be optionally
cached by setting cache_seconds, which will prevent the query being re-run
within that timeframe if previous results are available.
Supercedes #211, credit to @SamSaffron for the original PR.
* Fix problem: If autodiscovery is enable exporter make connection twice to database from connetion string (exclude current database from SQL-query);
* Fix problem: don't get default metrics and settings if autodiscovery is enabled. Now you can use --disable-default-metrics and --disable-settings-metrics with --auto-discover-databases and
* Use struct instead of interface{} when parsing query user
* Use MappingOptions
* Split function to be more testable
* Rename function to parseUserQueries
* Start to add test about query parsing
Some backstory
==============
I was attempting to use postgres_exporter with the official Docker
container (https://hub.docker.com/_/postgres) In a Kubernetes
StatefulSet, with a side-car configuration, but found that I wasn't able
to connect even with sharing the Postgres Unix listening socket, between
both containers. After copying the container over to an Alpine base I
quickly found out that the postgres_exporter was actually starting
before the main Postres container had dropped the unix socket onto the
file system, a quick work around is to write a bash for loop checking
for the existence of a unix socket, however this would require
maintaining a container, besides other users may find retries useful on
startup.
Implementation
==============
All changes are made to the getServer function and variables are
local, I was unsure if it was worth adding command line switches but
this would allow for a more sophisticated backOff loop in the future.
Hope this help, and let me know if you would like me to changes
anything.
If exporter is scraped by multiple Prometheuses (as we do) - Collect() could be called concurrently. In result in some cases one of Prometheuses could get pg_up = 0, because it was explicitly set to zero on first Collect call.
* Add exclude-databases option
* Update readme to explain --exclude-databases
* Add comments to ExcludeDatabases function and unexport Contains function
This is useful if your database uses true/false for state and want to make prometheus alerts based on that.
Before, booleans were not able to be parsed. See issue #201
When you area monitoring server from cloud providers the exporter
IP/hostname is not the server IP, so add some constant labels is useful
on dashboards and alerts.
And is very important to use with `--disable-default-metrics` to add
info like `datname` and figure out the database name that you are
monitoring
This did in fact turn out to be an oversight in the error handling. Now, any
error in the initial connection path will always trip pg_up to be 0.
Fixes#160
This commit implements a massive refactor of the repository, and
moves the build system over to use Mage (magefile.org) which should
allow seamless building across multiple platforms.