Created
July 11, 2015 22:33
-
-
Save sergey-chechaev/2b2a1a03fabece0b5032 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Yam | |
class ActionControllerLogger < YamLogger | |
def self.subscribe | |
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args| | |
event = ActiveSupport::Notifications::Event.new *args | |
self.structure(event.payload,event.duration, event.name) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Yam | |
class ActiveRecordLogger < YamLogger | |
def self.subscribe | |
ActiveSupport::Notifications.subscribe "sql.active_record" do |*args| | |
event = ActiveSupport::Notifications::Event.new *args | |
self.structure(event.payload,event.duration, event.name) | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Yam | |
class YamLogger | |
def self.start(**args) | |
settings = { | |
disable: false, | |
port: 8081, | |
host: 'localhost' | |
}.merge(args) | |
@@port = settings[:port] | |
@@host = settings[:host] | |
unless settings[:disable] | |
Yam::YamLogger.start_socket | |
Yam::YamLogger.subscribe | |
end | |
end | |
def self.start_socket | |
begin | |
@@socket = TCPSocket.new @@host, @@port | |
rescue Exception => e | |
# IO.popen('ruby em.rb') | |
end | |
end | |
def self.subscribe | |
Yam::ActiveRecordLogger.subscribe | |
Yam::ActionControllerLogger.subscribe | |
end | |
def self.structure(payload, duration, name) | |
hash = {} | |
names = name.split(".") | |
node = names[1].to_sym | |
payload[:duration] = duration | |
hash[node] = payload | |
begin | |
@@socket.write(hash) | |
rescue Exception => e | |
# IO.popen('ruby em.rb') | |
end | |
end | |
end | |
end | |
Структура для GO
{
"request": "url",
"metrics":
{
"name": "Front::AdCampaignsController#show",
"duration": 11212,
"start": "timestamp",
"child":
[{
"name": "sql",
"duration": 111,
"start": "timestamp",
}]
},
"timestamp": "1438440347"
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Формат для запросов для контроллера
{
"action_controller":{
"controller":"Front::AdCampaignsController",
"action":"index",
"params":{
"locale":"ru",
"action":"index",
"controller":"front/ad_campaigns"
},
"format":"html",
"method":"GET",
"path":"/ad_campaigns?locale=ru",
"status":200,
"view_runtime":1265.296,
"searchkick_runtime":0,
"db_runtime":156.83099999999993,
"duration":1743.555
}
}