@cryptotaxi247 / netdata-1 / commits / 657738522

postgres: do not return cached data (#7228)

* postgres: reset self.data on every iteration * postgres: format file

Ilya Mashchenko committed Oct 30, 2019 at 17:14 UTC 657738522e2a9feb78eb46a34d1ef736b3975a5f
1 file changed +20 -21
collectors/python.d.plugin/postgres/postgres.chart.py
+20 -21
@@ -10,19 +10,18 @@ try:
10 from psycopg2 import extensions
11 from psycopg2.extras import DictCursor
12 from psycopg2 import OperationalError
13 +
14 PSYCOPG2 = True
15 except ImportError:
16 PSYCOPG2 = False
17
18 from bases.FrameworkServices.SimpleService import SimpleService
19
19 -
20 DEFAULT_PORT = 5432
21 DEFAULT_USER = 'postgres'
22 -DEFAULT_CONNECT_TIMEOUT = 2 # seconds
22 +DEFAULT_CONNECT_TIMEOUT = 2 # seconds
23 DEFAULT_STATEMENT_TIMEOUT = 5000 # ms
24
25 -
25 CONN_PARAM_DSN = 'dsn'
26 CONN_PARAM_HOST = 'host'
27 CONN_PARAM_PORT = 'port'
@@ -37,7 +36,6 @@ CONN_PARAM_SSL_CRL = 'sslcrl'
36 CONN_PARAM_SSL_CERT = 'sslcert'
37 CONN_PARAM_SSL_KEY = 'sslkey'
38
40 -
39 QUERY_NAME_WAL = 'WAL'
40 QUERY_NAME_ARCHIVE = 'ARCHIVE'
41 QUERY_NAME_BACKENDS = 'BACKENDS'
@@ -145,7 +143,6 @@ V96 = 'V96'
143 V10 = 'V10'
144 V11 = 'V11'
145
148 -
146 QUERY_WAL = {
147 DEFAULT: """
148 SELECT
@@ -904,6 +901,7 @@ class Service(SimpleService):
901 if not self.alive and not self.reconnect():
902 return None
903
904 + self.data = dict()
905 try:
906 cursor = self.conn.cursor(cursor_factory=DictCursor)
907
@@ -989,7 +987,8 @@ class Service(SimpleService):
987 self.queries[query_factory(QUERY_NAME_WAL, self.server_version)] = METRICS[QUERY_NAME_WAL]
988
989 if self.server_version >= 100000:
992 - self.queries[query_factory(QUERY_NAME_REPSLOT_FILES, self.server_version)] = METRICS[QUERY_NAME_REPSLOT_FILES]
990 + v = METRICS[QUERY_NAME_REPSLOT_FILES]
991 + self.queries[query_factory(QUERY_NAME_REPSLOT_FILES, self.server_version)] = v
992
993 if self.server_version >= 90400:
994 self.queries[query_factory(QUERY_NAME_AUTOVACUUM)] = METRICS[QUERY_NAME_AUTOVACUUM]
@@ -1005,12 +1004,12 @@ class Service(SimpleService):
1004 ]
1005 self.definitions['database_size']['lines'].append(dim)
1006 for chart_name in [name for name in self.order if name.startswith('db_stat')]:
1008 - add_database_stat_chart(
1009 - order=self.order,
1010 - definitions=self.definitions,
1011 - name=chart_name,
1012 - database_name=database_name,
1013 - )
1007 + add_database_stat_chart(
1008 + order=self.order,
1009 + definitions=self.definitions,
1010 + name=chart_name,
1011 + database_name=database_name,
1012 + )
1013 add_database_lock_chart(
1014 order=self.order,
1015 definitions=self.definitions,
@@ -1078,10 +1077,10 @@ def add_database_lock_chart(order, definitions, database_name):
1077 chart_name = database_name + '_locks'
1078 order.insert(-1, chart_name)
1079 definitions[chart_name] = {
1081 - 'options':
1080 + 'options':
1081 [None, 'Locks on db: ' + database_name, 'locks', 'db ' + database_name, 'postgres.db_locks', 'line'],
1083 - 'lines': create_lines(database_name)
1084 - }
1082 + 'lines': create_lines(database_name)
1083 + }
1084
1085
1086 def add_database_stat_chart(order, definitions, name, database_name):
@@ -1097,8 +1096,8 @@ def add_database_stat_chart(order, definitions, name, database_name):
1096 order.insert(0, chart_name)
1097 name, title, units, _, context, chart_type = chart_template['options']
1098 definitions[chart_name] = {
1100 - 'options': [name, title + ': ' + database_name, units, 'db ' + database_name, context, chart_type],
1101 - 'lines': create_lines(database_name, chart_template['lines'])}
1099 + 'options': [name, title + ': ' + database_name, units, 'db ' + database_name, context, chart_type],
1100 + 'lines': create_lines(database_name, chart_template['lines'])}
1101
1102
1103 def add_replication_delta_chart(order, definitions, name, application_name):
@@ -1115,8 +1114,8 @@ def add_replication_delta_chart(order, definitions, name, application_name):
1114 order.insert(position, chart_name)
1115 name, title, units, _, context, chart_type = chart_template['options']
1116 definitions[chart_name] = {
1118 - 'options': [name, title + ': ' + application_name, units, 'replication delta', context, chart_type],
1119 - 'lines': create_lines(application_name, chart_template['lines'])}
1117 + 'options': [name, title + ': ' + application_name, units, 'replication delta', context, chart_type],
1118 + 'lines': create_lines(application_name, chart_template['lines'])}
1119
1120
1121 def add_replication_slot_chart(order, definitions, name, slot_name):
@@ -1133,5 +1132,5 @@ def add_replication_slot_chart(order, definitions, name, slot_name):
1132 order.insert(position, chart_name)
1133 name, title, units, _, context, chart_type = chart_template['options']
1134 definitions[chart_name] = {
1136 - 'options': [name, title + ': ' + slot_name, units, 'replication slot files', context, chart_type],
1137 - 'lines': create_lines(slot_name, chart_template['lines'])}
1135 + 'options': [name, title + ': ' + slot_name, units, 'replication slot files', context, chart_type],
1136 + 'lines': create_lines(slot_name, chart_template['lines'])}