Link Search Menu Expand Document


Because sometimes you just wanna throw some stats in the current process.

This is simple global Hash variable on a process. Grows over time. No expiration. Use with caution.


Trifle::Stats.configure do |config|
  config.driver =


This is simple driver that stores data within itself. No configuration is necessary. You can initialize one driver and share it throughout your app, or let each thread has its own driver.

irb(main):001:0> driver =
=> #<Trifle::Stats::Driver::Process:0x00007fb6e30ba080 @data={}, @separator="::">


Once you create instance of a driver, you can use it to set, inc or get your data.

irb(main):002:0> driver.get(key: ['test', 'now'])
=> {}

irb(main):003:0> ['test', 'now'], count: 1, success: 1, error: 0)
=> {"count"=>1, "success"=>1, "error"=>0}
irb(main):004:0> driver.get(key: ['test', 'now'])
=> {"count"=>1, "success"=>1, "error"=>0}

irb(main):005:0> ['test', 'now'], count: 1, success: 0, error: 1, account: { count: 1 })
=> {"count"=>1, "success"=>0, "error"=>1, "account.count"=>1}
irb(main):006:0> driver.get(key: ['test', 'now'])
=> {"count"=>2, "success"=>1, "error"=>1, "account"=>{"count"=>1}}


You can see data being stored on the driver object itself. Keep that on mind if you are storing lots of data in memory.

irb(main):007:0> driver
=> #<Trifle::Stats::Driver::Process:0x00007fb6e30ba080 @data={"test::now"=>{"count"=>2, "success"=>1, "error"=>1, "account.count"=>1}}, @separator="::">