diff --git a/checks.d/postgres.py b/checks.d/postgres.py index 8193c6ade1..db1ec1510c 100644 --- a/checks.d/postgres.py +++ b/checks.d/postgres.py @@ -584,6 +584,11 @@ def get_connection(self, key, host, port, user, password, dbname, ssl, use_cache elif port != '': connection = pg.connect(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 = pg.connect(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 b250e9b932..74cde77c1c 100644 --- a/conf.d/postgres.yaml.example +++ b/conf.d/postgres.yaml.example @@ -11,6 +11,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) @@ -56,4 +60,4 @@ instances: # Collect count metrics, default value is True for backward compatibility but they migth be slow, # suggested value is False. # collect_count_metrics: False -# \ No newline at end of file +#