@cryptotaxi247 / netdata-1 / commits / e4d849b34

Use summary views where available.

Facetoe committed Oct 4, 2016 at 22:32 UTC e4d849b3425e02dfb392521584e3adb57607497e
1 file changed +41 -55
python.d/postgres.chart.py
+41 -55
@@ -18,39 +18,48 @@ retries = 60
18 # 'port': 5432
19 # }
20
21 -ORDER = ["Tuples", "Scans", "BGWriter", "BufferCache"]
21 CHARTS = {
22 "Tuples": {
23 'options': ["tuples", "PostgreSQL tuple access", "Tuples / sec", "tuples", "postgres.tuples", "line"],
24 'lines': [
26 - ["inserted", "inserted", "incremental", 1, 1],
27 - ["seqread", "seqread", "incremental", 1, 1],
28 - ["hotupdated", "hotupdated", "incremental", 1, 1],
29 - ["deleted", "deleted", "incremental", 1, 1],
30 - ["updated", "updated", "incremental", 1, 1],
31 - ["idxfetch", "idxfetch", "incremental", 1, 1],
25 + ["tup_inserted", "tup_inserted", "incremental", 1, 1],
26 + ["tup_inserted", "tup_inserted", "incremental", 1, 1],
27 + ["tup_fetched", "tup_fetched", "incremental", 1, 1],
28 + ["tup_updated", "tup_updated", "incremental", 1, 1],
29 + ["tup_deleted", "tup_deleted", "incremental", 1, 1],
30 ]},
33 - "Scans": {
34 - 'options': ["scans", "PostgreSQL scan types", "Scans / sec", "scans", "postgres.scans", "line"],
31 + "Transactions": {
32 + 'options': ["transactions", "Transactions", "transactions / sec", "transactions", "postgres.transactions", "line"],
33 'lines': [
36 - ["sequential", "sequential", "incremental", 1, 1],
37 - ["index", "index", "incremental", 1, 1],
34 + ["xact_commit", "xact_commit", "incremental", 1, 1],
35 + ["xact_rollback", "xact_rollback", "incremental", 1, 1],
36 ]},
39 - "BGWriter": {
40 - 'options': ["bgwriter", "BG Writer Activity", "Buffers / sec", "bgwriter", "postgres.bgwriter", "line"],
41 - 'lines': [
42 - ["buffers_alloc", "buffers_alloc", "incremental", 1, 1],
43 - ["buffers_clean", "buffers_clean", "incremental", 1, 1],
44 - ["buffers_checkpoint", "buffers_checkpoint", "incremental", 1, 1],
45 - ["buffers_backend", "buffers_backend", "incremental", 1, 1],
46 - ]},
47 - "BufferCache": {
48 - 'options': ["buffer_cache", "Buffer Cache", "Buffers / sec", "buffer_cache", "postgres.buffer_cache", "line"],
37 + "BlockAccess": {
38 + 'options': ["block_access", "block_access", "Block / sec ", "block_access", "postgres.block_access", "line"],
39 'lines': [
40 ["blks_read", "blks_read", "incremental", 1, 1],
41 ["blks_hit", "blks_hit", "incremental", 1, 1],
52 - ]}
42 + ]},
43 + "BlockTime": {
44 + 'options': ["block_time", "block_time", "milliseconds ", "block_time", "postgres.block_time", "line"],
45 + 'lines': [
46 + ["blk_read_time", "blk_read_time", "incremental", 1, 1],
47 + ["blk_write_time", "blk_write_time", "incremental", 1, 1],
48 + ]},
49 + "Checkpoints": {
50 + 'options': ["checkpoints", "Checkpoints", "Checkpoints", "checkpoints", "postgres.checkpoints", "line"],
51 + 'lines': [
52 + ["bg_checkpoint_time", "bg_checkpoint_time", "absolute", 1, 1],
53 + ["bg_checkpoint_requested", "bg_checkpoint_requested", "absolute", 1, 1],
54 + ]},
55 + "Buffers": {
56 + 'options': ["buffers", "buffers", "Buffer/ sec", "buffers", "postgres.buffers", "line"],
57 + 'lines': [
58 + ["buffers_written", "buffers_written", "incremental", 1, 1],
59 + ["buffers_allocated", "buffers_allocated", "incremental", 1, 1],
60 + ]},
61 }
62 +ORDER = ["Tuples", "Transactions", "BlockAccess", "BlockTime", "Checkpoints", "Buffers"]
63
64
65 class Service(SimpleService):
@@ -63,7 +72,7 @@ class Service(SimpleService):
72
73 def connect(self):
74 params = dict(user='postgres',
66 - database=None,
75 + database='postgres',
76 password=None,
77 host='localhost',
78 port=5432)
@@ -82,45 +91,22 @@ class Service(SimpleService):
91 def _get_data(self):
92 cursor = self.connection.cursor(cursor_factory=DictCursor)
93 cursor.execute("""
85 - SELECT
86 - -- Tuples
87 - COALESCE(sum(seq_tup_read),0) AS seqread,
88 - COALESCE(sum(idx_tup_fetch),0) AS idxfetch,
89 - COALESCE(sum(n_tup_ins),0) AS inserted,
90 - COALESCE(sum(n_tup_upd),0) AS updated,
91 - COALESCE(sum(n_tup_del),0) AS deleted,
92 - COALESCE(sum(n_tup_hot_upd),0) AS hotupdated,
93 -
94 - -- Scans
95 - COALESCE(sum(seq_scan),0) AS sequential,
96 - COALESCE(sum(idx_scan),0) AS index
97 - FROM pg_stat_user_tables
98 - """)
99 - graph_data = {k: float(v) for k, v in cursor.fetchone().items()}
94 + SELECT *
95 + FROM pg_stat_database
96 + WHERE datname = %(database)s
97 + """, self.configuration)
98 + graph_data = dict(cursor.fetchone())
99
100 # Pull in BGWriter info
101 cursor.execute("""
102 SELECT
104 - buffers_checkpoint,
105 - buffers_clean,
106 - buffers_backend,
107 - buffers_alloc
108 - FROM
109 - pg_stat_bgwriter
103 + pg_stat_get_bgwriter_timed_checkpoints() AS bg_checkpoint_time,
104 + pg_stat_get_bgwriter_requested_checkpoints() AS bg_checkpoint_requested,
105 + pg_stat_get_buf_written_backend() AS buffers_written,
106 + pg_stat_get_buf_alloc() AS buffers_allocated
107 """)
108 graph_data.update(dict(cursor.fetchone()))
109
113 - cursor.execute("""
114 - SELECT
115 - sum(blks_read) AS blks_read,
116 - sum(blks_hit) AS blks_hit
117 - FROM
118 - pg_stat_database
119 - WHERE
120 - datname = %(database)s
121 - """, self.configuration)
122 - graph_data.update({k: float(v) for k, v in cursor.fetchone().items()})
123 -
110 self.connection.commit()
111 cursor.close()
112 return graph_data