Giter Club home page Giter Club logo

peek-performance_bar's Introduction

Peek

Build Status Gem Version Inline docs

Take a peek into your Rails application.

Preview

This is a profiling tool originally built at GitHub to help us get an insight into our application. Now, we have extracted this into Peek, so that other Rails applications can experience the same benefit.

Peek puts a little bar on top of your application to show you all sorts of helpful information about your application. From the screenshot above, you can see that Peek provides information about database queries, cache, Resque workers and more. However, this is only part of Peek's beauty.

The true beauty of Peek lies in the fact that it is an extensible platform. If there are some performance metrics that you need but are not available on Peek, you can find them in the list of available Peek Views and integrate them into Peek. Even if you do not find what you want on Peek Views, you can always create your own.

Installation

Add this line to your application's Gemfile:

gem 'peek'

And then execute:

$ bundle

Or install it yourself as:

$ gem install peek

Usage

Now that Peek is installed, you'll need to mount the engine within your config/routes.rb file:

Some::Application.routes.draw do
  mount Peek::Railtie => '/peek'
  root to: 'home#show'
end

To pick which views you want to see in your Peek bar, just create a file at config/initializers/peek.rb that has a list of the views you'd like to include:

Peek.into Peek::Views::Git, nwo: 'github/janky'
Peek.into Peek::Views::Mysql2
Peek.into Peek::Views::Redis
Peek.into Peek::Views::Dalli

Feel free to pick and install from the list or create your own. The order they are added to Peek is the order they will appear in your bar.

Next, to render the Peek bar in your application, add the following snippet just after the opening <body> tag in your application layout.

<%= render 'peek/bar' %>

It will look like:

<html>
  <head>
    <title>Application</title>
  </head>
  <body>
    <%= render 'peek/bar' %>
    <%= yield %>
  </body>
</html>

Peek fetches the data collected throughout your requests by using the unique request id that was assigned to the request by Rails. It will call out to its own controller at Peek::ResultsController which will render the data and be inserted into the bar.

Now that you have the partials in your application, you will need to include the CSS and JS that help make Peek โœจ

In app/assets/stylesheets/application.scss:

//= require peek

In app/assets/javascripts/application.coffee:

#= require jquery
#= require jquery_ujs
#= require peek

Note: Each additional view may have their own CSS and JS that you may need to require which should be stated in their usage documentation.

Configuring the default adapter

For Peek to work, it keeps track of all requests made in your application so it can report back and display that information in the Peek bar. By default it stores this information in memory, which is not recommended for production environments.

In production environments you may have application servers on multiple hosts. Peek will not be able to access the request data if it was saved in memory on another host. Peek provides additional adapters for multi server environments.

You can configure which adapter Peek uses by updating your application config or an individual environment config file. We'll use production as an example.

Note: Peek does not provide the dependencies for each of these adapters. If you use these adapters be sure to include their dependencies in your application.

Peeked::Application.configure do
  # ...

  # Redis with no options
  config.peek.adapter = :redis

  # Redis with options
  config.peek.adapter = :redis, {
    client: Redis.new,
    expires_in: 60 * 30 # => 30 minutes in seconds
  }

  # Memcache with no options
  config.peek.adapter = :memcache

  # Memcache with options
  config.peek.adapter = :memcache, {
    client: Dalli::Client.new,
    expires_in: 60 * 30 # => 30 minutes in seconds
  }

  # Elasticsearch with no options
  config.peek.adapter = :elasticsearch

  # Elasticsearch with options
  config.peek.adapter = :elasticsearch, {
    client: Elasticsearch::Client.new,
    expires_in: 60 * 30, # => 30 minutes in seconds
    index: 'peek_requests_index',
    type: 'peek_request'
  }

  # ...
end

Peek doesn't persist the request data forever. It uses a safe 30 minute cache length so that data will be available if you'd like to aggregate it or use it for other Peek views. You can update this to be 30 seconds if you don't want the data to be available for these or other uses.

Customizing the bar

You can customize the appearance of the bar by customizing it in your own application's CSS.

One common example is fixing the peek bar to the bottom, rather than top, of a page, for use with Bootstrap:

#peek {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
}

Using Peek with PJAX

It just works.

Using Peek with Turbolinks

It just works.

Access Control

Peek will only render in development and staging environments. If you'd like to whitelist a select number of users to view Peek in production you can override the peek_enabled? guard in ApplicationController:

class ApplicationController < ActionController::Base
  def peek_enabled?
    current_user.staff?
  end
end

Available Peek views

Feel free to submit a Pull Request adding your own Peek item to this list.

Creating your own Peek item

Each Peek item is a self contained Rails engine which gives you the power to use all features of Ruby on Rails to dig in deep within your application and report it back to the Peek bar. A Peek item is just a custom class that is responsible for fetching and building the data that should be reported back to the user.

There are still some docs to be written, but if you'd like to check out a simple example of how to create your own, just checkout peek-git. To just look at an example view, there is Peek::Views::Git.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

peek-performance_bar's People

Contributors

0rvar avatar brandonweiss avatar carlosbrando avatar dewski avatar gfx avatar godfat avatar jnunemaker avatar lucasmazza avatar rymai avatar tubaxenor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

peek-performance_bar's Issues

Use of ES6 "class" not supported by Pale Moon browser.

The Pale Moon browser is one of the browsers we use at our web development shop, and is an important browser for us to test against. It does not yet (may never?) support the ES6 keyword "class" which is used in the file performance_bar.js of this project. Including peek bar in our Rails projects cause JS to fail to work in many confusing ways while using the Pale Moon browser. Please consider supporting this web browser. Until that happens, we can't use the peek plug-in, and instead have to use an alternative. =(

