Class: HeimdallApm::Vault

Inherits:
Object
  • Object
show all
Defined in:
lib/heimdall_apm/vault.rb

Overview

Keeps in RAM one or more minute’s worth of metrics. When informed to by the background thread, it pushes the in-RAM metrics off to InfluxDB.

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Vault

Returns a new instance of Vault.



9
10
11
12
13
# File 'lib/heimdall_apm/vault.rb', line 9

def initialize(context)
  @context  = context
  @lock     = Mutex.new
  @spans    = Hash.new { |h, k| h[k] = Span.new(k, @context) }
end

Instance Method Details

#current_spanObject



15
16
17
# File 'lib/heimdall_apm/vault.rb', line 15

def current_span
  @spans[current_timestamp]
end

#current_timestampObject



28
29
30
31
# File 'lib/heimdall_apm/vault.rb', line 28

def current_timestamp
  time = Time.now.utc
  time.to_i - time.sec
end

#retrieve_and_delete_previous_spanObject



19
20
21
22
# File 'lib/heimdall_apm/vault.rb', line 19

def retrieve_and_delete_previous_span
  timestamp = current_timestamp - 60
  @lock.synchronize { @spans.delete(timestamp) }
end

#store_transaction_metrics(txn, metrics) ⇒ Object



24
25
26
# File 'lib/heimdall_apm/vault.rb', line 24

def store_transaction_metrics(txn, metrics)
  @lock.synchronize { current_span.add_point(txn, metrics) }
end