diff options
author | Facetoe <facetoe@facetoe.com.au> | 2017-07-30 23:47:55 +0800 |
---|---|---|
committer | Facetoe <facetoe@facetoe.com.au> | 2017-07-30 23:47:55 +0800 |
commit | eae6659e8a5e585a6f7f9a41c1b82ed963e4a287 (patch) | |
tree | 91d2250bd9f2b935a147e178a469df8ec1854e99 | |
parent | d2e9b448afc21ae82444702ca2280d00796eab55 (diff) |
postgres.chart.py: Fix superuser bug.
Resolve issue raised in #2520 that led to non superuser instances
attempting to execute queries that require superuser privs.
-rw-r--r-- | python.d/postgres.chart.py | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/python.d/postgres.chart.py b/python.d/postgres.chart.py index ef710cb841..e9e0f841d6 100644 --- a/python.d/postgres.chart.py +++ b/python.d/postgres.chart.py @@ -244,10 +244,10 @@ class Service(SimpleService): self.database_poll = configuration.pop('database_poll', None) self.configuration = configuration self.connection = False - self.is_superuser = False self.data = dict() self.locks_zeroed = dict() self.databases = list() + self.queries = QUERY_STATS.copy() def _connect(self): params = dict(user='postgres', @@ -294,12 +294,12 @@ class Service(SimpleService): def add_additional_queries_(self, is_superuser): if self.index_stats: - QUERY_STATS[QUERIES['INDEX_STATS']] = METRICS['INDEX_STATS'] + self.queries[QUERIES['INDEX_STATS']] = METRICS['INDEX_STATS'] if self.table_stats: - QUERY_STATS[QUERIES['TABLE_STATS']] = METRICS['TABLE_STATS'] + self.queries[QUERIES['TABLE_STATS']] = METRICS['TABLE_STATS'] if is_superuser: - QUERY_STATS[QUERIES['BGWRITER']] = METRICS['BGWRITER'] - QUERY_STATS[QUERIES['ARCHIVE']] = METRICS['ARCHIVE'] + self.queries[QUERIES['BGWRITER']] = METRICS['BGWRITER'] + self.queries[QUERIES['ARCHIVE']] = METRICS['ARCHIVE'] def create_dynamic_charts_(self): @@ -318,7 +318,7 @@ class Service(SimpleService): cursor = self.connection.cursor(cursor_factory=DictCursor) try: self.data.update(self.locks_zeroed) - for query, metrics in QUERY_STATS.items(): + for query, metrics in self.queries.items(): self.query_stats_(cursor, query, metrics) except OperationalError: @@ -398,13 +398,3 @@ def add_database_stat_chart_(order, definitions, name, database_name): definitions[chart_name] = { 'options': [name, title + ': ' + database_name, units, 'db ' + database_name, context, chart_type], 'lines': create_lines(database_name, chart_template['lines'])} - - -# -# def add_replication_stats(self, cursor): -# cursor.execute(REPLICATION) -# temp = cursor.fetchall() -# for row in temp: -# self.add_gauge_value('Replication/%s' % row.get('client_addr', 'Unknown'), -# 'byte_lag', -# int(row.get('byte_lag', 0))) |