Giter Club home page Giter Club logo

io_monitor's Issues

undefined method `body` and `code` for nil

I believe since the response is nil.. then open-uri tries to call resp.code which does not work

image

IoMonitor.configure do |config|
  config.publish = :logs
  config.warn_threshold = 0.8 
  config.adapters = [:active_record, :net_http, :redis] 
end

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!

Provide initial implementation

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.