influxdb-rails 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +11 -0
- data/.github/workflows/rubocop.yml +18 -0
- data/.github/workflows/spec.yml +32 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +35 -7
- data/CHANGELOG.md +40 -1
- data/README.md +125 -27
- data/Rakefile +0 -6
- data/gemfiles/Gemfile.rails-6.0.x +9 -0
- data/gemfiles/Gemfile.rails-6.1.x +9 -0
- data/influxdb-rails.gemspec +7 -4
- data/lib/influxdb-rails.rb +13 -2
- data/lib/influxdb/rails/configuration.rb +8 -12
- data/lib/influxdb/rails/context.rb +6 -40
- data/lib/influxdb/rails/helpers/rspec_matchers.rb +48 -0
- data/lib/influxdb/rails/metric.rb +39 -0
- data/lib/influxdb/rails/middleware/action_mailer_subscriber.rb +22 -0
- data/lib/influxdb/rails/middleware/active_job_subscriber.rb +67 -0
- data/lib/influxdb/rails/middleware/active_record_subscriber.rb +26 -0
- data/lib/influxdb/rails/middleware/block_instrumentation_subscriber.rb +24 -0
- data/lib/influxdb/rails/middleware/render_subscriber.rb +15 -16
- data/lib/influxdb/rails/middleware/request_subscriber.rb +16 -21
- data/lib/influxdb/rails/middleware/sql_subscriber.rb +18 -18
- data/lib/influxdb/rails/middleware/subscriber.rb +40 -27
- data/lib/influxdb/rails/railtie.rb +15 -18
- data/lib/influxdb/rails/sql/normalizer.rb +3 -3
- data/lib/influxdb/rails/tags.rb +33 -0
- data/lib/influxdb/rails/test_client.rb +13 -0
- data/lib/influxdb/rails/values.rb +24 -0
- data/lib/influxdb/rails/version.rb +1 -1
- data/lib/rails/generators/influxdb/templates/initializer.rb +4 -0
- data/sample-dashboard/Dockerfile +2 -2
- data/sample-dashboard/README.md +21 -28
- data/sample-dashboard/Rakefile +10 -5
- data/sample-dashboard/Ruby On Rails ActiveJob.json +600 -0
- data/sample-dashboard/{Ruby On Rails Performance (per Action).json → Ruby On Rails Performance per Action.json } +343 -589
- data/sample-dashboard/{Ruby On Rails Performance (per Request).json → Ruby On Rails Performance per Request.json } +361 -211
- data/sample-dashboard/Ruby On Rails Performance.json +1347 -1139
- data/sample-dashboard/Ruby On Rails Requests.json +834 -0
- data/sample-dashboard/Ruby On Rails Slowlog by Action.json +278 -0
- data/sample-dashboard/Ruby On Rails Slowlog by Request.json +277 -0
- data/sample-dashboard/Ruby On Rails Slowlog by SQL.json +328 -0
- data/sample-dashboard/docker-compose.yml +6 -1
- data/sample-dashboard/provisioning/activejob.json +600 -0
- data/sample-dashboard/provisioning/performance-action.json +334 -580
- data/sample-dashboard/provisioning/performance-request.json +355 -205
- data/sample-dashboard/provisioning/performance.json +1336 -1128
- data/sample-dashboard/provisioning/requests.json +834 -0
- data/sample-dashboard/provisioning/slowlog-action.json +278 -0
- data/sample-dashboard/provisioning/slowlog-requests.json +277 -0
- data/sample-dashboard/provisioning/slowlog-sql.json +328 -0
- data/spec/requests/action_controller_metrics_spec.rb +96 -0
- data/spec/requests/action_mailer_deliver_metrics_spec.rb +42 -0
- data/spec/requests/action_view_collection_metrics_spec.rb +57 -0
- data/spec/requests/action_view_partial_metrics_spec.rb +53 -0
- data/spec/requests/action_view_template_metrics_spec.rb +53 -0
- data/spec/requests/active_job_enqueue_metrics_spec.rb +56 -0
- data/spec/requests/active_job_perform_metrics_spec.rb +62 -0
- data/spec/requests/active_record_instantiation_metrics_spec.rb +56 -0
- data/spec/requests/active_record_sql_metrics_spec.rb +87 -0
- data/spec/requests/block_inistrumentation_spec.rb +55 -0
- data/spec/requests/context_spec.rb +27 -0
- data/spec/requests/logger_spec.rb +10 -0
- data/spec/spec_helper.rb +12 -4
- data/spec/support/broken_client.rb +11 -0
- data/spec/support/rails5/app.rb +48 -13
- data/spec/support/rails6/app.rb +83 -0
- data/spec/support/views/layouts/mailer.txt.erb +1 -0
- data/spec/support/views/{widgets → metrics}/_item.html.erb +0 -0
- data/spec/support/views/{widgets → metrics}/index.html.erb +0 -0
- data/spec/support/views/metrics/show.html.erb +4 -0
- data/spec/unit/block_instrumentation_spec.rb +18 -0
- data/spec/unit/tags.rb +47 -0
- metadata +123 -45
- data/.travis.yml +0 -37
- data/gemfiles/Gemfile.rails-4.2.x +0 -7
- data/gemfiles/Gemfile.rails-5.0.x +0 -7
- data/gemfiles/Gemfile.rails-5.1.x +0 -7
- data/lib/influxdb/rails/instrumentation.rb +0 -34
- data/lib/influxdb/rails/middleware/simple_subscriber.rb +0 -33
- data/spec/controllers/widgets_controller_spec.rb +0 -15
- data/spec/integration/integration_helper.rb +0 -1
- data/spec/integration/metrics_spec.rb +0 -27
- data/spec/shared_examples/data.rb +0 -61
- data/spec/support/rails4/app.rb +0 -48
- data/spec/unit/context_spec.rb +0 -40
- data/spec/unit/middleware/render_subscriber_spec.rb +0 -96
- data/spec/unit/middleware/request_subscriber_spec.rb +0 -103
- data/spec/unit/middleware/sql_subscriber_spec.rb +0 -108
@@ -1,31 +1,30 @@
|
|
1
|
-
require "influxdb/rails/middleware/
|
1
|
+
require "influxdb/rails/middleware/subscriber"
|
2
2
|
|
3
3
|
module InfluxDB
|
4
4
|
module Rails
|
5
5
|
module Middleware
|
6
|
-
class RenderSubscriber <
|
7
|
-
def short_hook_name
|
8
|
-
return "render_template" if hook_name.include?("render_template")
|
9
|
-
return "render_partial" if hook_name.include?("render_partial")
|
10
|
-
return "render_collection" if hook_name.include?("render_collection")
|
11
|
-
end
|
12
|
-
|
6
|
+
class RenderSubscriber < Subscriber # :nodoc:
|
13
7
|
private
|
14
8
|
|
15
|
-
def values
|
16
|
-
|
9
|
+
def values
|
10
|
+
{
|
11
|
+
value: duration,
|
17
12
|
count: payload[:count],
|
18
|
-
cache_hits: payload[:cache_hits]
|
19
|
-
|
13
|
+
cache_hits: payload[:cache_hits],
|
14
|
+
}
|
20
15
|
end
|
21
16
|
|
22
|
-
def tags
|
23
|
-
|
24
|
-
location: location,
|
17
|
+
def tags
|
18
|
+
{
|
25
19
|
hook: short_hook_name,
|
26
20
|
filename: payload[:identifier],
|
27
21
|
}
|
28
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
def short_hook_name
|
25
|
+
return "render_template" if hook_name.include?("render_template")
|
26
|
+
return "render_partial" if hook_name.include?("render_partial")
|
27
|
+
return "render_collection" if hook_name.include?("render_collection")
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
@@ -4,44 +4,39 @@ module InfluxDB
|
|
4
4
|
module Rails
|
5
5
|
module Middleware
|
6
6
|
class RequestSubscriber < Subscriber # :nodoc:
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
InfluxDB::Rails.client.write_point \
|
11
|
-
configuration.measurement_name,
|
12
|
-
values: values(start, finish, payload),
|
13
|
-
tags: tags(payload),
|
14
|
-
timestamp: timestamp(finish)
|
15
|
-
rescue StandardError => e
|
16
|
-
::Rails.logger.error("[InfluxDB::Rails] Unable to write points: #{e.message}")
|
7
|
+
def write
|
8
|
+
super
|
17
9
|
ensure
|
18
10
|
InfluxDB::Rails.current.reset
|
19
11
|
end
|
20
12
|
|
21
13
|
private
|
22
14
|
|
23
|
-
def tags
|
24
|
-
|
15
|
+
def tags
|
16
|
+
{
|
25
17
|
method: "#{payload[:controller]}##{payload[:action]}",
|
26
18
|
hook: "process_action",
|
27
19
|
status: payload[:status],
|
28
20
|
format: payload[:format],
|
29
21
|
http_method: payload[:method],
|
30
|
-
|
31
|
-
app_name: configuration.application_name,
|
22
|
+
exception: payload[:exception]&.first,
|
32
23
|
}
|
33
|
-
super(tags)
|
34
24
|
end
|
35
25
|
|
36
|
-
def values
|
26
|
+
def values
|
37
27
|
{
|
38
|
-
controller:
|
28
|
+
controller: duration,
|
39
29
|
view: (payload[:view_runtime] || 0).ceil,
|
40
30
|
db: (payload[:db_runtime] || 0).ceil,
|
41
|
-
started:
|
42
|
-
}
|
43
|
-
|
44
|
-
|
31
|
+
started: started,
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def started
|
36
|
+
InfluxDB.convert_timestamp(
|
37
|
+
start.utc,
|
38
|
+
configuration.client.time_precision
|
39
|
+
)
|
45
40
|
end
|
46
41
|
end
|
47
42
|
end
|
@@ -1,35 +1,35 @@
|
|
1
|
-
require "influxdb/rails/middleware/
|
1
|
+
require "influxdb/rails/middleware/subscriber"
|
2
2
|
require "influxdb/rails/sql/query"
|
3
3
|
|
4
4
|
module InfluxDB
|
5
5
|
module Rails
|
6
6
|
module Middleware
|
7
|
-
class SqlSubscriber <
|
8
|
-
def call(_name, started, finished, _unique_id, payload)
|
9
|
-
super if InfluxDB::Rails::Sql::Query.new(payload).track?
|
10
|
-
end
|
11
|
-
|
7
|
+
class SqlSubscriber < Subscriber # :nodoc:
|
12
8
|
private
|
13
9
|
|
14
|
-
def values
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
result = super
|
20
|
-
result.empty? ? :raw : result
|
10
|
+
def values
|
11
|
+
{
|
12
|
+
value: duration,
|
13
|
+
sql: InfluxDB::Rails::Sql::Normalizer.new(payload[:sql]).perform,
|
14
|
+
}
|
21
15
|
end
|
22
16
|
|
23
|
-
def tags
|
24
|
-
|
25
|
-
tags = {
|
26
|
-
location: location,
|
17
|
+
def tags
|
18
|
+
{
|
27
19
|
hook: "sql",
|
28
20
|
operation: query.operation,
|
29
21
|
class_name: query.class_name,
|
30
22
|
name: query.name,
|
23
|
+
location: :raw,
|
31
24
|
}
|
32
|
-
|
25
|
+
end
|
26
|
+
|
27
|
+
def disabled?
|
28
|
+
super || !query.track?
|
29
|
+
end
|
30
|
+
|
31
|
+
def query
|
32
|
+
@query ||= InfluxDB::Rails::Sql::Query.new(payload)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "influxdb/rails/metric"
|
2
|
+
|
1
3
|
module InfluxDB
|
2
4
|
module Rails
|
3
5
|
module Middleware
|
@@ -5,49 +7,60 @@ module InfluxDB
|
|
5
7
|
# which are intended as ActiveSupport::Notifications.subscribe
|
6
8
|
# consumers.
|
7
9
|
class Subscriber
|
8
|
-
|
9
|
-
attr_reader :hook_name
|
10
|
-
|
11
|
-
def initialize(configuration, hook_name)
|
10
|
+
def initialize(configuration:, hook_name:, start:, finish:, payload:)
|
12
11
|
@configuration = configuration
|
13
12
|
@hook_name = hook_name
|
13
|
+
@start = start
|
14
|
+
@finish = finish
|
15
|
+
@payload = payload
|
14
16
|
end
|
15
17
|
|
16
|
-
def call(
|
17
|
-
|
18
|
+
def self.call(name, start, finish, _id, payload)
|
19
|
+
new(
|
20
|
+
configuration: InfluxDB::Rails.configuration,
|
21
|
+
start: start,
|
22
|
+
finish: finish,
|
23
|
+
payload: payload,
|
24
|
+
hook_name: name
|
25
|
+
).write
|
26
|
+
end
|
27
|
+
|
28
|
+
def write
|
29
|
+
return if disabled?
|
30
|
+
|
31
|
+
metric.write
|
32
|
+
rescue StandardError => e
|
33
|
+
::Rails.logger.error("[InfluxDB::Rails] Unable to write points: #{e.message}")
|
18
34
|
end
|
19
35
|
|
20
36
|
private
|
21
37
|
|
22
|
-
|
23
|
-
|
38
|
+
attr_reader :configuration, :hook_name, :start, :finish, :payload
|
39
|
+
|
40
|
+
def metric
|
41
|
+
InfluxDB::Rails::Metric.new(
|
42
|
+
values: values,
|
43
|
+
tags: tags,
|
44
|
+
configuration: configuration,
|
45
|
+
timestamp: finish
|
46
|
+
)
|
24
47
|
end
|
25
48
|
|
26
|
-
def
|
27
|
-
|
49
|
+
def tags
|
50
|
+
raise NotImplementedError, "must be implemented in subclass"
|
28
51
|
end
|
29
52
|
|
30
|
-
def
|
31
|
-
|
32
|
-
result = configuration.tags_middleware.call(result)
|
33
|
-
result.reject! do |_, value|
|
34
|
-
value.nil? || value == ""
|
35
|
-
end
|
36
|
-
result
|
53
|
+
def values
|
54
|
+
raise NotImplementedError, "must be implemented in subclass"
|
37
55
|
end
|
38
56
|
|
39
|
-
def
|
40
|
-
|
41
|
-
!configuration.ignore_current_environment? &&
|
42
|
-
!configuration.ignored_hooks.include?(hook_name)
|
57
|
+
def duration
|
58
|
+
((finish - start) * 1000).ceil
|
43
59
|
end
|
44
60
|
|
45
|
-
def
|
46
|
-
|
47
|
-
|
48
|
-
current.controller,
|
49
|
-
current.action,
|
50
|
-
].reject(&:blank?).join("#")
|
61
|
+
def disabled?
|
62
|
+
configuration.ignore_current_environment? ||
|
63
|
+
configuration.ignored_hooks.include?(hook_name)
|
51
64
|
end
|
52
65
|
end
|
53
66
|
end
|
@@ -11,38 +11,35 @@ module InfluxDB
|
|
11
11
|
end
|
12
12
|
|
13
13
|
ActiveSupport.on_load(:action_controller) do
|
14
|
-
require "influxdb/rails/instrumentation"
|
15
|
-
include InfluxDB::Rails::Instrumentation
|
16
|
-
|
17
14
|
before_action do
|
18
15
|
current = InfluxDB::Rails.current
|
19
|
-
current.
|
16
|
+
current.values = { request_id: request.request_id } if request.respond_to?(:request_id)
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
23
20
|
cache = lambda do |_, _, _, _, payload|
|
24
21
|
current = InfluxDB::Rails.current
|
25
|
-
|
26
|
-
current.
|
22
|
+
location = [payload[:controller], payload[:action]].join("#")
|
23
|
+
current.tags = { location: location }
|
27
24
|
end
|
28
25
|
ActiveSupport::Notifications.subscribe "start_processing.action_controller", &cache
|
29
26
|
|
30
27
|
{
|
31
|
-
"process_action.action_controller"
|
32
|
-
"render_template.action_view"
|
33
|
-
"render_partial.action_view"
|
34
|
-
"render_collection.action_view"
|
35
|
-
"sql.active_record"
|
36
|
-
|
37
|
-
|
28
|
+
"process_action.action_controller" => Middleware::RequestSubscriber,
|
29
|
+
"render_template.action_view" => Middleware::RenderSubscriber,
|
30
|
+
"render_partial.action_view" => Middleware::RenderSubscriber,
|
31
|
+
"render_collection.action_view" => Middleware::RenderSubscriber,
|
32
|
+
"sql.active_record" => Middleware::SqlSubscriber,
|
33
|
+
"instantiation.active_record" => Middleware::ActiveRecordSubscriber,
|
34
|
+
"enqueue.active_job" => Middleware::ActiveJobSubscriber,
|
35
|
+
"perform.active_job" => Middleware::ActiveJobSubscriber,
|
36
|
+
"deliver.action_mailer" => Middleware::ActionMailerSubscriber,
|
37
|
+
"block_instrumentation.influxdb_rails" => Middleware::BlockInstrumentationSubscriber,
|
38
|
+
}.each do |hook_name, subscriber|
|
39
|
+
ActiveSupport::Notifications.subscribe(hook_name, subscriber)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
# rubocop:enable Metrics/BlockLength
|
41
|
-
|
42
|
-
def subscribe_to(hook_name, subscriber_class)
|
43
|
-
subscriber = subscriber_class.new(InfluxDB::Rails.configuration, hook_name)
|
44
|
-
ActiveSupport::Notifications.subscribe hook_name, subscriber
|
45
|
-
end
|
46
43
|
end
|
47
44
|
end
|
48
45
|
end
|
@@ -8,9 +8,9 @@ module InfluxDB
|
|
8
8
|
|
9
9
|
def perform
|
10
10
|
query.squish!
|
11
|
-
query.gsub!(/(\s(=|>|<|>=|<=|<>|!=)\s)('[^']+'|[
|
12
|
-
query.gsub!(/(\sIN\s)\([
|
13
|
-
regex = /(\sBETWEEN\s)('[^']+'|[
|
11
|
+
query.gsub!(/(\s(=|>|<|>=|<=|<>|!=)\s)('[^']+'|[$+\-\w.]+)/, '\1xxx')
|
12
|
+
query.gsub!(/(\sIN\s)\([^()]+\)/i, '\1(xxx)')
|
13
|
+
regex = /(\sBETWEEN\s)('[^']+'|[+\-\w.]+)(\sAND\s)('[^']+'|[+\-\w.]+)/i
|
14
14
|
query.gsub!(regex, '\1xxx\3xxx')
|
15
15
|
query.gsub!(/(\sVALUES\s)\(.+\)/i, '\1(xxx)')
|
16
16
|
query.gsub!(/(\s(LIKE|ILIKE|SIMILAR TO|NOT SIMILAR TO)\s)('[^']+')/i, '\1xxx')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module InfluxDB
|
2
|
+
module Rails
|
3
|
+
class Tags
|
4
|
+
def initialize(config:, tags: {}, additional_tags: InfluxDB::Rails.current.tags)
|
5
|
+
@tags = tags
|
6
|
+
@config = config
|
7
|
+
@additional_tags = additional_tags
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_h
|
11
|
+
expanded_tags.reject do |_, value|
|
12
|
+
value.to_s.blank?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
attr_reader :additional_tags, :tags, :config
|
19
|
+
|
20
|
+
def expanded_tags
|
21
|
+
config.tags_middleware.call(tags.merge(default_tags))
|
22
|
+
end
|
23
|
+
|
24
|
+
def default_tags
|
25
|
+
{
|
26
|
+
server: Socket.gethostname,
|
27
|
+
app_name: config.application_name,
|
28
|
+
location: :raw,
|
29
|
+
}.merge(additional_tags)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module InfluxDB
|
2
|
+
module Rails
|
3
|
+
class Values
|
4
|
+
def initialize(values: {}, additional_values: InfluxDB::Rails.current.values)
|
5
|
+
@values = values
|
6
|
+
@additional_values = additional_values
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_h
|
10
|
+
expanded_values.reject do |_, value|
|
11
|
+
value.to_s.blank?
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :additional_values, :values
|
18
|
+
|
19
|
+
def expanded_values
|
20
|
+
values.merge(additional_values)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -11,6 +11,10 @@ InfluxDB::Rails.configure do |config|
|
|
11
11
|
# config.client.username = "root"
|
12
12
|
# config.client.password = "root"
|
13
13
|
|
14
|
+
## If your InfluxDB service requires an HTTPS connection then you can
|
15
|
+
## enable it here.
|
16
|
+
# config.client.use_ssl = true
|
17
|
+
|
14
18
|
## Various other client and connection options. These are used to create
|
15
19
|
## an `InfluxDB::Client` instance (i.e. `InfluxDB::Rails.client`).
|
16
20
|
##
|
data/sample-dashboard/Dockerfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
FROM opensuse/leap:15.
|
1
|
+
FROM opensuse/leap:15.2
|
2
2
|
|
3
3
|
ENV NOKOGIRI_USE_SYSTEM_LIBRARIES 1
|
4
4
|
RUN useradd -g users -p rails -d /home/rails -m rails
|
5
5
|
RUN echo 'rails ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
|
6
6
|
|
7
7
|
RUN zypper -n addrepo -f https://dl.yarnpkg.com/rpm/yarn.repo; zypper --gpg-auto-import-keys refresh
|
8
|
-
RUN zypper -n install --no-recommends ruby2.5-devel nodejs10 make gcc timezone sudo pkg-config sqlite3-devel libxml2-devel libxslt-devel yarn git-core curl
|
8
|
+
RUN zypper -n install --no-recommends ruby2.5-devel nodejs10 make gcc-c++ timezone sudo pkg-config sqlite3-devel libxml2-devel libxslt-devel yarn git-core curl
|
9
9
|
RUN zypper -n clean -a
|
10
10
|
RUN gem install --no-format-executable --no-document rails -v '~> 6'
|
11
11
|
|
data/sample-dashboard/README.md
CHANGED
@@ -4,36 +4,42 @@ A dashboard providing Ruby on Rails performance insights based on
|
|
4
4
|
[Free Software](https://www.fsf.org/about/what-is-free-software), ready to
|
5
5
|
run inside your data-center.
|
6
6
|
|
7
|
-
![Screenshot of the dashboard](https://grafana.com/api/dashboards/10428/images/
|
7
|
+
![Screenshot of the dashboard](https://grafana.com/api/dashboards/10428/images/10103/image)
|
8
8
|
|
9
|
-
By default it measures (in various forms):
|
9
|
+
By default it measures (in various forms) performance of:
|
10
10
|
|
11
|
-
- Controller
|
12
|
-
- View/Partial
|
13
|
-
- Database
|
11
|
+
- Controller Actions
|
12
|
+
- View/Partial Rendering
|
13
|
+
- Database Queries
|
14
|
+
- ActiveJobs
|
15
|
+
- ActionMailers
|
14
16
|
|
15
|
-
|
17
|
+
The dashboards provide an overview and various ways to drill down into numbers on a per request or per action basis. Of course you can use all the awesome features that Influx (Downsampling/Data Retention), Grafana (Alerts, Annotations) and influxdb-rails (custom tags) provide and extend this to your needs. Use your freedom and run, copy, distribute, study, change and improve this software!
|
16
18
|
|
17
19
|
## Requirements
|
18
20
|
|
19
|
-
To be able to measure performance you need the following things available:
|
21
|
+
To be able to measure performance of your Ruby on Rails application you need to have the following things available:
|
20
22
|
|
21
|
-
- [InfluxDB 1.x](https://
|
22
|
-
- [Grafana](https://grafana.com/
|
23
|
+
- [InfluxDB 1.x](https://www.influxdata.com/products/influxdb/)
|
24
|
+
- [Grafana](https://grafana.com/)
|
23
25
|
- A [Ruby On Rails](https://rubyonrails.org/) application with [influxdb-rails](https://github.com/influxdata/influxdb-rails) enabled
|
24
26
|
|
25
27
|
## Installation
|
26
28
|
|
27
|
-
Once you have influx/grafana instances running in your infrastructure just [import
|
28
|
-
dashboards from grafana](https://grafana.com/docs/reference/export_import/#importing-a-dashboard).
|
29
|
+
Once you have influx/grafana instances running in your infrastructure just [import the
|
30
|
+
dashboards from grafana.com](https://grafana.com/docs/reference/export_import/#importing-a-dashboard).
|
29
31
|
|
30
|
-
- [Overview
|
31
|
-
- [Request
|
32
|
+
- [Ruby On Rails Performance Overview](https://grafana.com/dashboards/10428/)
|
33
|
+
- Performance insights into individual requests, see [Ruby On Rails Performance per Request](https://grafana.com/dashboards/10429/)
|
34
|
+
- Performance of individual actions, see [Ruby On Rails Performance per Action](https://grafana.com/grafana/dashboards/11031)
|
35
|
+
- [Ruby On Rails Health Overview](https://grafana.com/grafana/dashboards/14115)
|
36
|
+
- [Ruby on Rails ActiveJob Overview](https://grafana.com/grafana/dashboards/14116)
|
37
|
+
- [Ruby on Rails Slowlog by Request](https://grafana.com/grafana/dashboards/14118)
|
38
|
+
- [Ruby on Rails Slowlog by Action](https://grafana.com/grafana/dashboards/14117)
|
39
|
+
- [Ruby on Rails Slowlog by SQL](https://grafana.com/grafana/dashboards/14119)
|
32
40
|
|
33
41
|
You can also paste the `.json` files from this repository.
|
34
42
|
|
35
|
-
In the unlikely case that you need to change the dashboard *UID*s during import you can configure the *UID* the `Overview` dashboard uses to link to the `Request` dashboard in the [variables](https://grafana.com/docs/reference/templating/#adding-a-variable). Just paste whatever *UID* you've set up for the `Request` dashboard.
|
36
|
-
|
37
43
|
## Demo
|
38
44
|
|
39
45
|
This repository includes a [docker-compose](https://docs.docker.com/compose/) demo setup that brings a simple rails app, influxdb and grafana.
|
@@ -54,19 +60,6 @@ Go to http://0.0.0.0:4000 and do some things. Every request to the rails app wil
|
|
54
60
|
|
55
61
|
You can also use the dashboard with any other rails app you already have. Follow our [install instructions](https://github.com/influxdata/influxdb-rails/#installation), the default configuration works with the demo InfluxDB running on localhost:8086.
|
56
62
|
|
57
|
-
To be able to view individual requests you have to enable request ID tags in your application. Something like:
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
class ApplicationController < ActionController::Base
|
61
|
-
|
62
|
-
before_action :set_influx_data
|
63
|
-
|
64
|
-
def set_influx_data
|
65
|
-
InfluxDB::Rails.current.values = { request: request.request_id }
|
66
|
-
end
|
67
|
-
end
|
68
|
-
```
|
69
|
-
|
70
63
|
### ...then see the dashboards in action
|
71
64
|
|
72
65
|
Just go to http://0.0.0.0:3000 and log in with admin/admin.
|