Class: RedCross::Trackers::ApplicationTracker
- Defined in:
- lib/red_cross/trackers/application_tracker.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #compact(hash) ⇒ Object
- #flush ⇒ Object
- #group(attrs, additional_args = {}) ⇒ Object
- #identify(attrs, additional_args = {}) ⇒ Object
-
#initialize(database = 'application_metrics', host, port) ⇒ ApplicationTracker
constructor
A new instance of ApplicationTracker.
- #monitor_request(attrs) ⇒ Object
- #track(attrs, additional_args = {}) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(database = 'application_metrics', host, port) ⇒ ApplicationTracker
Returns a new instance of ApplicationTracker.
12 13 14 15 16 17 18 19 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 12 def initialize(database = 'application_metrics', host, port) @client = InfluxDB::Client.new udp: { host: host, port: port, }, discard_write_errors: true, database: database end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 10 def client @client end |
Instance Method Details
#compact(hash) ⇒ Object
62 63 64 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 62 def compact(hash) hash.respond_to?(:compact) ? hash.compact : hash.delete_if {|k,v| v == nil } end |
#flush ⇒ Object
29 30 31 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 29 def flush {} end |
#group(attrs, additional_args = {}) ⇒ Object
33 34 35 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 33 def group(attrs, additional_args = {}) {} end |
#identify(attrs, additional_args = {}) ⇒ Object
25 26 27 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 25 def identify(attrs, additional_args = {}) {} end |
#monitor_request(attrs) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 37 def monitor_request(attrs) return if client.nil? event = attrs[:event].to_s properties = attrs[:properties] || {} values = { count: 1 }.merge((properties.delete(:fields) || {})) begin client.write_point(event, { values: compact(values), tags: compact(properties) }) rescue => e error_data = { log_message: 'Failed to send monitor data to InfluxDB', event_arguments: { event: event, tags: properties, fields: values }, exception: { class: e.class.to_s, message: e., backtrace: e.backtrace } } log :error, error_data end end |
#track(attrs, additional_args = {}) ⇒ Object
21 22 23 |
# File 'lib/red_cross/trackers/application_tracker.rb', line 21 def track(attrs, additional_args = {}) monitor_request(attrs.merge(additional_args)) end |