Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[postgres] Fix unix socket connection with psycopg2 #2968

Merged
merged 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions checks.d/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
TABLE_COUNT_LIMIT = 200

def psycopg2_connect(*args, **kwargs):
del kwargs['ssl']
if 'ssl' in kwargs:
del kwargs['ssl']
if 'unix_sock' in kwargs:
kwargs['host'] = kwargs['unix_sock']
del kwargs['unix_sock']
return psycopg2.connect(*args, **kwargs)


Expand Down Expand Up @@ -605,7 +609,7 @@ def get_connection(self, key, host, port, user, password, dbname, ssl, connect_f
elif host.startswith('/'):
# If the hostname starts with /, it's probably a path
# to a UNIX socket. This is similar behaviour to psql
connection = pg.connect(unix_sock=host, user=user,
connection = connect_fct(unix_sock=host, user=user,
password=password, database=dbname)
else:
connection = connect_fct(host=host, user=user, password=password,
Expand Down
9 changes: 5 additions & 4 deletions conf.d/postgres.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ instances:
# - optional_tag2

# Connect using a UNIX socket (host must begin with a /)
# If `use_psycopg2` is enabled, use the directory of the UNIX socket (ex: `/run/postgresql/`)
# - host: /run/postgresql/.s.PGSQL.5433
# dbname: db_name

Expand All @@ -24,7 +25,7 @@ instances:
# - my_table
# - my_other_table
#
# By default all schemas are included. To track relations from specific schemas only,
# By default all schemas are included. To track relations from specific schemas only,
# use the following syntax:
#
# relations:
Expand All @@ -37,10 +38,10 @@ instances:

# Custom metrics
# Below are some examples of commonly used metrics, which are implemented as custom metrics.
# Uncomment them if you want to use them as is, or use as an example for creating your own custom metrics.
# Uncomment them if you want to use them as is, or use as an example for creating your own custom metrics.
# The format for describing custome metrics is identical with the one used for common metrics in postgres.py
# Be extra careful with ensuring proper custom metrics description format. If your custom metric does not work
# after an agent restart, look for errors in the output of "/etc/init.d/datadog-agent info" command, as well as
# Be extra careful with ensuring proper custom metrics description format. If your custom metric does not work
# after an agent restart, look for errors in the output of "/etc/init.d/datadog-agent info" command, as well as
# /var/log/datadog/collector.log file.
#
# custom_metrics:
Expand Down