Class: Cloudscale::Plugins::PostgresServerStatus
- Defined in:
- lib/cloudscale/plugins/postgres/postgres_server_status.rb
Instance Attribute Summary collapse
-
#blksHit ⇒ Object
readonly
Returns the value of attribute blksHit.
-
#blksRead ⇒ Object
readonly
Returns the value of attribute blksRead.
-
#generalInformation ⇒ Object
readonly
Returns the value of attribute generalInformation.
-
#menu_bulkOps ⇒ Object
readonly
Returns the value of attribute menu_bulkOps.
-
#menu_generalInformationm ⇒ Object
readonly
Returns the value of attribute menu_generalInformationm.
-
#menu_numBackends ⇒ Object
readonly
Returns the value of attribute menu_numBackends.
-
#menu_rowStats ⇒ Object
readonly
Returns the value of attribute menu_rowStats.
-
#menu_transactionInformation ⇒ Object
readonly
Returns the value of attribute menu_transactionInformation.
-
#numBackends ⇒ Object
readonly
Returns the value of attribute numBackends.
-
#rowDeleted ⇒ Object
readonly
Returns the value of attribute rowDeleted.
-
#rowInserts ⇒ Object
readonly
Returns the value of attribute rowInserts.
-
#rowsSelectIdx ⇒ Object
readonly
Returns the value of attribute rowsSelectIdx.
-
#rowsSelectScan ⇒ Object
readonly
Returns the value of attribute rowsSelectScan.
-
#rowTotal ⇒ Object
readonly
Returns the value of attribute rowTotal.
-
#rowUpdated ⇒ Object
readonly
Returns the value of attribute rowUpdated.
-
#xactCommit ⇒ Object
readonly
Returns the value of attribute xactCommit.
-
#xactRollback ⇒ Object
readonly
Returns the value of attribute xactRollback.
-
#xactTotal ⇒ Object
readonly
Returns the value of attribute xactTotal.
Attributes inherited from Plugin
Instance Method Summary collapse
- #collect(agentInstanceId) ⇒ Object
-
#initialize ⇒ PostgresServerStatus
constructor
A new instance of PostgresServerStatus.
- #is_enabled ⇒ Object
- #log ⇒ Object
- #report_database_stats(agentInstanceId) ⇒ Object
- #report_general_information(agentInstanceId) ⇒ Object
- #report_table_stats(agentInstanceId) ⇒ Object
Methods inherited from Plugin
inherited, plugins, remove, remove_agenInstance, reset, resetRestEndpoint
Constructor Details
#initialize ⇒ PostgresServerStatus
Returns a new instance of PostgresServerStatus.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 23 def initialize super if is_enabled = Plugins::PluginMenus.load_hash() @menu_generalInformation = (["pgDatabaseStats"], "generalInformation") @menu_numBackends = (["pgDatabaseStats"], "numBackends") @menu_transactionInformation = (["pgDatabaseStats"], "transactionInformation") @menu_bulkOps = (["pgDatabaseStats"], "bulkOps") @menu_rowStats = (["pgTableStats"], "rowStats") @connection = Plugins::PostgresDbWrapper.instance.connection components = Plugins::PluginComponents.load_hash() @numBackends = load_metric(components["pgDatabaseStats"], "numBackends") @xactCommit = load_metric(components["pgDatabaseStats"], "xactCommit") @xactRollback = load_metric(components["pgDatabaseStats"], "xactRollback") @xactTotal = load_metric(components["pgDatabaseStats"], "xactTotal") @blksRead = load_metric(components["pgDatabaseStats"], "blksRead") @blksHit = load_metric(components["pgDatabaseStats"], "blksHit") @generalInformation = load_metric(components["pgDatabaseStats"], "generalInformation") @rowsSelectIdx = load_metric(components["pgTableStats"], "rowsSelectIdx") @rowsSelectScan = load_metric(components["pgTableStats"], "rowsSelectScan") @rowInserts = load_metric(components["pgTableStats"], "rowInserts") @rowUpdated = load_metric(components["pgTableStats"], "rowUpdated") @rowDeleted = load_metric(components["rowDeleted"], "rowDeleted") @rowTotal = load_metric(components["rowTotal"], "rowTotal") end end |
Instance Attribute Details
#blksHit ⇒ Object (readonly)
Returns the value of attribute blksHit.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def blksHit @blksHit end |
#blksRead ⇒ Object (readonly)
Returns the value of attribute blksRead.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def blksRead @blksRead end |
#generalInformation ⇒ Object (readonly)
Returns the value of attribute generalInformation.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def generalInformation @generalInformation end |
#menu_bulkOps ⇒ Object (readonly)
Returns the value of attribute menu_bulkOps.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def @menu_bulkOps end |
#menu_generalInformationm ⇒ Object (readonly)
Returns the value of attribute menu_generalInformationm.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def @menu_generalInformationm end |
#menu_numBackends ⇒ Object (readonly)
Returns the value of attribute menu_numBackends.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def @menu_numBackends end |
#menu_rowStats ⇒ Object (readonly)
Returns the value of attribute menu_rowStats.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def @menu_rowStats end |
#menu_transactionInformation ⇒ Object (readonly)
Returns the value of attribute menu_transactionInformation.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def @menu_transactionInformation end |
#numBackends ⇒ Object (readonly)
Returns the value of attribute numBackends.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def numBackends @numBackends end |
#rowDeleted ⇒ Object (readonly)
Returns the value of attribute rowDeleted.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def rowDeleted @rowDeleted end |
#rowInserts ⇒ Object (readonly)
Returns the value of attribute rowInserts.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def rowInserts @rowInserts end |
#rowsSelectIdx ⇒ Object (readonly)
Returns the value of attribute rowsSelectIdx.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def rowsSelectIdx @rowsSelectIdx end |
#rowsSelectScan ⇒ Object (readonly)
Returns the value of attribute rowsSelectScan.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def rowsSelectScan @rowsSelectScan end |
#rowTotal ⇒ Object (readonly)
Returns the value of attribute rowTotal.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def rowTotal @rowTotal end |
#rowUpdated ⇒ Object (readonly)
Returns the value of attribute rowUpdated.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def rowUpdated @rowUpdated end |
#xactCommit ⇒ Object (readonly)
Returns the value of attribute xactCommit.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def xactCommit @xactCommit end |
#xactRollback ⇒ Object (readonly)
Returns the value of attribute xactRollback.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def xactRollback @xactRollback end |
#xactTotal ⇒ Object (readonly)
Returns the value of attribute xactTotal.
12 13 14 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12 def xactTotal @xactTotal end |
Instance Method Details
#collect(agentInstanceId) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 54 def collect(agentInstanceId) log.info("Calling Collect on MongoServerStatus") report_general_information(agentInstanceId) report_database_stats(agentInstanceId) report_table_stats(agentInstanceId) end |
#is_enabled ⇒ Object
19 20 21 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 19 def is_enabled false end |
#log ⇒ Object
15 16 17 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 15 def log @log = Logger.new(STDOUT) end |
#report_database_stats(agentInstanceId) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 61 def report_database_stats(agentInstanceId) 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] report(rowsSelectIdx, , row['rows_select_idx'], false, agentInstanceId, "rowsSelectIdxChart", "Select indexes", "Select indexes across all tables in the database", "area", "Time", "Count", "c", nil) report(rowsSelectScan, , row['rows_select_scan'], false, agentInstanceId, "rowsSelectScanChart", "Row select scan", "Row select scans across all tables in the database", "area", "Time", "Count", "c", nil) report(rowInserts, , row['rows_insert'], false, agentInstanceId, "rowInsertsChart", "Row inserts", "Row inserts across all tables in the database", "area", "Time", "Count", "c", nil) report(rowUpdated, , row['rows_update'], false, agentInstanceId, "rowUpdatedChart", "Row updates", "Row updates across all tables in the database", "area", "Time", "Count", "c", nil) report(rowDeleted, , row['rows_delete'], false, agentInstanceId, "rowDeletedChart", "Row deletes", "Row deletes across all tables in the database", "area", "Time", "Count", "c", nil) report(rowTotal, , row['rows_total'], false, agentInstanceId, "rowTotalChart", "Rows affected", "Rows affected across all tables in the database", "area", "Time", "Count", "c", nil) end |
#report_general_information(agentInstanceId) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 116 def report_general_information(agentInstanceId) result = @connection.exec('SELECT datid, datname, pid, usesysid, usename, client_addr, client_hostname, client_port, backend_start, state, waiting FROM pg_stat_activity;') row = result[0] body = Array.new body.push(["DatId", row['datid']]) body.push(["Datname", row['datname']]) body.push(["Pid", row['pid']]) body.push(["Use Sysid", row['usesysid']]) body.push(["usename", row['usename']]) body.push(["client_addr", row['client_addr']]) body.push(["client_hostname", row['client_hostname']]) body.push(["client_port", row['client_port']]) body.push(["backend_start", row['backend_start']]) body.push(["state", row['state']]) body.push(["waiting", row['waiting']]) mongo_general_inf_table = Monitor::Table.new("generalInformationPostgres", "Postgres General Information", nil, body, "compact") mongo_general_inf_table. = "General Information regarding your Postgres Instance" persist_table(mongo_general_inf_table, agentInstanceId, ) end |
#report_table_stats(agentInstanceId) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 90 def report_table_stats(agentInstanceId) 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] report(xactCommit, , row['xact_commit'], false, agentInstanceId, "xactCommitChart", "Transaction commits", "Transaction commits across all tables in the database", "area", "Time", "Count", "c", nil) report(xactRollback, , row['xact_rollback'], false, agentInstanceId, "xactRollbackChart", "Transaction rollback", "Transaction rollback across all tables in the database", "area", "Time", "Count", "c", nil) report(xactTotal, , row['xact_total'], false, agentInstanceId, "xactTotalChart", "Transactions total", "Transactions total across all tables in the database", "area", "Time", "Count", "c", nil) report(blksRead, , row['blks_read'], false, agentInstanceId, "blksReadChart", "Bulk reads", "Bulk reads across all tables in the database", "area", "Time", "Count", "c", nil) report(blksHit, , row['blks_hit'], false, agentInstanceId, "blksHitChart", "Bulk hits", "Bulk hits across all tables in the database", "area", "Time", "Count", "c", nil) end |