Class: Litemetric::Collector
Constant Summary
collapse
- DEFAULT_OPTIONS =
{
path: ":memory:",
sync: 1,
flush_interval: 3, summarize_interval: 10, snapshot_interval: 1 }
- RESOLUTIONS =
{
minute: 300, hour: 3600, day: 24 * 3600, week: 7 * 24 * 3600 }
Instance Method Summary
collapse
#close, #journal_mode, #options, #path, #size, #synchronous
#_fork
Constructor Details
#initialize(options = {}) ⇒ Collector
Returns a new instance of Collector.
263
264
265
|
# File 'lib/litestack/litemetric.rb', line 263
def initialize(options = {})
init(options)
end
|
Instance Method Details
#capture(topic, event, key, value = nil, time = nil) ⇒ Object
267
268
269
270
271
272
273
|
# File 'lib/litestack/litemetric.rb', line 267
def capture(topic, event, key, value = nil, time = nil)
if key.is_a? Array
key.each { |k| capture_single_key(topic, event, k, value, time) }
else
capture_single_key(topic, event, key, value, time)
end
end
|
#capture_single_key(topic, event, key, value, time = nil) ⇒ Object
275
276
277
|
# File 'lib/litestack/litemetric.rb', line 275
def capture_single_key(topic, event, key, value, time = nil)
run_stmt(:capture_event, topic.to_s, event.to_s, key.to_s, time, 1, value)
end
|
#count ⇒ Object
279
280
281
|
# File 'lib/litestack/litemetric.rb', line 279
def count
run_stmt(:event_count)[0][0]
end
|
#create_connection ⇒ Object
298
299
300
301
302
303
|
# File 'lib/litestack/litemetric.rb', line 298
def create_connection
super("#{__dir__}/litemetric_collector.sql.yml") do |conn|
conn.execute("ATTACH ? as m", @options[:dbpath].to_s)
conn.wal_autocheckpoint = 10000
end
end
|
#flush ⇒ Object
283
284
285
286
287
288
289
290
291
292
293
294
295
296
|
# File 'lib/litestack/litemetric.rb', line 283
def flush
limit = 1000 count = run_stmt(:event_count)[0][0]
while count > 0
@conn.acquire do |conn|
conn.transaction(:immediate) do
conn.stmts[:migrate_events].execute!(limit)
conn.stmts[:delete_migrated_events].execute!(limit)
count = conn.stmts[:event_count].execute![0][0]
end
end
sleep 0.005 end
end
|