diff --git a/checks.d/postgres.py b/checks.d/postgres.py index 6caa49757a..22082e662c 100644 --- a/checks.d/postgres.py +++ b/checks.d/postgres.py @@ -602,6 +602,11 @@ def get_connection(self, key, host, port, user, password, dbname, ssl, connect_f elif port != '': connection = connect_fct(host=host, port=port, user=user, password=password, database=dbname, ssl=ssl) + 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, + password=password, database=dbname) else: connection = connect_fct(host=host, user=user, password=password, database=dbname, ssl=ssl) diff --git a/conf.d/postgres.yaml.example b/conf.d/postgres.yaml.example index f21649cf1d..950a039770 100644 --- a/conf.d/postgres.yaml.example +++ b/conf.d/postgres.yaml.example @@ -12,6 +12,10 @@ instances: # - optional_tag1 # - optional_tag2 +# Connect using a UNIX socket (host must begin with a /) +# - host: /run/postgresql/.s.PGSQL.5433 +# dbname: db_name + # Track per-relation (table) metrics # The list of relations/tables must be specified here. # Each relation generates many metrics (10 + 10 per index)