influxdb-rails 0.4.999 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +77 -0
- data/.travis.yml +21 -14
- data/CHANGELOG.md +27 -8
- data/README.md +14 -9
- data/Rakefile +7 -8
- data/gemfiles/Gemfile.rails-5.2.x +7 -0
- data/influxdb-rails.gemspec +26 -37
- data/lib/influxdb-rails.rb +94 -119
- data/lib/influxdb/rails/air_traffic_controller.rb +22 -20
- data/lib/influxdb/rails/backtrace.rb +5 -5
- data/lib/influxdb/rails/configuration.rb +78 -47
- data/lib/influxdb/rails/exception_presenter.rb +53 -42
- data/lib/influxdb/rails/instrumentation.rb +15 -15
- data/lib/influxdb/rails/logger.rb +7 -4
- data/lib/influxdb/rails/middleware/hijack_render_exception.rb +4 -19
- data/lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb +11 -12
- data/lib/influxdb/rails/rack.rb +2 -2
- data/lib/influxdb/rails/railtie.rb +16 -30
- data/lib/influxdb/rails/version.rb +1 -1
- data/lib/rails/generators/influxdb/influxdb_generator.rb +5 -4
- data/spec/controllers/widgets_controller_spec.rb +2 -2
- data/spec/integration/exceptions_spec.rb +5 -9
- data/spec/integration/metrics_spec.rb +2 -4
- data/spec/spec_helper.rb +16 -13
- data/spec/support/rails4/app.rb +10 -5
- data/spec/support/rails5/app.rb +11 -5
- data/spec/unit/backtrace_spec.rb +2 -5
- data/spec/unit/configuration_spec.rb +19 -15
- data/spec/unit/exception_presenter_spec.rb +3 -3
- data/spec/unit/influxdb_rails_spec.rb +104 -56
- metadata +38 -39
- data/gemfiles/Gemfile.rails-4.0.x +0 -8
- data/gemfiles/Gemfile.rails-4.1.x +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68333c3962daf87c05e1ff1b221accc5854e4c7d671f0d0441a5c789b2322cee
|
4
|
+
data.tar.gz: 56017328de99c335fd4c590fe80c2d9de1b9132f39a7d3ac6d07b87b551597f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6c6087522e487aaefabe377698d2275270070c0e9d70eb7110fd90000f2160fc03b127879e39481ca0ff7f1f6bc5010075c4d9fe64bd30ecebd9b04b7e98df6
|
7
|
+
data.tar.gz: baf2150e6140c85119da580cb89b06204a0372277c6adf7c57f15b89c214e41d80f05e0b47447df939eecc26dfb27115787750d92a22ae3ced38a047448f97bc
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- 'Rakefile'
|
4
|
+
- '*.gemspec'
|
5
|
+
- 'lib/**/*.rb'
|
6
|
+
- 'spec/**/*.rb'
|
7
|
+
Exclude:
|
8
|
+
- 'bin/**/*'
|
9
|
+
- 'smoke/**/*'
|
10
|
+
- 'Gemfile'
|
11
|
+
DisplayCopNames: true
|
12
|
+
StyleGuideCopsOnly: false
|
13
|
+
TargetRubyVersion: 2.3
|
14
|
+
|
15
|
+
Rails:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Layout/EmptyLinesAroundArguments:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Layout/SpaceBeforeBlockBraces:
|
22
|
+
EnforcedStyleForEmptyBraces: space
|
23
|
+
|
24
|
+
Layout/AlignHash:
|
25
|
+
EnforcedColonStyle: table
|
26
|
+
EnforcedHashRocketStyle: table
|
27
|
+
|
28
|
+
Metrics/AbcSize:
|
29
|
+
Max: 20
|
30
|
+
|
31
|
+
Metrics/BlockLength:
|
32
|
+
Exclude:
|
33
|
+
- 'spec/**/*.rb'
|
34
|
+
|
35
|
+
Metrics/LineLength:
|
36
|
+
Max: 100
|
37
|
+
Exclude:
|
38
|
+
- 'spec/**/*.rb'
|
39
|
+
|
40
|
+
Metrics/ModuleLength:
|
41
|
+
CountComments: false # count full line comments?
|
42
|
+
Max: 120
|
43
|
+
|
44
|
+
Metrics/ParameterLists:
|
45
|
+
Max: 6
|
46
|
+
|
47
|
+
Naming/UncommunicativeMethodParamName:
|
48
|
+
AllowedNames: [io, id, db, ex]
|
49
|
+
|
50
|
+
Naming/FileName:
|
51
|
+
Exclude:
|
52
|
+
- lib/influxdb-rails.rb
|
53
|
+
|
54
|
+
Style/FormatStringToken:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/FrozenStringLiteralComment:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/NumericPredicate:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/RescueModifier:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/StringLiterals:
|
67
|
+
EnforcedStyle: double_quotes
|
68
|
+
|
69
|
+
Style/TrailingCommaInArrayLiteral:
|
70
|
+
EnforcedStyleForMultiline: comma
|
71
|
+
Exclude:
|
72
|
+
- "spec/**/*.rb"
|
73
|
+
|
74
|
+
Style/TrailingCommaInHashLiteral:
|
75
|
+
EnforcedStyleForMultiline: comma
|
76
|
+
Exclude:
|
77
|
+
- "spec/**/*.rb"
|
data/.travis.yml
CHANGED
@@ -4,25 +4,32 @@ language: ruby
|
|
4
4
|
before_install:
|
5
5
|
- gem update --system --no-doc
|
6
6
|
- gem install bundler --no-doc
|
7
|
+
- gem update bundler --no-doc
|
7
8
|
rvm:
|
8
|
-
-
|
9
|
-
- 2.3
|
9
|
+
- ruby-head
|
10
|
+
- 2.5.3
|
11
|
+
- 2.4.5
|
12
|
+
- 2.3.8
|
10
13
|
gemfile:
|
14
|
+
- gemfiles/Gemfile.rails-5.2.x
|
11
15
|
- gemfiles/Gemfile.rails-5.1.x
|
12
16
|
- gemfiles/Gemfile.rails-5.0.x
|
13
17
|
- gemfiles/Gemfile.rails-4.2.x
|
14
|
-
|
15
|
-
-
|
18
|
+
env:
|
19
|
+
- TEST_TASK=spec
|
16
20
|
matrix:
|
21
|
+
allow_failures:
|
22
|
+
- rvm: ruby-head
|
23
|
+
include:
|
24
|
+
- { rvm: "2.5.3", gemfile: "Gemfile", env: [TEST_TASK=rubocop] }
|
17
25
|
exclude:
|
18
|
-
# Rails < 5 not on MRI 2.4
|
19
|
-
- { rvm:
|
20
|
-
- { rvm: "2.4.
|
21
|
-
- { rvm: "2.
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
on_failure: always
|
26
|
+
# Rails < 5 not on MRI 2.4+
|
27
|
+
- { rvm: ruby-head, gemfile: "gemfiles/Gemfile.rails-4.2.x" }
|
28
|
+
- { rvm: "2.4.5", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
|
29
|
+
- { rvm: "2.5.3", gemfile: "gemfiles/Gemfile.rails-4.2.x" }
|
30
|
+
addons:
|
31
|
+
apt:
|
32
|
+
packages:
|
33
|
+
- haveged
|
34
|
+
- libgmp-dev
|
28
35
|
script: bundle exec rake spec
|
data/CHANGELOG.md
CHANGED
@@ -3,14 +3,33 @@
|
|
3
3
|
For the full commit log, [see here](https://github.com/influxdata/influxdb-rails/commits/master).
|
4
4
|
|
5
5
|
|
6
|
-
##
|
7
|
-
|
8
|
-
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
-
|
13
|
-
|
6
|
+
## v1.0.0.beta1, released 2018-11-22
|
7
|
+
|
8
|
+
- Added app name to the measurement's tag sets (#44, @stefanhorning)
|
9
|
+
- Added config parameters for additional series:
|
10
|
+
- `InfluxDB::Rails::Configuration#series_name_for_instrumentation`
|
11
|
+
- `InfluxDB::Rails::Configuration#series_name_for_exceptions`
|
12
|
+
- Added method, status and format tags to metrics (#50, @ChrisBr)
|
13
|
+
|
14
|
+
### Breaking changes
|
15
|
+
|
16
|
+
- Support for Ruby <= 2.2.x has been removed
|
17
|
+
- Support for Rails <= 4.1.x has been removed
|
18
|
+
- Changed keys for exceptions (#43, @vassilevsky & @kkentzo)
|
19
|
+
- Exception message and backtrace are now InfluxDB values (changed from tags).
|
20
|
+
- The keys changed from `message` to `exception_message` and from
|
21
|
+
`backtrace` to `exception_backtrace`, since a single shard does not
|
22
|
+
allow for tags and values to share the same key
|
23
|
+
- To convert existing exception traces into the new format for
|
24
|
+
consistency, see [this gist][migrate].
|
25
|
+
- Removed `time` key from InfluxDB::Rails::ExceptionPresenter#context`
|
26
|
+
- use `InfluxDB::Rails.current_timestamp` directly
|
27
|
+
- Removed previously deprecated methods:
|
28
|
+
- `InfluxDB::Rails::Configuration#reraise_global_exceptions`
|
29
|
+
- `InfluxDB::Rails::Configuration#database_name`
|
30
|
+
- `InfluxDB::Rails::Configuration#application_id`
|
31
|
+
|
32
|
+
[migrate]: https://gist.github.com/dmke/2d0f4ccf9f43faf82e732dc041e90ca2
|
14
33
|
|
15
34
|
## v0.4.3, released 2017-12-12
|
16
35
|
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
> You are looking at the
|
2
|
-
>
|
3
|
-
>
|
1
|
+
> You are looking at the README for the master branch of this gem.
|
2
|
+
> The latest released version lives in the stable-04 branch,
|
3
|
+
> [see here](https://github.com/influxdata/influxdb-rails/tree/stable-04#readme)
|
4
4
|
> for an online version.
|
5
5
|
|
6
6
|
# influxdb-rails
|
@@ -9,7 +9,7 @@
|
|
9
9
|
[![Build Status](https://travis-ci.org/influxdata/influxdb-rails.svg?branch=master)](https://travis-ci.org/influxdata/influxdb-rails)
|
10
10
|
|
11
11
|
Automatically instrument your Ruby on Rails applications and write the
|
12
|
-
metrics directly into [InfluxDB](
|
12
|
+
metrics directly into [InfluxDB](http://influxdb.org/).
|
13
13
|
|
14
14
|
This gem is designed for Rails 4.0+, Ruby 2.2+ and InfluxDB 0.9+.
|
15
15
|
|
@@ -27,7 +27,7 @@ To get things set up, just create an initializer:
|
|
27
27
|
|
28
28
|
```
|
29
29
|
$ cd /to/you/rails/application
|
30
|
-
$ touch config/initializers/
|
30
|
+
$ touch config/initializers/influxdb_rails.rb
|
31
31
|
```
|
32
32
|
|
33
33
|
In this file, you can configure the `InfluxDB::Rails` adapter. The default
|
@@ -51,9 +51,18 @@ InfluxDB::Rails.configure do |config|
|
|
51
51
|
# config.series_name_for_controller_runtimes = "rails.controller"
|
52
52
|
# config.series_name_for_view_runtimes = "rails.view"
|
53
53
|
# config.series_name_for_db_runtimes = "rails.db"
|
54
|
+
# config.series_name_for_exceptions = "rails.exceptions"
|
55
|
+
# config.series_name_for_instrumentation = "instrumentation"
|
56
|
+
|
57
|
+
# Set the application name to something meaningful, by default we
|
58
|
+
# infer the app name from the Rails.application class name.
|
59
|
+
# config.application_name = Rails.application.class.parent_name
|
54
60
|
end
|
55
61
|
```
|
56
62
|
|
63
|
+
To see all default values, take a look into `InfluxDB::Rails::Configuration::DEFAULTS`,
|
64
|
+
defined in `lib/influxdb/rails/configuration.rb`
|
65
|
+
|
57
66
|
Out of the box, you'll automatically get reporting of your controller,
|
58
67
|
view, and db runtimes for each request. You can also call through to the
|
59
68
|
underlying `InfluxDB::Client` object to write arbitrary data like this:
|
@@ -81,10 +90,6 @@ To work around this limitation, set the `config.time_precision` to one
|
|
81
90
|
of `"ms"` (milliseconds, 1·10<sup>-3</sup>s), `"us"` (microseconds,
|
82
91
|
1·10<sup>-6</sup>s) or `"ns"` (nanoseconds, 1·10<sup>-9</sup>s).
|
83
92
|
|
84
|
-
**Please note:** The default value for the time precision is going to
|
85
|
-
change with version 1.0 of this gem, although the final value is not
|
86
|
-
determined yet.
|
87
|
-
|
88
93
|
[duplicate-points]: https://docs.influxdata.com/influxdb/v1.4/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-duplicate-points
|
89
94
|
|
90
95
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Bundler::GemHelper.install_tasks
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rubocop/rake_task"
|
3
|
+
RuboCop::RakeTask.new
|
5
4
|
|
6
5
|
begin
|
7
6
|
targeted_files = ARGV.drop(1)
|
8
|
-
file_pattern = targeted_files.empty? ?
|
7
|
+
file_pattern = targeted_files.empty? ? "spec/**/*_spec.rb" : targeted_files
|
9
8
|
|
10
|
-
require
|
11
|
-
require
|
9
|
+
require "rspec/core"
|
10
|
+
require "rspec/core/rake_task"
|
12
11
|
|
13
12
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
14
13
|
t.pattern = FileList[file_pattern]
|
@@ -19,7 +18,7 @@ begin
|
|
19
18
|
config.formatter = :documentation
|
20
19
|
end
|
21
20
|
rescue LoadError
|
22
|
-
require
|
21
|
+
require "spec/rake/spectask"
|
23
22
|
|
24
23
|
puts file_pattern
|
25
24
|
|
data/influxdb-rails.gemspec
CHANGED
@@ -1,44 +1,33 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require "influxdb/rails/version"
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
"bug_tracker_uri" => "https://github.com/influxdata/influxdb-rails/issues",
|
16
|
-
"changelog_uri" => "https://github.com/influxdata/influxdb-rails/blob/master/CHANGELOG.md",
|
17
|
-
"documentation_uri" => "https://github.com/influxdata/influxdb-rails/blob/master/README.md",
|
18
|
-
"source_code_uri" => "https://github.com/influxdata/influxdb-rails"
|
19
|
-
}
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "influxdb-rails"
|
7
|
+
spec.version = InfluxDB::Rails::VERSION
|
8
|
+
spec.authors = ["Dominik Menke", "Todd Persen"]
|
9
|
+
spec.email = ["dominik.menke@gmail.com", "todd@influxdb.com"]
|
10
|
+
spec.homepage = "https://influxdata.com"
|
11
|
+
spec.summary = "InfluxDB bindings for Ruby on Rails."
|
12
|
+
spec.description = "This gem automatically instruments your Ruby on Rails" \
|
13
|
+
" 4.2/5.x applications using InfluxDB for storage."
|
14
|
+
spec.licenses = ["MIT"]
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
s.require_paths = ["lib"]
|
16
|
+
spec.files = `git ls-files`.split($/) # rubocop:disable Style/SpecialGlobalVars
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features|smoke)/})
|
18
|
+
spec.require_paths = ["lib"]
|
25
19
|
|
26
|
-
|
27
|
-
s.add_runtime_dependency 'railties', '> 3'
|
20
|
+
spec.required_ruby_version = ">= 2.3.0"
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
s.add_development_dependency 'rake', ['>= 0']
|
32
|
-
s.add_development_dependency 'rdoc', ['>= 0']
|
33
|
-
s.add_development_dependency 'rspec', ['>= 0']
|
34
|
-
s.add_development_dependency 'rspec-rails', ['>= 3.0.0']
|
35
|
-
s.add_development_dependency 'tzinfo', ['>= 0']
|
22
|
+
spec.add_runtime_dependency "influxdb", "~> 0.5.0"
|
23
|
+
spec.add_runtime_dependency "railties", "> 3"
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
25
|
+
spec.add_development_dependency "bundler", ">= 1.0.0"
|
26
|
+
spec.add_development_dependency "fakeweb"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "rdoc"
|
29
|
+
spec.add_development_dependency "rspec"
|
30
|
+
spec.add_development_dependency "rspec-rails", ">= 3.0.0"
|
31
|
+
spec.add_development_dependency "rubocop", "~> 0.60.0"
|
32
|
+
spec.add_development_dependency "tzinfo"
|
44
33
|
end
|
data/lib/influxdb-rails.rb
CHANGED
@@ -2,8 +2,6 @@ require "net/http"
|
|
2
2
|
require "net/https"
|
3
3
|
require "rubygems"
|
4
4
|
require "socket"
|
5
|
-
require "thread"
|
6
|
-
|
7
5
|
require "influxdb/rails/version"
|
8
6
|
require "influxdb/rails/logger"
|
9
7
|
require "influxdb/rails/exception_presenter"
|
@@ -14,6 +12,8 @@ require "influxdb/rails/rack"
|
|
14
12
|
require "influxdb/rails/railtie" if defined?(Rails::Railtie)
|
15
13
|
|
16
14
|
module InfluxDB
|
15
|
+
# InfluxDB::Rails contains the glue code needed to integrate with
|
16
|
+
# InfluxDB and Rails. This is a singleton class.
|
17
17
|
module Rails
|
18
18
|
class << self
|
19
19
|
include InfluxDB::Rails::Logger
|
@@ -21,7 +21,7 @@ module InfluxDB
|
|
21
21
|
attr_writer :configuration
|
22
22
|
attr_writer :client
|
23
23
|
|
24
|
-
def configure(
|
24
|
+
def configure(_silent = false)
|
25
25
|
yield(configuration)
|
26
26
|
|
27
27
|
# if we change configuration, reload the client
|
@@ -30,151 +30,126 @@ module InfluxDB
|
|
30
30
|
InfluxDB::Logging.logger = configuration.logger unless configuration.logger.nil?
|
31
31
|
end
|
32
32
|
|
33
|
+
# rubocop:disable Metrics/MethodLength
|
34
|
+
# rubocop:disable Metrics/AbcSize
|
35
|
+
|
33
36
|
def client
|
34
|
-
@client ||= InfluxDB::Client.new
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
37
|
+
@client ||= InfluxDB::Client.new \
|
38
|
+
database: configuration.influxdb_database,
|
39
|
+
username: configuration.influxdb_username,
|
40
|
+
password: configuration.influxdb_password,
|
41
|
+
hosts: configuration.influxdb_hosts,
|
42
|
+
port: configuration.influxdb_port,
|
43
|
+
async: configuration.async,
|
44
|
+
use_ssl: configuration.use_ssl,
|
45
|
+
retry: configuration.retry,
|
46
|
+
open_timeout: configuration.open_timeout,
|
47
|
+
read_timeout: configuration.read_timeout,
|
48
|
+
max_delay: configuration.max_delay,
|
49
|
+
time_precision: configuration.time_precision
|
46
50
|
end
|
47
51
|
|
52
|
+
# rubocop:enable Metrics/MethodLength
|
53
|
+
# rubocop:enable Metrics/AbcSize
|
54
|
+
|
48
55
|
def configuration
|
49
56
|
@configuration ||= InfluxDB::Rails::Configuration.new
|
50
57
|
end
|
51
58
|
|
52
|
-
def report_exception_unless_ignorable(
|
53
|
-
report_exception(
|
59
|
+
def report_exception_unless_ignorable(ex, env = {})
|
60
|
+
report_exception(ex, env) unless ignorable_exception?(ex)
|
54
61
|
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
log :info, "[InfluxDB::Rails] Something went terribly wrong. Exception failed to take off! #{e.class}: #{e.message}"
|
75
|
-
end
|
62
|
+
alias transmit_unless_ignorable report_exception_unless_ignorable
|
63
|
+
|
64
|
+
# rubocop:disable Metrics/MethodLength
|
65
|
+
# rubocop:disable Metrics/AbcSize
|
66
|
+
|
67
|
+
def report_exception(ex, env = {})
|
68
|
+
timestamp = InfluxDB::Rails.current_timestamp
|
69
|
+
env = influxdb_request_data if env.empty? && defined? influxdb_request_data
|
70
|
+
exception_presenter = ExceptionPresenter.new(ex, env)
|
71
|
+
log :info, "Exception: #{exception_presenter.to_json[0..512]}..."
|
72
|
+
|
73
|
+
client.write_point \
|
74
|
+
configuration.series_name_for_exceptions,
|
75
|
+
values: exception_presenter.values.merge(ts: timestamp),
|
76
|
+
tags: exception_presenter.context.merge(exception_presenter.dimensions),
|
77
|
+
timestamp: timestamp
|
78
|
+
rescue StandardError => ex
|
79
|
+
log :info, "[InfluxDB::Rails] Something went terribly wrong." \
|
80
|
+
" Exception failed to take off! #{ex.class}: #{ex.message}"
|
76
81
|
end
|
77
|
-
|
82
|
+
alias transmit report_exception
|
78
83
|
|
79
|
-
def handle_action_controller_metrics(
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
84
|
+
def handle_action_controller_metrics(_name, start, finish, _id, payload)
|
85
|
+
tags = {
|
86
|
+
method: "#{payload[:controller]}##{payload[:action]}",
|
87
|
+
status: payload[:status],
|
88
|
+
format: payload[:format],
|
89
|
+
http_method: payload[:method],
|
90
|
+
path: payload[:path],
|
91
|
+
server: Socket.gethostname,
|
92
|
+
app_name: configuration.application_name,
|
93
|
+
}.reject { |_, value| value.nil? }
|
94
|
+
|
95
|
+
ts = convert_timestamp(finish.utc)
|
86
96
|
|
87
97
|
begin
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
timestamp: timestamp,
|
97
|
-
}
|
98
|
-
|
99
|
-
client.write_point configuration.series_name_for_view_runtimes, {
|
100
|
-
values: {
|
101
|
-
value: view_runtime,
|
102
|
-
},
|
103
|
-
tags: {
|
104
|
-
method: method,
|
105
|
-
server: hostname,
|
106
|
-
},
|
107
|
-
timestamp: timestamp,
|
108
|
-
}
|
109
|
-
|
110
|
-
client.write_point configuration.series_name_for_db_runtimes, {
|
111
|
-
values: {
|
112
|
-
value: db_runtime,
|
113
|
-
},
|
114
|
-
tags: {
|
115
|
-
method: method,
|
116
|
-
server: hostname,
|
117
|
-
},
|
118
|
-
timestamp: timestamp,
|
119
|
-
}
|
120
|
-
rescue => e
|
98
|
+
{
|
99
|
+
configuration.series_name_for_controller_runtimes => ((finish - start) * 1000).ceil,
|
100
|
+
configuration.series_name_for_view_runtimes => (payload[:view_runtime] || 0).ceil,
|
101
|
+
configuration.series_name_for_db_runtimes => (payload[:db_runtime] || 0).ceil,
|
102
|
+
}.each do |series_name, value|
|
103
|
+
client.write_point series_name, values: { value: value }, tags: tags, timestamp: ts
|
104
|
+
end
|
105
|
+
rescue StandardError => e
|
121
106
|
log :error, "[InfluxDB::Rails] Unable to write points: #{e.message}"
|
122
107
|
end
|
123
108
|
end
|
124
109
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
110
|
+
# rubocop:enable Metrics/MethodLength
|
111
|
+
# rubocop:enable Metrics/AbcSize
|
112
|
+
|
113
|
+
TIMESTAMP_CONVERSIONS = {
|
114
|
+
"ns" => 1e9.to_r,
|
115
|
+
nil => 1e9.to_r,
|
116
|
+
"u" => 1e6.to_r,
|
117
|
+
"ms" => 1e3.to_r,
|
118
|
+
"s" => 1.to_r,
|
119
|
+
"m" => 1.to_r / 60,
|
120
|
+
"h" => 1.to_r / 60 / 60,
|
121
|
+
}.freeze
|
122
|
+
private_constant :TIMESTAMP_CONVERSIONS
|
123
|
+
|
124
|
+
def convert_timestamp(time)
|
125
|
+
conv = TIMESTAMP_CONVERSIONS.fetch(configuration.time_precision) do
|
140
126
|
raise "Invalid time precision: #{configuration.time_precision}"
|
141
127
|
end
|
128
|
+
|
129
|
+
(time.to_r * conv).to_i
|
142
130
|
end
|
143
131
|
|
144
132
|
def current_timestamp
|
145
133
|
convert_timestamp(Time.now.utc)
|
146
134
|
end
|
147
135
|
|
148
|
-
def ignorable_exception?(
|
149
|
-
configuration.ignore_current_environment? ||
|
150
|
-
!!configuration.ignored_exception_messages.find{ |msg| /.*#{msg}.*/ =~ e.message } ||
|
151
|
-
configuration.ignored_exceptions.include?(e.class.to_s)
|
136
|
+
def ignorable_exception?(ex)
|
137
|
+
configuration.ignore_current_environment? || configuration.ignore_exception?(ex)
|
152
138
|
end
|
153
139
|
|
154
|
-
def rescue
|
155
|
-
|
156
|
-
rescue StandardError =>
|
157
|
-
if configuration.ignore_current_environment?
|
158
|
-
raise(e)
|
159
|
-
else
|
160
|
-
transmit_unless_ignorable(e)
|
161
|
-
end
|
162
|
-
end
|
140
|
+
def rescue
|
141
|
+
yield
|
142
|
+
rescue StandardError => ex
|
143
|
+
raise ex if configuration.ignore_current_environment?
|
163
144
|
|
164
|
-
|
165
|
-
block.call
|
166
|
-
rescue StandardError => e
|
167
|
-
transmit_unless_ignorable(e)
|
168
|
-
raise(e)
|
145
|
+
transmit_unless_ignorable(ex)
|
169
146
|
end
|
170
147
|
|
171
|
-
def
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
opts[:to].send(:include, opts[:from].const_get("Old" + module_name))
|
177
|
-
end
|
148
|
+
def rescue_and_reraise
|
149
|
+
yield
|
150
|
+
rescue StandardError => ex
|
151
|
+
transmit_unless_ignorable(ex)
|
152
|
+
raise ex
|
178
153
|
end
|
179
154
|
end
|
180
155
|
end
|