sql_exporter icon indicating copy to clipboard operation
sql_exporter copied to clipboard

adding db auto discovery support to postgres

Open noapinsler opened this issue 1 year ago • 5 comments

When using PostgreSQL, if the connection specifies exclude or include (only one can be specified), the exporter will create connections to the jobs based on the required databases. This parameter accepts a list of databases that can also be specified using regex, like so: 'postgres://postgres@localhost/exclude:postgres,test_db*?sslmode=disable'

noapinsler avatar Apr 17 '24 06:04 noapinsler

Exactly what we need 👍🏼

rezonick avatar Jun 19 '24 14:06 rezonick

@rezonick Do you have capacity to try this PR? I don't have availability to test it, but if it works for two people we can merge it.

dewey avatar Jun 19 '24 14:06 dewey

@dewey i can confirm that this PR is working...

orilani avatar Jun 20 '24 06:06 orilani

@dewey to elaborate more i took @noapinsler branch, build the dockerfile as is, and deploy it instead of the original sql exporter docker image with same config and values. i then used this configmap for connecting to my postgres: postgres://{{POSTGRES_USER}}:{{POSTGRES_PASSWORD}}@{{POSTGRES_URL}}:5432/include:org_*?sslmode=disable

postgres://{{POSTGRES_USER}}:{{POSTGRES_PASSWORD}}@{{POSTGRES_URL}}:5432/exclude:postgres?sslmode=disable

few logs example of top-tables logs that run with the second connection excluding the posgres db: {"caller":"job.go:389","job":"top-tables","level":"debug","msg":"Running Query","query":"top_tables","ts":"2024-06-24T20:08:32.161510244Z"} {"caller":"job.go:389","job":"top-tables","level":"debug","msg":"Running Query","query":"top_tables","ts":"2024-06-24T20:08:32.161640149Z"} {"caller":"job.go:389","job":"top-tables","level":"debug","msg":"Running Query","query":"top_tables","ts":"2024-06-24T20:08:32.16169112Z"} {"caller":"job.go:389","job":"top-tables","level":"debug","msg":"Running Query","query":"top_tables","ts":"2024-06-24T20:08:32.163286563Z"}

its being working for few days now and works good!

orilani avatar Jun 25 '24 06:06 orilani

@noapinsler Would you have time to replace the print statements with logging statements like in the rest of the file? Once that's done I can merge and create a release.

@orilani Thanks for taking the time to test it, sounds good!

dewey avatar Jun 25 '24 11:06 dewey

@dewey , I changed the printf to logger as in the rest of the file.

noapinsler avatar Jul 03 '24 12:07 noapinsler

Thanks!

dewey avatar Jul 03 '24 13:07 dewey

A new release is out, the Docker image is still being pushed but will be available shortly. Thanks for the contribution!

dewey avatar Jul 05 '24 12:07 dewey