Class: PgHero::HomeController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/pg_hero/home_controller.rb

Instance Method Summary collapse

Instance Method Details

#enable_query_statsObject



77
78
79
80
81
82
83
84
# File 'app/controllers/pg_hero/home_controller.rb', line 77

def enable_query_stats
  begin
    PgHero.enable_query_stats
    redirect_to :back, notice: "Query stats enabled"
  rescue ActiveRecord::StatementInvalid => e
    redirect_to :back, alert: "The database user does not have permission to enable query stats"
  end
end

#explainObject



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/pg_hero/home_controller.rb', line 50

def explain
  @title = "Explain"
  @query = params[:query]
  # TODO use get + token instead of post so users can share links
  # need to prevent CSRF and DoS
  if request.post? and @query
    begin
      @explanation = PgHero.explain(@query)
    rescue ActiveRecord::StatementInvalid => e
      @error = e.message
    end
  end
end

#indexObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/pg_hero/home_controller.rb', line 11

def index
  @title = "Status"
  @slow_queries = PgHero.slow_queries
  @long_running_queries = PgHero.long_running_queries
  @index_hit_rate = PgHero.index_hit_rate
  @table_hit_rate = PgHero.table_hit_rate
  @missing_indexes = PgHero.missing_indexes
  @unused_indexes = PgHero.unused_indexes
  @good_cache_rate = @table_hit_rate >= 0.99 && @index_hit_rate >= 0.99
  @query_stats_available = PgHero.query_stats_available?
  @rds = PgHero.rds?
end

#indexesObject



24
25
26
27
# File 'app/controllers/pg_hero/home_controller.rb', line 24

def indexes
  @title = "Indexes"
  @index_usage = PgHero.index_usage
end

#killObject



64
65
66
67
68
69
70
# File 'app/controllers/pg_hero/home_controller.rb', line 64

def kill
  if PgHero.kill(params[:pid])
    redirect_to root_path, notice: "Query killed"
  else
    redirect_to :back, notice: "Query no longer running"
  end
end

#kill_allObject



72
73
74
75
# File 'app/controllers/pg_hero/home_controller.rb', line 72

def kill_all
  PgHero.kill_all
  redirect_to :back, notice: "Connections killed"
end

#queriesObject



35
36
37
38
# File 'app/controllers/pg_hero/home_controller.rb', line 35

def queries
  @title = "Live Queries"
  @running_queries = PgHero.running_queries
end

#query_statsObject



40
41
42
43
# File 'app/controllers/pg_hero/home_controller.rb', line 40

def query_stats
  @title = "Queries"
  @query_stats = PgHero.query_stats
end

#reset_query_statsObject



86
87
88
89
90
91
92
93
# File 'app/controllers/pg_hero/home_controller.rb', line 86

def reset_query_stats
  begin
    PgHero.reset_query_stats
    redirect_to :back, notice: "Query stats reset"
  rescue ActiveRecord::StatementInvalid => e
    redirect_to :back, alert: "The database user does not have permission to reset query stats"
  end
end

#spaceObject



29
30
31
32
33
# File 'app/controllers/pg_hero/home_controller.rb', line 29

def space
  @title = "Space"
  @database_size = PgHero.database_size
  @relation_sizes = PgHero.relation_sizes
end

#system_statsObject



45
46
47
48
# File 'app/controllers/pg_hero/home_controller.rb', line 45

def system_stats
  @title = "System Stats"
  @cpu_usage = PgHero.cpu_usage
end