Socket
Book a DemoInstallSign in
Socket

rss_observer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rss_observer

0.2.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 04 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.