summaryrefslogtreecommitdiffstats
path: root/python.d
diff options
context:
space:
mode:
authorFacetoe <facetoe@facetoe.com.au>2016-10-23 14:53:00 +0800
committerFacetoe <facetoe@facetoe.com.au>2016-10-23 14:53:00 +0800
commit97b5b991c0e2b0222a54ad22b4594d9c95477193 (patch)
tree4ac525bc622928c6490d5a6c17268cb5bb3e13dc /python.d
parent0b780e3dd133e8ddfd523c083ce514b97f5dac62 (diff)
Reduce necessary queries.
Diffstat (limited to 'python.d')
-rw-r--r--python.d/postgres.chart.py35
1 files changed, 14 insertions, 21 deletions
diff --git a/python.d/postgres.chart.py b/python.d/postgres.chart.py
index cdb8bb8213..97daa37d5f 100644
--- a/python.d/postgres.chart.py
+++ b/python.d/postgres.chart.py
@@ -41,21 +41,20 @@ FROM
pg_stat_activity;
"""
-TABLE_SIZE_ON_DISK = """
-SELECT ((sum(relpages)* 8) * 1024) AS size_relations FROM pg_class WHERE relkind IN ('r', 't');
-"""
-
-TABLE_COUNT = """
-SELECT count(1) as relations FROM pg_class WHERE relkind IN ('r', 't');
-"""
-
-INDEX_SIZE_ON_DISK = """
-SELECT ((sum(relpages)* 8) * 1024) AS size_indexes FROM pg_class WHERE relkind = 'i';
+TABLE_STATS = """
+SELECT
+ ((sum(relpages) * 8) * 1024) AS size_relations,
+ count(1) AS relations
+FROM pg_class
+WHERE relkind IN ('r', 't');
"""
-INDEX_COUNT = """
-SELECT count(1) as indexes FROM pg_class WHERE relkind = 'i';
-"""
+INDEX_STATS = """
+SELECT
+ ((sum(relpages) * 8) * 1024) AS size_indexes,
+ count(1) AS indexes
+FROM pg_class
+WHERE relkind = 'i';"""
DATABASE = """
SELECT
@@ -346,21 +345,15 @@ class Service(SimpleService):
self.data['backend_process_idle'] = int(temp.get('backends_idle', 0))
def add_index_stats(self, cursor):
- cursor.execute(INDEX_COUNT)
+ cursor.execute(INDEX_STATS)
temp = cursor.fetchone()
self.data['index_count'] = int(temp.get('indexes', 0))
-
- cursor.execute(INDEX_SIZE_ON_DISK)
- temp = cursor.fetchone()
self.data['index_size'] = int(temp.get('size_indexes', 0))
def add_table_stats(self, cursor):
- cursor.execute(TABLE_COUNT)
+ cursor.execute(TABLE_STATS)
temp = cursor.fetchone()
self.data['table_count'] = int(temp.get('relations', 0))
-
- cursor.execute(TABLE_SIZE_ON_DISK)
- temp = cursor.fetchone()
self.data['table_size'] = int(temp.get('size_relations', 0))
def add_lock_stats(self, cursor):