Library for measurement of resource consumption
Add it to your Gemfile
:
gem 'consumption-meter'
Run the following command to install it:
$ bundle install
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}
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
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