Class: Unleash::MetricsReporter
- Inherits:
-
Object
- Object
- Unleash::MetricsReporter
- Defined in:
- lib/unleash/metrics_reporter.rb
Instance Attribute Summary collapse
-
#last_time ⇒ Object
Returns the value of attribute last_time.
Instance Method Summary collapse
- #generate_report ⇒ Object
-
#initialize ⇒ MetricsReporter
constructor
A new instance of MetricsReporter.
- #send ⇒ Object
Constructor Details
#initialize ⇒ MetricsReporter
Returns a new instance of MetricsReporter.
11 12 13 |
# File 'lib/unleash/metrics_reporter.rb', line 11 def initialize self.last_time = Time.now end |
Instance Attribute Details
#last_time ⇒ Object
Returns the value of attribute last_time.
9 10 11 |
# File 'lib/unleash/metrics_reporter.rb', line 9 def last_time @last_time end |
Instance Method Details
#generate_report ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/unleash/metrics_reporter.rb', line 15 def generate_report now = Time.now start = self.last_time stop = now self.last_time = now report = { 'appName': Unleash.configuration.app_name, 'instanceId': Unleash.configuration.instance_id, 'bucket': { 'start': start.iso8601(Unleash::TIME_RESOLUTION), 'stop': stop.iso8601(Unleash::TIME_RESOLUTION), 'toggles': Unleash.toggle_metrics.features } } Unleash.toggle_metrics.reset report end |
#send ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/unleash/metrics_reporter.rb', line 36 def send Unleash.logger.debug "send() Report" response = Unleash::Util::Http.post(Unleash.configuration.client_metrics_url, self.generate_report.to_json) if ['200', '202'].include? response.code Unleash.logger.debug "Report sent to unleash server sucessfully. Server responded with http code #{response.code}" else Unleash.logger.error "Error when sending report to unleash server. Server responded with http code #{response.code}." end end |