dmitrytsepelev / io_monitor Goto Github PK
View Code? Open in Web Editor NEWA gem that helps to detect potential memory bloats
License: MIT License
A gem that helps to detect potential memory bloats
License: MIT License
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!
IoMonitor.configure do |config|
config.publish = [:logs, :notifications]
end
More details on Cult.
We need to implement a module that patches controller actions to measure database and HTTP response payload:
class ReportController < ApplicationController
include IoToResponsePayloadRatio::Controller
def monthly_transaction_sum
sum = Transactions.where(date: Date.current.all_month).sum(&:amount)
render json: { sum: sum }
end
end
It can help find possible memory bloats earlier. These measurements can be sent to Rails logs or published as notification events. For instance, log could look like this:
Completed 200 OK in 1232ms (ActiveRecord: 400ms, DB Payload: 10kB, Body: 1kB, Allocations: 213223)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.