@cryptotaxi247 / netdata-1 / commits / 9a3e8f170

postgres timeouts (#4988)

* added `connect_timeout` and `statement_timeout` to postgres * change default statement_timeout to 5

Ilya Mashchenko committed Dec 14, 2018 at 23:34 UTC 9a3e8f1708ff338a5e903ecd24f8aa146d08c563
2 files changed +23 -10
collectors/python.d.plugin/postgres/postgres.chart.py
+16 -5
@@ -17,6 +17,12 @@ except ImportError:
17 from bases.FrameworkServices.SimpleService import SimpleService
18
19
20 +DEFAULT_PORT = 5432
21 +DEFAULT_USER = 'postgres'
22 +DEFAULT_CONNECT_TIMEOUT = 2 # seconds
23 +DEFAULT_STATEMENT_TIMEOUT = 5000 # ms
24 +
25 +
26 WAL = 'WAL'
27 ARCHIVE = 'ARCHIVE'
28 BACKENDS = 'BACKENDS'
@@ -787,6 +793,7 @@ class Service(SimpleService):
793 self.do_table_stats = configuration.pop('table_stats', False)
794 self.do_index_stats = configuration.pop('index_stats', False)
795 self.databases_to_poll = configuration.pop('database_poll', None)
796 + self.statement_timeout = configuration.pop('statement_timeout', DEFAULT_STATEMENT_TIMEOUT)
797 self.configuration = configuration
798
799 self.conn = None
@@ -811,11 +818,15 @@ class Service(SimpleService):
818 self.conn = None
819
820 try:
814 - params = dict(user='postgres',
815 - database=None,
816 - password=None,
817 - host=None,
818 - port=5432)
821 + params = dict(
822 + host=None,
823 + port=DEFAULT_PORT,
824 + database=None,
825 + user=DEFAULT_USER,
826 + password=None,
827 + connect_timeout=DEFAULT_CONNECT_TIMEOUT,
828 + options='-c statement_timeout={0}'.format(self.statement_timeout),
829 + )
830 params.update(self.configuration)
831
832 self.conn = psycopg2.connect(**params)
collectors/python.d.plugin/postgres/postgres.conf
+7 -5
@@ -63,11 +63,13 @@
63 #
64 # Connections can be configured with the following options:
65 #
66 -# database : 'example_db_name'
67 -# user : 'example_user'
68 -# password : 'example_pass'
69 -# host : 'localhost'
70 -# port : 5432
66 +# database : 'example_db_name'
67 +# user : 'example_user'
68 +# password : 'example_pass'
69 +# host : 'localhost'
70 +# port : 5432
71 +# connect_timeout : 2 # in seconds, default is 2
72 +# statement_timeout : 2000 # in ms, default is 2000
73 #
74 # Additionally, the following options allow selective disabling of charts
75 #