Giter VIP home page Giter VIP logo

von's Introduction

Von Build Status

Von is an opinionated Redis stats tracker. It works with keys, you choose one, Von increments it. It has a few built in conveniences:

Requirements

Von uses Redis for storing counters so you'll need it get going. If you're on OS X you can use homebrew:

$ brew install redis

Auto Incrementing Parent Keys

Keys are namespaced and every parent key is incremented when you increment a child key, for example:

Von.increment('downloads')          # bumps the 'downloads' key 1 time
Von.increment('downloads:app123')   # bumps the 'downloads:app123' key 1 time AND the 'downloads' key 1 time

Tracking Time Periods

By default Von will only bump a "total" counter for the given key. This is great, but what makes Von really useful is that it can be configured to group certain keys by hour, day, week, month, and year. And you can set limits on how many of each you want to keep around. Here's how it works:

Configuring Time Periods

Von.configure do |config|
    # Keep daily stats for 30 days
    config.counter 'downloads', daily: 30

    # Keep monthly stats for 3 months and yearly stats for 2 years
    config.counter 'uploads', monthly: 3, yearly: 2
end

Tracking the Current Time Period

If just wanna track stats on the current minute/hour/day/week/etc, you can set that up pretty easily with Von:

Von.configure do |config|
    # Track downloads stats for the current hour
    config.counter 'downloads', current: :hour

    # Track page views for the current day and week
    config.counter 'page-views', current: [ :day, :week ]
end

Tracking "Bests"

Time periods are pretty cool, but sometimes you wanna know when you did your best. You can track these with Von as well:

Von.configure do |config|
    # Track the best day for downloads
    config.counter 'downloads', best: :day

    # Track the best hour and week for page views
    config.counter 'page-views', best: [ :hour, :week ]
end

Incrementing

Once you've configured the keys you don't have to do anything special, just increment the key, Von will handle this rest.

Von.increment('downloads')
Von.increment('uploads')
Von.increment('page-views')

Getting Stats

# get the total downloads (returns an Integer)
Von.count('downloads').total       #=> 4

# get the monthly counts (returns an Array of Hashes)
Von.count('uploads').per(:month)   #=> [ { timestamp: '2012-03', count: 3 }, { timestamp: '2013-04', count: 1 }, { timestamp: '2013-05', count: 0 }]

# get the download stats for the hour
Von.count('downloads').this(:hour)          #=> 10
# or
Von.count('downloads').current(:hour)       #=> 10

# get the page-views for today
Von.count('page-views').today               #=> 78
Von.count('page-views').current(:day)       #=> 78

# get the best day for downloads (returns a Hash)
Von.count('downloads').best(:day)  #=> { timestamp: '2012-03-01', count: 10 }

One nice thing to note, if you're counting a time period and there wasn't a value stored for the particular hour/day/week/etc, it'll be populated with a zero, this ensures that if you want 30 days of stats, you get 30 days of stats.

Configuration

There are a few things you might want to configure in Von, you can do this in the configure block where you would also set time periods and expirations.

Von.configure do |config|
    # set the Redis connection to an already existing connection
    config.redis = Redis.current
    # Initialize a new Redis connection given options
    config.redis = { host: 'localhost', port: 6379 }
    
    # rescue Redis connection errors
    # if the connection fails, no errors are raised by default
    config.raise_connection_errors = false

    # set the top level Redis key namespace
    config.namespace = 'von'

    # set the various formatting for time periods (defaults shown)
    config.yearly_format  = '%Y'
    config.monthly_format = '%Y-%m'
    config.weekly_format  = '%Y-%m-%d'
    config.daily_format   = '%Y-%m-%d'
    config.hourly_format  = '%Y-%m-%d %H:00'
end

Installation

Add this line to your application's Gemfile:

gem 'von'

And then execute:

$ bundle

Or install it yourself as:

$ gem install von

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

von's People

Contributors

