14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/stackify/metrics/metrics_sender.rb', line 14
def upload_metrics aggr_metrics
return true if aggr_metrics.nil? || aggr_metrics.length == 0
current_time = Stackify::Utils.rounded_current_time
device_id = Stackify::EnvDetails.instance.auth_info['DeviceID']
if Stackify.authorized?
records = []
aggr_metrics.each_pair do |_key, metric|
next if metric.sent || metric.occurred_utc.to_i >= current_time.to_i
record = Stackify::Metrics::MetricForSubmit.new(metric).to_h
record['ClientDeviceID'] = device_id if !device_id.nil?
records << record
metric.sent = true
end
if records.any?
Stackify.internal_log :debug, "Uploading Aggregate Metrics at #{ Time.now }: \n" + JSON.pretty_generate(records)
response = send_request SUBMIT_METRIS_URI, records.to_json
Stackify.internal_log :info, 'Metrics are uploaded successfully' if response.try(:status) == 200
end
else
Stackify.log_internal_error "Uploading of metrics is failed because of authorization failure"
end
end
|