Created by Maciej Mensfeld / @maciejmensfeld / mensfeld.pl
It depends ;)
There are no universal solutions
around_filter :method do |task|
benchmark(task.name) do
task.process
end
end
def benchmark(task_name)
t = Time.now
result = yield
# Mongoid simple object
Usage.create!(
task_name: task_name,
time_taken: (t.to_f - Time.now.to_f)*1000
)
end
He probably doesn't care ;)
Heka is an open source stream processing software system developed by Mozilla. Heka is a “Swiss Army Knife” type tool for data processing
In computing, AOP is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.
There are many AOP libraries for Ruby. We use Aspector
With AOP we can create concerns that we can attach to any method of any class as a before, around and after action.
class Handler < BaseHandler
def handle
# Sends a UDP packet about method usage
Usage.increment(key)
end
before options[:method], aspect_arg: true do |aspect|
aspect.handle
end
end
# Counter for Sinatra app requests
Handler.apply(App, method: :call, key: :request)
# Counter for number of invokations of process method
Handler.apply(Processor, method: :process, key: :processor)
# Monitor number of invokations, time taken and number of errors
Usage::ComplexHandler.apply(
App, method: :call, key: :request
)
Usage::ComplexHandler.apply(
FbService, method: :find, key: :fb_find
)
# We can always track how often do we save Mongoid objects
Usage::IncrementHandler.apply(
Mongoid::Document, method: :save, key: :mg_save
)
{
"target": "",
"function": "max",
"column": "value",
"series": "stats.request.times.upper",
"query": "select max(value) from \"stats.request.times.upper\"",
"groupby_field": "",
"alias": "Requests time upper"
},
Maciej Mensfeld