trvsdnn avatar teeparham avatar thegrubbsian avatar jakubkosinski avatar

Stargazers

The Tiến avatar  清玩 avatar m.b. avatar Noah Pryor avatar Angus H. avatar Sam McGrail avatar Javier Honduvilla Coto avatar Przemyslaw Mroczek avatar Randy Girard avatar  avatar Mac Młynarczyk avatar Dmitry Shmalko avatar ᴘɪᴇʀᴄᴇ ᴍᴏᴏʀᴇ™ avatar Thibaut LE LEVIER avatar Roberto Arce avatar John Barker avatar Boris Bügling avatar Stefan Stüben avatar Tiago Portela avatar Harold Figueroa avatar Jan Filipowski avatar Raquel Hernandez avatar Hemant Kumar Singh avatar sincospi avatar Dmitriy Plekhanov avatar Jonathan Gomez avatar Amir Mamedov avatar Bruno Bonamin avatar Steve Thomas avatar Florian Dütsch avatar Chris McKnight avatar Andrea Campolonghi avatar Vicente Reig avatar  avatar Jim Neath avatar Aleks avatar Râu Cao avatar Joshua Warchol avatar Arsen Gasparyan avatar Reinaldo Oliveira avatar  avatar Matt Hooks avatar Grant Walker avatar S avatar Steve Hoeksema avatar Justin Aiken avatar Marcus Wood avatar Danil Pismenny avatar Julien Ammous avatar Jonathan Markwell avatar Sven Riedel avatar Devdatta Kane avatar Pablo Alvarez de Sotomayor Posadillo avatar BC Broussard avatar Michael Peteuil avatar Titov Andrey avatar  avatar David Cornu avatar Martin Tithonium avatar Emil Soman avatar SeHoon Park avatar Truong Hoang Dung avatar Yury Lebedev avatar  avatar Josiah Roe avatar Thomas Klemm avatar Denys Slipetskyy avatar Stepan Tubanov avatar Sebastian Maier avatar Boris Staal avatar Phillip Reichelt avatar Greg Reinacker avatar Lisovskii Vladislav avatar Vasil Nesterov avatar Mattias  avatar Daniel Hadley avatar Ramil Badretdinov avatar Alexey Plutalov avatar Miguel Guinada avatar Kenneth Geerts avatar Mikhail Nikalyukin avatar zach zhao avatar Blake Jakopovic avatar  avatar Alexander Paramonov avatar Jesper Kjeldgaard avatar Maxime Garcia avatar John McDowall avatar JP Boily avatar Dan Lee avatar Utkarsh Kukreti avatar Florian Bertholin avatar Jacques Crocker avatar Andrew Kozlov avatar Dylan Fareed avatar Tristan avatar Radosław Woźniak avatar Roberto Barros avatar Sai Ram Kunala avatar elvuel avatar

Watchers

Avishai Weiss avatar Pablo Cordero avatar Josiah Roe avatar

von's Issues

Add unique counters

I would be really nice to have unique counters using redis bitsets - it may be used to calculate e.g. daily/weekly/monthly active users.

You can find nice article describing this feature on Spool blog.

add counters for "bests"

Allow tracking of best days/weeks/months/years.

Maybe something like:

# setup the counter
Von.configure do |config|
  config.counter 'signups', :best => :day
end

# get the count
Von.count('signups', :best => :day)
# or
Von.count('signups', :best_day)

configuring a dynamic key?

The following allows me to run use the 'current' method for the key "zone_id":

Von.configure do |config|
  config.counter 'zone_id', current: [ :day, :week, :month, :year ]
end

However, if I have a key that's based on a unique ID (zone_id:xxx), is there a way to configure Von to provide 'current' counts for all keys matching zone_id:* ?

add counters for today

Would be useful to track stats for just today (instead of tracking daily and pulling the most recent entry).

add counters for average

Not 100% sure how this would look, but it would be nice to have an average: "we average x signups per hour/day/etc"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.