justwatchcom / sql_exporter

Flexible SQL Exporter for Prometheus.
MIT License
404 stars 109 forks source link

How can I pass connection using env? #49

Closed s-titov closed 2 years ago

s-titov commented 3 years ago

Hello, thank for your exporter.

How can I pass connection using env variables? I don't wanna show my connection's data in config.

erlendvollset commented 3 years ago

I tried setting postgres:// (which is valid https://www.postgresql.org/docs/current/libpq-connect.html) as connection string and then setting the PGHOST, PGDATABASE, PGUSER, PGPASSWORD environment variables. But getting the following error in sql_exporter: missing "=" after "postgres:" in connection info string

erlendvollset commented 3 years ago

Replaced the connection string with postgres:/// and it works fine.

dewey commented 2 years ago

I just added a feature that I've been using internally for a while already: https://github.com/justwatchcom/sql_exporter/pull/56

This should take care of this.