Class: Cloudscale::Plugins::PostgresServerStatus

Inherits:
Plugin
  • Object
show all
Defined in:
lib/cloudscale/plugins/postgres/postgres_server_status.rb

Instance Attribute Summary collapse

Attributes inherited from Plugin

#plugins, #rest_client

Instance Method Summary collapse

Methods inherited from Plugin

inherited, plugins, remove, remove_agenInstance, reset, resetRestEndpoint

Constructor Details

#initializePostgresServerStatus

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
    menus = Plugins::PluginMenus.load_hash()
    @menu_generalInformation = load_menu(menus["pgDatabaseStats"], "generalInformation")
    @menu_numBackends = load_menu(menus["pgDatabaseStats"], "numBackends")
    @menu_transactionInformation = load_menu(menus["pgDatabaseStats"], "transactionInformation")
    @menu_bulkOps = load_menu(menus["pgDatabaseStats"], "bulkOps")
    @menu_rowStats = load_menu(menus["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

#blksHitObject (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

#blksReadObject (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

#generalInformationObject (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

Returns the value of attribute menu_bulkOps.



12
13
14
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12

def menu_bulkOps
  @menu_bulkOps
end

Returns the value of attribute menu_generalInformationm.



12
13
14
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12

def menu_generalInformationm
  @menu_generalInformationm
end

Returns the value of attribute menu_numBackends.



12
13
14
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12

def menu_numBackends
  @menu_numBackends
end

Returns the value of attribute menu_rowStats.



12
13
14
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12

def menu_rowStats
  @menu_rowStats
end

Returns the value of attribute menu_transactionInformation.



12
13
14
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 12

def menu_transactionInformation
  @menu_transactionInformation
end

#numBackendsObject (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

#rowDeletedObject (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

#rowInsertsObject (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

#rowsSelectIdxObject (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

#rowsSelectScanObject (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

#rowTotalObject (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

#rowUpdatedObject (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

#xactCommitObject (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

#xactRollbackObject (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

#xactTotalObject (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_enabledObject



19
20
21
# File 'lib/cloudscale/plugins/postgres/postgres_server_status.rb', line 19

def is_enabled
  false
end

#logObject



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, menu_rowStats, row['rows_select_idx'], false, agentInstanceId, "rowsSelectIdxChart",
      "Select indexes", "Select indexes across all tables in the database", "area", "Time", "Count", "c",  nil) 
  
  report(rowsSelectScan, menu_rowStats, 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, menu_rowStats, row['rows_insert'], false, agentInstanceId, "rowInsertsChart",
      "Row inserts", "Row inserts across all tables in the database", "area", "Time", "Count", "c",  nil)
      
  report(rowUpdated, menu_rowStats, row['rows_update'], false, agentInstanceId, "rowUpdatedChart",
      "Row updates", "Row updates across all tables in the database", "area", "Time", "Count", "c",  nil)
      
  report(rowDeleted, menu_rowStats, row['rows_delete'], false, agentInstanceId, "rowDeletedChart",
      "Row deletes", "Row deletes across all tables in the database", "area", "Time", "Count", "c",  nil)
  
  report(rowTotal, menu_rowStats, 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.caption = "General Information regarding your Postgres Instance"
  
  persist_table(mongo_general_inf_table, agentInstanceId, menu_generalInformation)
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, menu_transactionInformation, row['xact_commit'], false, agentInstanceId, "xactCommitChart",
      "Transaction commits", "Transaction commits across all tables in the database", "area", "Time", "Count", "c",  nil)
  
  report(xactRollback, menu_transactionInformation, row['xact_rollback'], false, agentInstanceId, "xactRollbackChart",
      "Transaction rollback", "Transaction rollback across all tables in the database", "area", "Time", "Count", "c",  nil)
      
  report(xactTotal, menu_transactionInformation, row['xact_total'], false, agentInstanceId, "xactTotalChart",
      "Transactions total", "Transactions total across all tables in the database", "area", "Time", "Count", "c",  nil)
      
  report(blksRead, menu_bulkOps, row['blks_read'], false, agentInstanceId, "blksReadChart",
      "Bulk reads", "Bulk reads across all tables in the database", "area", "Time", "Count", "c",  nil)
  
  report(blksHit, menu_bulkOps, row['blks_hit'], false, agentInstanceId, "blksHitChart",
      "Bulk hits", "Bulk hits across all tables in the database", "area", "Time", "Count", "c",  nil)
end