Skip to content

Commit

Permalink
postgres timeouts (netdata#4988)
Browse files Browse the repository at this point in the history
* added `connect_timeout` and `statement_timeout` to postgres

* change default statement_timeout to 5
  • Loading branch information
ilyam8 authored Dec 14, 2018
1 parent 39ad3c5 commit 9a3e8f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
21 changes: 16 additions & 5 deletions collectors/python.d.plugin/postgres/postgres.chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
from bases.FrameworkServices.SimpleService import SimpleService


DEFAULT_PORT = 5432
DEFAULT_USER = 'postgres'
DEFAULT_CONNECT_TIMEOUT = 2 # seconds
DEFAULT_STATEMENT_TIMEOUT = 5000 # ms


WAL = 'WAL'
ARCHIVE = 'ARCHIVE'
BACKENDS = 'BACKENDS'
Expand Down Expand Up @@ -787,6 +793,7 @@ def __init__(self, configuration=None, name=None):
self.do_table_stats = configuration.pop('table_stats', False)
self.do_index_stats = configuration.pop('index_stats', False)
self.databases_to_poll = configuration.pop('database_poll', None)
self.statement_timeout = configuration.pop('statement_timeout', DEFAULT_STATEMENT_TIMEOUT)
self.configuration = configuration

self.conn = None
Expand All @@ -811,11 +818,15 @@ def connect(self):
self.conn = None

try:
params = dict(user='postgres',
database=None,
password=None,
host=None,
port=5432)
params = dict(
host=None,
port=DEFAULT_PORT,
database=None,
user=DEFAULT_USER,
password=None,
connect_timeout=DEFAULT_CONNECT_TIMEOUT,
options='-c statement_timeout={0}'.format(self.statement_timeout),
)
params.update(self.configuration)

self.conn = psycopg2.connect(**params)
Expand Down
12 changes: 7 additions & 5 deletions collectors/python.d.plugin/postgres/postgres.conf
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@
#
# Connections can be configured with the following options:
#
# database : 'example_db_name'
# user : 'example_user'
# password : 'example_pass'
# host : 'localhost'
# port : 5432
# database : 'example_db_name'
# user : 'example_user'
# password : 'example_pass'
# host : 'localhost'
# port : 5432
# connect_timeout : 2 # in seconds, default is 2
# statement_timeout : 2000 # in ms, default is 2000
#
# Additionally, the following options allow selective disabling of charts
#
Expand Down

0 comments on commit 9a3e8f1

Please sign in to comment.