Module: StatCollector
Instance Method Summary collapse
- #cache_hit ⇒ Object
- #capture_stats! ⇒ Object
- #connections ⇒ Object
- #locks ⇒ Object
- #reset_target_stats! ⇒ Object
- #stat_statements ⇒ Object
- #stats ⇒ Object
- #target_db ⇒ Object
Instance Method Details
#cache_hit ⇒ Object
43 44 45 46 47 48 |
# File 'lib/stat_collector.rb', line 43 def cache_hit target_db[:pg_statio_user_tables] .select("(sum(heap_blks_hit) - sum(heap_blks_read)) / sum(heap_blks_hit) as ratio".lit) .first[:ratio] .to_f end |
#capture_stats! ⇒ Object
18 19 20 21 22 |
# File 'lib/stat_collector.rb', line 18 def capture_stats! s = stats DB[:stats] << {data: s.to_json} "connections=#{s[:connections]} stat_statements=#{s[:stat_statements].count} cache_hit=#{cache_hit}" end |
#connections ⇒ Object
32 33 34 |
# File 'lib/stat_collector.rb', line 32 def connections target_db[:pg_stat_activity].count end |
#locks ⇒ Object
50 51 52 |
# File 'lib/stat_collector.rb', line 50 def locks target_db[:pg_locks].exclude(:granted).count end |
#reset_target_stats! ⇒ Object
24 25 26 |
# File 'lib/stat_collector.rb', line 24 def reset_target_stats! target_db.execute "select pg_stat_statements_reset()" end |
#stat_statements ⇒ Object
36 37 38 39 40 41 |
# File 'lib/stat_collector.rb', line 36 def stat_statements TARGET_DB[:pg_stat_statements] .select(:query, :calls, :total_time) .exclude(query: '<insufficient privilege>') .all end |
#stats ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/stat_collector.rb', line 9 def stats { connections: connections, stat_statements: stat_statements, cache_hit: cache_hit, locks: locks } end |
#target_db ⇒ Object
28 29 30 |
# File 'lib/stat_collector.rb', line 28 def target_db TARGET_DB end |