Module: Litemetric::Measurable

Included in:
Litecable, Litecache, Litedb, Litedb::Statement, Litejobqueue
Defined in:
lib/litestack/litemetric.rb

Instance Method Summary collapse

Instance Method Details

#capture(event, key = event, value = nil) ⇒ Object



216
217
218
219
# File 'lib/litestack/litemetric.rb', line 216

def capture(event, key = event, value = nil)
  return unless @litemetric
  @litemetric.capture(metrics_identifier, event, key, value)
end

#capture_snapshotObject



234
235
236
237
238
239
240
# File 'lib/litestack/litemetric.rb', line 234

def capture_snapshot
  return unless @litemetric
  state = snapshot if defined? snapshot
  if state
    @litemetric.capture_snapshot(metrics_identifier, state)
  end
end

#collect_metricsObject



197
198
199
200
201
# File 'lib/litestack/litemetric.rb', line 197

def collect_metrics
  @litemetric = Litemetric.instance
  @litemetric.register(metrics_identifier)
  @snapshotter = create_snapshotter
end

#create_snapshotterObject



203
204
205
206
207
208
209
210
# File 'lib/litestack/litemetric.rb', line 203

def create_snapshotter
  Litescheduler.spawn do
    while @running
      sleep @litemetric.options[:snapshot_interval]
      capture_snapshot
    end
  end
end

#measure(event, key = event) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/litestack/litemetric.rb', line 221

def measure(event, key = event)
  unless @litemetric
    yield
    return 0
  end
  t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  yield
  t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  value = t2 - t1
  capture(event, key, value)
  value # return value so other events can reuse it
end

#metrics_identifierObject



212
213
214
# File 'lib/litestack/litemetric.rb', line 212

def metrics_identifier
  self.class.name # override in included classes
end