mirror of
https://github.com/netdata/netdata.git
synced 2025-05-17 22:52:21 +00:00
postgres timeouts (#4988)
* added `connect_timeout` and `statement_timeout` to postgres * change default statement_timeout to 5
This commit is contained in:
parent
39ad3c587d
commit
9a3e8f1708
2 changed files with 23 additions and 10 deletions
collectors/python.d.plugin/postgres
|
@ -17,6 +17,12 @@ except ImportError:
|
|||
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'
|
||||
|
@ -787,6 +793,7 @@ class Service(SimpleService):
|
|||
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
|
||||
|
@ -811,11 +818,15 @@ class Service(SimpleService):
|
|||
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)
|
||||
|
|
|
@ -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
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue