0.0
The project is in a healthy, maintained state
Trifle::Stats is a way too simple timeline analytics that helps you track custom metrics. Automatically increments counters for each enabled range. It supports timezones and different week beginning.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Development

~> 2.1
>= 0
>= 0
~> 13.0
~> 3.2
= 1.0.0
>= 2.14.0
>= 1.2
>= 4.2

Runtime

~> 2.0
 Project Readme

Trifle::Stats

Gem Version Ruby Gitpod ready-to-code

Simple analytics backed by Redis, Postgres, MongoDB, Google Analytics, Segment, or whatever. 1

Trifle::Stats is a way too simple timeline analytics that helps you track custom metrics. Automatically increments counters for each enabled range. It supports timezones and different week beginning.

Documentation

You can find guides and documentation at https://trifle.io/docs/stats

Installation

Add this line to your application's Gemfile:

gem 'trifle-stats'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install trifle-stats

Usage

You don't need to use it with Rails, but you still need to run Trifle::Stats.configure. If youre running it with Rails, create config/initializers/trifle-stats.rb and configure the gem.

Trifle::Stats.configure do |config|
  config.driver = Trifle::Stats::Driver::Redis.new
  config.track_ranges = [:hour, :day]
  config.time_zone = 'Europe/Bratislava'
  config.beginning_of_week = :monday
end

Track values

Available ranges are :minute, :hour, :day, :week, :month, :quarter, :year.

Now track your first metrics

Trifle::Stats.track(key: 'event::logs', at: Time.now, values: {count: 1, duration: 2, lines: 241})
=> [{2021-01-25 16:00:00 +0100=>{:count=>1, :duration=>2, :lines=>241}}, {2021-01-25 00:00:00 +0100=>{:count=>1, :duration=>2, :lines=>241}}]
# or do it few more times
Trifle::Stats.track(key: 'event::logs', at: Time.now, values: {count: 1, duration: 1, lines: 56})
=> [{2021-01-25 16:00:00 +0100=>{:count=>1, :duration=>1, :lines=>56}}, {2021-01-25 00:00:00 +0100=>{:count=>1, :duration=>1, :lines=>56}}]
Trifle::Stats.track(key: 'event::logs', at: Time.now, values: {count: 1, duration: 5, lines: 361})
=> [{2021-01-25 16:00:00 +0100=>{:count=>1, :duration=>5, :lines=>361}}, {2021-01-25 00:00:00 +0100=>{:count=>1, :duration=>5, :lines=>361}}]

Get values

Retrieve your values for specific range.

Trifle::Stats.values(key: 'event::logs', from: Time.now, to: Time.now, range: :day)
=> [{2021-01-25 00:00:00 +0100=>{"count"=>3, "duration"=>8, "lines"=>658}}]

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/trifle-io/trifle-stats.

Footnotes

  1. TBH only Redis for now 💔. ↩