Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
basic controller action stats display
Browse files Browse the repository at this point in the history
  • Loading branch information
aastronautss committed Apr 14, 2017
1 parent 739e075 commit 319d0f0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
Empty file added action
Empty file.
28 changes: 28 additions & 0 deletions app/controllers/app_bins_controller.rb
Expand Up @@ -2,6 +2,34 @@ class AppBinsController < ApplicationController
before_action :set_app_bin

def show
sql = <<~SQL
SELECT c, a, event_type, AVG(tot_duration) AS avg_time_spent, ROUND(AVG(event_count)) AS avg_count, COUNT(*) AS total_requests
FROM (
SELECT t_id, ca.controller AS c, ca.action AS a, e.event_type, AVG(e.duration) AS avg_duration, SUM(e.duration) AS tot_duration, COUNT(e.duration) AS event_count
FROM transaction_events AS e
INNER JOIN (
SELECT cycle_transaction_id AS t_id, data->>'controller' AS controller, data->>'action' AS action
FROM transaction_events
WHERE event_type = 'controller_action'
) AS ca
ON ca.t_id = e.cycle_transaction_id
GROUP BY t_id, ca.controller, ca.action, e.event_type
) AS totals
GROUP BY c, a, event_type
ORDER BY total_requests DESC, c, a, event_type;
SQL

tuples = ActiveRecord::Base.connection.execute sql
@actions = {}
tuples.each do |tuple|
c_a = "#{tuple['c']}##{tuple['a']}"
@actions[c_a] ||= {}
event_values = Hash[tuple.slice('avg_time_spent', 'avg_count', 'total_requests').
map do |k, v|
[k, v.to_i == v.to_f ? v.to_i : v.to_f]
end]
@actions[c_a][tuple['event_type']] = event_values
end
end

def new
Expand Down
25 changes: 25 additions & 0 deletions app/views/app_bins/show.html.haml
@@ -1 +1,26 @@
= @app_bin.to_param

%table
%thead
%tr
%th Controller#action
%th Average Response (ms)
%th Total Requests
%th Average # Queries
%th % in App
%th % in SQL
%th % in View
%tbody
- @actions.each do |action, data|
- total_time = data['controller_action']['avg_time_spent']
- sql_time = data['sql'] ? data['sql']['avg_time_spent'] : 0.0
- view_time = data['view'] ? data['view']['avg_time_spent'] : 0.0
- app_time = total_time - sql_time - view_time
%tr
%td= action
%td= "%0.2f" % total_time
%td= data['controller_action']['total_requests']
%td= data['sql']['avg_count']
%td= "%0.1f" % (app_time / total_time)
%td= "%0.1f" % (sql_time / total_time)
%td= "%0.1f" % (view_time / total_time)
Empty file added controller
Empty file.

0 comments on commit 319d0f0

Please sign in to comment.