1 # -*- coding: utf-8 -*-
4 from base import SimpleService
5 from psycopg2.extras import DictCursor
7 # default module values
12 # Default Config options.
17 # 'host': 'localhost',
23 'options': ["tuples", "PostgreSQL tuple access", "Tuples / sec", "tuples", "postgres.tuples", "line"],
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],
32 'options': ["transactions", "Transactions", "transactions / sec", "transactions", "postgres.transactions", "line"],
34 ["xact_commit", "xact_commit", "incremental", 1, 1],
35 ["xact_rollback", "xact_rollback", "incremental", 1, 1],
38 'options': ["block_access", "block_access", "Block / sec ", "block_access", "postgres.block_access", "line"],
40 ["blks_read", "blks_read", "incremental", 1, 1],
41 ["blks_hit", "blks_hit", "incremental", 1, 1],
44 'options': ["block_time", "block_time", "milliseconds ", "block_time", "postgres.block_time", "line"],
46 ["blk_read_time", "blk_read_time", "incremental", 1, 1],
47 ["blk_write_time", "blk_write_time", "incremental", 1, 1],
50 'options': ["checkpoints", "Checkpoints", "Checkpoints", "checkpoints", "postgres.checkpoints", "line"],
52 ["bg_checkpoint_time", "bg_checkpoint_time", "absolute", 1, 1],
53 ["bg_checkpoint_requested", "bg_checkpoint_requested", "absolute", 1, 1],
56 'options': ["buffers", "buffers", "Buffer/ sec", "buffers", "postgres.buffers", "line"],
58 ["buffers_written", "buffers_written", "incremental", 1, 1],
59 ["buffers_allocated", "buffers_allocated", "incremental", 1, 1],
62 ORDER = ["Tuples", "Transactions", "BlockAccess", "BlockTime", "Checkpoints", "Buffers"]
65 class Service(SimpleService):
66 def __init__(self, configuration=None, name=None):
67 super(self.__class__, self).__init__(configuration=configuration, name=name)
69 self.definitions = CHARTS
70 self.configuration = configuration
71 self.connection = None
74 params = dict(user='postgres',
79 params.update(self.configuration)
80 if self.connection is None:
81 self.connection = psycopg2.connect(**params)
87 except Exception as e:
92 cursor = self.connection.cursor(cursor_factory=DictCursor)
96 WHERE datname = %(database)s
97 """, self.configuration)
98 graph_data = dict(cursor.fetchone())
100 # Pull in BGWriter info
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
108 graph_data.update(dict(cursor.fetchone()))
110 self.connection.commit()