brunoporto / consumption-meter

Library for measurement of resource consumption

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consumption Meter

Library for measurement of resource consumption

How to install

Add it to your Gemfile:

gem 'consumption-meter'

Run the following command to install it:

$ bundle install

How to use

Include ConsumptionMeter inside Model you need to measure:

class MyModel
    include ConsumptionMeter
end

Then call measure method:

# @params unit, price_per_unit, field, filter={}
MyModel.measure :size, 10, :file_size, {account_id: account.id}

Measures Units

Size

meter = MyModel.measure :size, 10, :file_size, {account_id: account.id}
# Sum file_size = 2179.0

# PRICE PER UNIT (:B, :KB, :MB, :GB)
meter.price :KB
#> 21.279296875

# SIZE IN UNIT (:B, :KB, :MB, :GB)
meter.size :KB
#> 2.1279296875

Quantity

SUM

meter = MyModel.measure :quantity, 10, :qty, {account_id: account.id}
# Sum qty = 45.5

# TOTAL PRICE
meter.price
#> 455.0

# TOTAL SIZE
meter.size
#> 45.5

COUNT

meter = MyModel.measure :quantity, 10, nil, {account_id: account.id}
# Count Records = 5.0

# TOTAL PRICE
meter.price
#> 50.0

# TOTAL SIZE
meter.size
#> 5.0

About

Library for measurement of resource consumption

License:MIT License


Languages

Language:Ruby 83.8%Language:HTML 12.1%Language:JavaScript 2.5%Language:CSS 1.6%