Module: InfluxDB::Rails
- Extended by:
- Logger
- Defined in:
- lib/influxdb-rails.rb,
lib/influxdb/rails/rack.rb,
lib/influxdb/rails/logger.rb,
lib/influxdb/rails/railtie.rb,
lib/influxdb/rails/version.rb,
lib/influxdb/rails/backtrace.rb,
lib/influxdb/rails/configuration.rb,
lib/influxdb/rails/instrumentation.rb,
lib/influxdb/rails/exception_presenter.rb,
lib/influxdb/rails/air_traffic_controller.rb,
lib/influxdb/rails/middleware/hijack_render_exception.rb,
lib/influxdb/rails/middleware/hijack_rescue_action_everywhere.rb
Defined Under Namespace
Modules: AirTrafficController, Instrumentation, Logger, Middleware
Classes: Backtrace, Configuration, ExceptionPresenter, Rack, Railtie
Constant Summary
collapse
- VERSION =
"0.1.10"
Constants included
from Logger
Logger::PREFIX
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.client ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/influxdb-rails.rb', line 33
def client
@client ||= InfluxDB::Client.new configuration.influxdb_database,
:username => configuration.influxdb_username,
:password => configuration.influxdb_password,
:hosts => configuration.influxdb_hosts,
:port => configuration.influxdb_port,
:async => configuration.async,
:use_ssl => configuration.use_ssl
end
|
Class Method Details
24
25
26
27
28
29
30
31
|
# File 'lib/influxdb-rails.rb', line 24
def configure(silent = false)
yield(configuration)
self.client = nil
InfluxDB::Logging.logger = configuration.logger unless configuration.logger.nil?
end
|
.current_timestamp ⇒ Object
89
90
91
|
# File 'lib/influxdb-rails.rb', line 89
def current_timestamp
Time.now.utc.to_i
end
|
.handle_action_controller_metrics(name, start, finish, id, payload) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/influxdb-rails.rb', line 67
def handle_action_controller_metrics(name, start, finish, id, payload)
timestamp = finish.utc.to_i
controller_runtime = ((finish - start)*1000).ceil
view_runtime = (payload[:view_runtime] || 0).ceil
db_runtime = (payload[:db_runtime] || 0).ceil
method = "#{payload[:controller]}##{payload[:action]}"
hostname = Socket.gethostname
begin
client.write_point configuration.series_name_for_controller_runtimes,
:value => controller_runtime, :method => method, :server => hostname
client.write_point configuration.series_name_for_view_runtimes,
:value => view_runtime, :method => method, :server => hostname
client.write_point configuration.series_name_for_db_runtimes,
:value => db_runtime, :method => method, :server => hostname
rescue => e
log :error, "[InfluxDB::Rails] Unable to write points: #{e.message}"
end
end
|
.ignorable_exception?(e) ⇒ Boolean
93
94
95
96
97
|
# File 'lib/influxdb-rails.rb', line 93
def ignorable_exception?(e)
configuration.ignore_current_environment? ||
!!configuration.ignored_exception_messages.find{ |msg| /.*#{msg}.*/ =~ e.message } ||
configuration.ignored_exceptions.include?(e.class.to_s)
end
|
.report_exception(e, env = {}) ⇒ Object
Also known as:
transmit
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/influxdb-rails.rb', line 52
def report_exception(e, env = {})
begin
env = influxdb_request_data if env.empty? && defined? influxdb_request_data
exception_presenter = ExceptionPresenter.new(e, env)
log :info, "Exception: #{exception_presenter.to_json[0..512]}..."
client.write_point "rails.exceptions",
exception_presenter.context.merge(exception_presenter.dimensions)
rescue => e
log :info, "[InfluxDB::Rails] Something went terribly wrong. Exception failed to take off! #{e.class}: #{e.message}"
end
end
|
.report_exception_unless_ignorable(e, env = {}) ⇒ Object
Also known as:
transmit_unless_ignorable
47
48
49
|
# File 'lib/influxdb-rails.rb', line 47
def report_exception_unless_ignorable(e, env = {})
report_exception(e, env) unless ignorable_exception?(e)
end
|
.rescue(&block) ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/influxdb-rails.rb', line 99
def rescue(&block)
block.call
rescue StandardError => e
if configuration.ignore_current_environment?
raise(e)
else
transmit_unless_ignorable(e)
end
end
|
.rescue_and_reraise(&block) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/influxdb-rails.rb', line 109
def rescue_and_reraise(&block)
block.call
rescue StandardError => e
transmit_unless_ignorable(e)
raise(e)
end
|