Class: RedCross::Trackers::MonitorTracker
- Defined in:
- lib/red_cross/trackers/monitor_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 = 'test', host = 'localhost', port = 8086, write_timeout = 0.05, read_timeout = 0.05, logger = false, async = true) ⇒ MonitorTracker
constructor
A new instance of MonitorTracker.
- #monitor_request(attrs) ⇒ Object
- #track(attrs, additional_args = {}) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(database = 'test', host = 'localhost', port = 8086, write_timeout = 0.05, read_timeout = 0.05, logger = false, async = true) ⇒ MonitorTracker
Returns a new instance of MonitorTracker.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 6 def initialize(database = 'test', host = 'localhost', port = 8086, write_timeout = 0.05, read_timeout = 0.05, logger = false, async = true) InfluxDB::Logging.logger = logger = async if == true = { num_worker_threads: 1 } end @client = InfluxDB::Client.new database, host: host, port: port, async: , retry: false, write_timeout: write_timeout.to_f, read_timeout: read_timeout.to_f end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 4 def client @client end |
Instance Method Details
#compact(hash) ⇒ Object
67 68 69 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 67 def compact(hash) hash.respond_to?(:compact) ? hash.compact : hash.delete_if {|k,v| v == nil } end |
#flush ⇒ Object
33 34 35 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 33 def flush {} end |
#group(attrs, additional_args = {}) ⇒ Object
37 38 39 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 37 def group(attrs, additional_args = {}) {} end |
#identify(attrs, additional_args = {}) ⇒ Object
29 30 31 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 29 def identify(attrs, additional_args = {}) {} end |
#monitor_request(attrs) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 41 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) }) client.writer.worker.stop! 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
25 26 27 |
# File 'lib/red_cross/trackers/monitor_tracker.rb', line 25 def track(attrs, additional_args = {}) monitor_request(attrs.merge(additional_args)) end |