Git Product home page Git Product logo

rss_observer's Introduction

RssObserver

Rails middleware for observing of RSS memory changes around the request. Under the hood, it utilizes the get_process_mem gem.

CircleCI

Installation

Add the line gem 'rss_observer' to your Gemfile and run bundle install.

Configuration

To use this middleware in a Rails application, modify relevant environment file (or application.rb to log rss in all environments). You can use the supplied STDOUT logger and insert the RssObserver middleware after Rails::Rack::Logger.

require 'rss_observer/logger_handler'
module FooApp
  class Application < Rails::Application
    # ...
    config.middleware.insert_after Rails::Rack::Logger, RssObserver::Middleware, RssObserver::LoggerHandler.new
  end
end

More realistically, you'll need something more production-ready. You can prepare a custom class that will make use of Rails.logger, that, with request_id in log tags will allow you to match the usage log with actual request logs.

# lib/rails_logger_handler.rb
class RailsLoggerHandler
  def initial_memory(kilobytes)
    Thread.current[:_initial_memory] = kilobytes
  end

  def final_memory(kilobytes)
    Rails.logger.info "Memory change: #{final_memory - Thread.current[:_initial_memory]} KB"
  end
end

# config/application.rb
require_relative '../lib/rails_logger_handler'
module FooApp
  class Application < Rails::Application
    # ...
    config.log_tags = [:request_id]
    config.middleware.insert_after Rails::Rack::Logger, RssObserver::Middleware, RailsLoggerHandler.new
  end
end

Example

RssObserver vs Default Rails request logs

I, [2019-09-03T14:56:22.735264 #7290]  INFO -- : [96956f1a-7f7f-4836-a8a1-bc3c05696433] Completed 200 OK in 47ms (Views: 29.7ms | ActiveRecord: 6.3ms | Allocations: 18614)
I, [2019-09-03T14:56:22.737113 #7290]  INFO -- : [96956f1a-7f7f-4836-a8a1-bc3c05696433] Memory change: 264.0 KB

rss_observer's People

Contributors

dependabot[bot] avatar maciek-rr avatar

Stargazers

 avatar

Watchers

 avatar

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.