io_monitor
io_monitor copied to clipboard
Allocations missing in ActiveSupport notifications
Hi! Thanks for this very useful gem. I see stats about allocations in the logs but not in the AS notification.
for example in the logs I see:
Completed 200 OK in 20638ms (Views: 14986.2ms | Flexirest: 0.0ms for 0 calls | ActiveRecord: 4770.2ms | ActiveRecord Payload: 1.14 MB | NetHttp Payload: 0 Bytes | Redis Payload: 0 Bytes | Response Payload: 1.2 MB | Allocations: 16348844)
but in the notification I see:
{:controller=>"Api::Integration::Events::InvitesController", :action=>"index", :method=>"GET", :status=>200, :view_runtime=>14986.230043135583, :db_runtime=>4770.207956790924, :path=>"/api/blendr/organizations/562/events/6069/invites", :active_record=>1197902, :net_http=>0, :redis=>0, :response=>1256895}
I am trying to export these metrics to prometheus to find out which endpoints use most allocations.
How can I add that info to the AS notification?
This is what I am doing now:
IoMonitor.configure do |config|
config.publish = [:logs, :notifications] # defaults to :logs
config.warn_threshold = 0.8 # defaults to 0
config.adapters = [:active_record, :net_http, :redis] # defaults to [:active_record]
end
# if Rails.env.production?
require 'prometheus_exporter/client'
ActiveSupport::Notifications.subscribe("process_action.action_controller") do |name, start, finish, id, payload|
io_monitor = payload[:io_monitor] || {}# { active_record: 866, response: 25 }
metrics = payload.slice(:controller, :action, :method, :status, :view_runtime, :db_runtime, :path).merge(io_monitor)
p metrics
# PrometheusExporter::Client.default.send_json(type: "io_monitor", **metrics)
end
Thanks!
Hi @vitobotta! The gem sends the notification with the name warn_threshold_reached.io_monitor
and the ratio in the payload. Looks like you're subscribing to the event sent by Rails itself.
Aha!!! Will give that a try. Thanks!