Class: Cloudscale::Plugins::PostgresServerStatus
- Defined in:
- lib/cloudscale/plugins/postgres/postgres_server_status.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Attributes inherited from Plugin
Instance Method Summary collapse
- #collect(agentInstanceId) ⇒ Object
-
#initialize ⇒ PostgresServerStatus
constructor
A new instance of PostgresServerStatus.
- #is_enabled ⇒ Object
- #report_database_stats(registry, metrics) ⇒ Object
- #report_table_stats(registry, metrics) ⇒ Object
Methods inherited from Plugin
Constructor Details
#initialize ⇒ PostgresServerStatus
Returns a new instance of PostgresServerStatus.
18 19 20 21 22 23 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 18 def initialize super if is_enabled @connection = Preops::PostgresPreop.instance.connection end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def connection @connection end |
Instance Method Details
#collect(agentInstanceId) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 25 def collect(agentInstanceId) registry = Monitor::Registry.instance metrics = Metrics::Agent.new log.info("Calling Collect on PostgresServerStatus") report_database_stats(registry, metrics) report_table_stats(registry, metrics) end |
#is_enabled ⇒ Object
14 15 16 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 14 def is_enabled Preops::PostgresPreop.instance.is_enabled end |
#report_database_stats(registry, metrics) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 33 def report_database_stats(registry, metrics) result = @connection.exec('SELECT sum(idx_tup_fetch) AS "rows_select_idx", sum(seq_tup_read) AS "rows_select_scan", sum(n_tup_ins) AS "rows_insert", sum(n_tup_upd) AS "rows_update", sum(n_tup_del) AS "rows_delete", (sum(idx_tup_fetch) + sum(seq_tup_read) + sum(n_tup_ins) + sum(n_tup_upd) + sum(n_tup_del)) AS "rows_total" FROM pg_stat_all_tables;') row = result[0] registry.metrics["postgres.rows.select.index"] = metrics.gauge :rows_select_idx do { :value => row['rows_select_idx'] } end registry.metrics["postgres.rows.select.scan"] = metrics.gauge :rows_select_scan do { :value => row['rows_select_scan'] } end registry.metrics["postgres.rows.inserts"] = metrics.gauge :rows_insert do { :value => row['rows_insert'] } end registry.metrics["postgres.rows.updates"] = metrics.gauge :rows_update do { :value => row['rows_update'] } end registry.metrics["postgres.rows.select.delete"] = metrics.gauge :rows_delete do { :value => row['rows_delete'] } end registry.metrics["postgres.rows.select.total"] = metrics.gauge :rows_total do { :value => row['rows_total'] } end end |
#report_table_stats(registry, metrics) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 68 def report_table_stats(registry, metrics) result = @connection.exec('SELECT sum(numbackends) AS "numbackends", sum(xact_commit) AS "xact_commit", sum(xact_rollback) AS "xact_rollback", sum(xact_commit+xact_rollback) AS "xact_total", sum(blks_read) AS "blks_read", sum(blks_hit) AS "blks_hit" FROM pg_stat_database;') row = result[0] registry.metrics["postgres.transactions.commit"] = metrics.gauge :xact_commit do { :value => row['xact_commit'] } end registry.metrics["postgres.transactions.rollback"] = metrics.gauge :xact_rollback do { :value => row['xact_rollback'] } end registry.metrics["postgres.transactions.total"] = metrics.gauge :xact_total do { :value => row['xact_total'] } end registry.metrics["postgres.bulk.reads"] = metrics.gauge :blks_read do { :value => row['blks_read'] } end registry.metrics["postgres.bulk.hits"] = metrics.gauge :blks_hit do { :value => row['blks_hit'] } end end |