Additional info:
https://forum.palemoon.org/viewtopic.php?f=13&t=17663

Bullet and Performance Bar Don't Get Along

I have a Rails 3.2.18 app, with both peek-performance_bar (1.1.4) and [bullet](https://github.com/flyerhzm/bullet) (4.10.0) installed.

But when I have the peek-performance-bar gem in my Gemfile, bullet stops alerting. I've done some preliminary digging and can't see exactly where you're colliding, but it definitely seems you are.

My middleware stack:

$ rake middleware
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f94e1f4b168>
use UTF8ParamValidator
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use BetterErrors::Middleware
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use CleanCookies::Rack
use ActionDispatch::Cookies
use ActiveRecord::SessionStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use ActionDispatch::Head
use Rack::ConditionalGet
use Rack::ETag
use ActionDispatch::BestStandardsSupport
use NewRelic::Rack::DeveloperMode
use NewRelic::Rack::BrowserMonitoring
use NewRelic::Rack::AgentHooks
use NewRelic::Rack::ErrorCollector
use Bullet::Rack
use ExceptionNotification::Rack
run Recruit::Application.routes

My bullet config is watching for N+1s and notifying using the the Rails logger, console, and alert, but changing that doesn't seem to matter.

My Peek config includes other views; they can be installed and bullet still works. But simply adding peek-performance-bar to the Gemfile is enough to kill Bullet.

Incorrect time

Hey all,

I'm getting times such as 1398445106.853s on Rails 4.1 (Chrome and Firefox, OSX). Would this be caused by turbolinks possibly? Not sure what additional information would be useful, let me know!

Edit: When I restart chrome and visit the webpage for the first time, the time is reported correctly. It seems like all subsequent page visits will get the incorrect time (quitting Chrome entirely resets this). Firefox reports the incorrect time for all page loads.

Tooltips blocked by mouse

The timing tooltips are blocked by the hovering mouse and disappear immediately when I move the mouse away to see the content. Perhaps a 500ms delay before fading out?

v1.3 is written with ES6 and no longer compiles in a "standard" Rails 4 app

It's somewhat OK, but I think it's worth mentioning in changelog and readme files. I spent quite some time debugging it after gem update. The error wasn't that straightforward:

ExecJS::RuntimeError: SyntaxError: Unexpected token: name (PerformanceBar) (line: 358, col: 6, pos: 12943)

Error
    at new JS_Parse_Error (/tmp/execjs20171106-3876-1k89ds2js:3623:11948)
    at js_error (/tmp/execjs20171106-3876-1k89ds2js:3623:12167)
    at croak (/tmp/execjs20171106-3876-1k89ds2js:3623:22038)
    at token_error (/tmp/execjs20171106-3876-1k89ds2js:3623:22175)
    at unexpected (/tmp/execjs20171106-3876-1k89ds2js:3623:22263)
    at semicolon (/tmp/execjs20171106-3876-1k89ds2js:3623:22781)
    at simple_statement (/tmp/execjs20171106-3876-1k89ds2js:3623:25959)
    at /tmp/execjs20171106-3876-1k89ds2js:3623:23747
    at /tmp/execjs20171106-3876-1k89ds2js:3623:22954
    at /tmp/execjs20171106-3876-1k89ds2js:3624:3759
new JS_Parse_Error ((execjs):3623:11948)
js_error ((execjs):3623:12167)
croak ((execjs):3623:22038)
token_error ((execjs):3623:22175)
unexpected ((execjs):3623:22263)
semicolon ((execjs):3623:22781)
simple_statement ((execjs):3623:25959)

And just a suggestion: please reverse the order in your changelog files across all peek gems. A common practice suggests that versions should go in descending order. Then the most recent changes are always at the top which is much more convenient. Examples:
https://github.com/rails/webpacker/blob/master/CHANGELOG.md
https://github.com/rspec/rspec-core/blob/master/Changelog.md
https://github.com/thoughtbot/factory_bot_rails/blob/master/NEWS
https://github.com/mperham/sidekiq/blob/master/Changes.md
https://github.com/plataformatec/devise/blob/master/CHANGELOG.md

Anyway, thank you for peek, it's awesome and we use it everyday. Let me know if I can help with any of these issues I mentioned above.

Javascript breaks on iOS

    @timing ?= window.performance.timing

iOS does not have window.performance so checking for window.performance.timing breaks.

Hover over bar causes line jump

When I hover my mouse over one of the perf bar elements, the tooltip text is written as a line of text in the document, not an actual tooltip, and causes the bar to jump from under my cursor. I'm using Chrome 25 on OSX and have included both CSS and JS.

Screen Shot 2013-03-16 at 4 02 50 PM

Weird timing being shown in the performance bar on page navigation

I've installed Peek into my application, and this is what I've been getting.

bug

This happens only when you navigate to the page, i.e. if you open the page by URL or refresh the page, this doesn't seem to occur. I'm thinking of this as a turbolinks issue.

Any help?

Bootstrap 3

Switched to Bootstrap 3 and now peek bar javascript is giving INSANE widths
e.g.

width: 1820.6347305389222px;

This shoots off to the right side of the page. Not really sure why or what would cause this with moving to Bootstrap 3. Please let me know if there's any way I can help.

Strange frontend time (Turbolinks?)

When a page is loaded using Cmd+R, everything works just fine.

But if I navigate to a different page, the timer goes crazy:

screen shot 2018-03-02 at 7 06 57 pm

This started after I added Turbolinks, which may be the problem.

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.