Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A ruby gem for basic stats collection and reporting.
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
.simplecov
.travis.yml
.yardopts
CHANGELOG.md
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
abaci.gemspec

README.md

Abaci

Build Status Dependency Status

Abaci (pronounced abba-sigh) is a simple structure for the collection and reporting on numerical counters. Counters can be used to track time-based statistics for a wide array of functions within your application. Abaci uses a Redis backend to store all counters for lightning quick read and write access.

What does abaci mean? Its the plural form of Abacus, a common arithmetic assistance device from before we had computers. Imagine that.

Requirements

  • Ruby 1.9.2+
  • Redis

Configuration

Abaci will use the default Redis instance by default, assumed to be available via Redis.current. To use with a specific Redis instance, pass a Redis object to Abaci.options[:redis]. You can use it this way with Redis Namespace if necessary.

By default, the prefix ab is used before all stats stored in Redis. If you are using running multiple apps using the same Redis instance (likely in development mode), you can change the prefix by setting Abaci.options[:prefix].

Here's a sample configuration that we use often:

connection = Redis.new
REDIS = Redis::Namespace.new(:ns, :redis => connection)

Abaci.options[:redis] = REDIS
Abaci.options[:prefix] = 'stats'

If you are using Rails, put that in an initializer and you're good to go.

Basic Usage

# Log page views
Abaci['views'].increment # => 1
Abaci['views'].increment # => 2

# Increment (and decrement) all take a parameter or default to incrementing by 1
Abaci['views'].increment(3) # => 5

# Decrementing is available if needed
Abaci['views'].decrement # => 4

# Get total number of views
Abaci['views'].get # => 4

# Get total number of views in year 2012
Abaci['views'].get(2012) # => 4

# Get total number of views in October of 2012
Abaci['views'].get(2012, 10) # => 4

# Get total number of views on October 20, 2012
Abaci['views'].get(2012, 10, 20) # => 4

# Get total views in the last 30 days
Abaci['views'].get_last_days(30) # => 4

# View all counter stat keys stored
Abaci['views'].keys

# Clear counters for views
Abaci['views'].del

Issues

If you have any issues or find bugs running Abaci, please report them on Github. While most functions should be stable, Abaci is still in its infancy and certain issues may be present.

License

Abaci is released under the MIT license

Contributions and pull-requests are more than welcome.

Something went wrong with that request. Please try again.