Module: Litemetric::Measurable
- Included in:
- Litecable, Litecache, Litedb, Litedb::Statement, Litejobqueue
- Defined in:
- lib/litestack/litemetric.rb
Instance Method Summary collapse
- #capture(event, key = event, value = nil) ⇒ Object
- #capture_snapshot ⇒ Object
- #collect_metrics ⇒ Object
- #create_snapshotter ⇒ Object
- #measure(event, key = event) ⇒ Object
- #metrics_identifier ⇒ Object
Instance Method Details
#capture(event, key = event, value = nil) ⇒ Object
217 218 219 220 |
# File 'lib/litestack/litemetric.rb', line 217 def capture(event, key = event, value = nil) return unless @litemetric @litemetric.capture(metrics_identifier, event, key, value) end |
#capture_snapshot ⇒ Object
235 236 237 238 239 240 241 |
# File 'lib/litestack/litemetric.rb', line 235 def capture_snapshot return unless @litemetric state = snapshot if defined? snapshot if state @litemetric.capture_snapshot(metrics_identifier, state) end end |
#collect_metrics ⇒ Object
198 199 200 201 202 |
# File 'lib/litestack/litemetric.rb', line 198 def collect_metrics @litemetric = Litemetric.instance @litemetric.register(metrics_identifier) @snapshotter = create_snapshotter end |
#create_snapshotter ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/litestack/litemetric.rb', line 204 def create_snapshotter Litescheduler.spawn do while @running capture_snapshot sleep @litemetric.[:snapshot_interval] end end end |
#measure(event, key = event) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/litestack/litemetric.rb', line 222 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_identifier ⇒ Object
213 214 215 |
# File 'lib/litestack/litemetric.rb', line 213 def metrics_identifier self.class.name # override in included classes end |