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.
264
265
266
|
# File 'lib/litestack/litemetric.rb', line 264
def initialize(options = {})
init(options)
end
|
Instance Method Details
#capture(topic, event, key, value = nil, time = nil) ⇒ Object
268
269
270
271
272
273
274
|
# File 'lib/litestack/litemetric.rb', line 268
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
276
277
278
|
# File 'lib/litestack/litemetric.rb', line 276
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
280
281
282
|
# File 'lib/litestack/litemetric.rb', line 280
def count
run_stmt(:event_count)[0][0]
end
|
#create_connection ⇒ Object
299
300
301
302
303
304
|
# File 'lib/litestack/litemetric.rb', line 299
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/litestack/litemetric.rb', line 284
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
|