BellyWash

BellyWash ~ way too simple analytics backed by Redis, Postgres, MongoDB, Google Analytics, Segment, or whatever*.

BellyWash is a simple timeline analytics plugin that helps you track custom metrics. Automatically increments counters for each enabled range. It supports timezones and different week beginning.

  • TBH only Redis for now </3

Installation

Add this line to your application's Gemfile:

gem 'belly_wash'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install belly_wash

Usage

You don't need to use it with Rails, but you still need to run BellyWash.configure. If youre running it with Rails, create config/initializers/belly_wash.rb and configure the gem.

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

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

Now track your first metrics

BellyWash.track(key: 'event::logs', at: Time.zone.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
BellyWash.track(key: 'event::logs', at: Time.zone.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}}]
BellyWash.track(key: 'event::logs', at: Time.zone.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}}]

You can then retrieve your values for specific range.

BellyWash.values_for(key: 'event::logs', from: Time.now.beginning_of_day, to: Time.now.end_of_day, range: :hour)
=> [{2021-01-25 00:00:00 +0100=>{"count"=>3, "duration"=>8, "lines"=>658}}]

You can also store nested counters like

BellyWash.track(key: 'event::logs', at: Time.zone.now, values: {
  count: 1,
  duration: {
    parsing: 21,
    compression: 8,
    upload: 1
  },
  lines: 25432754
})

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/jozefvaclavik/belly_wash.