Code Monkey home page Code Monkey logo

new_relic_ping's Introduction

NewRelicPing

Gem Version Latest public release

Build Status Coverage Status Code Climate Master branch status

Add a URL to your rails application to respond to ping requests from NewRelic (and other services). This is something that we've found we often implement. While you can often simply call the root URL when monitoring, that isn't always possible if the homepage is protected by a login screen which returns a 403 status. Adding this gem keeps the ping URL's out of your main application space, and as a bonus, makes additional support for data stores or other services in your heartbeat a breeze.

Usage

Add this to your Gemfile

gem 'new_relic_ping'

mount in your routes.rb

mount NewRelicPing::Engine => '/status'
# Or optionally mount this at an obfuscated url instead
# mount NewRelicPing::Engine => '/status/5260b194fdea00da7e29b92f54d03028'

This enables two URL's

/status/ping
/status/health

ping will respond with the text OK, and status 200 when your rails server is available. The health action is to allow more deep monitoring of the health of your service. You can configure additional checks to run when this controller action is hit, this allows you to keep tabs on things like response times for services or data stores your app is dependent on.

Configuring monitoring checks

Configure a block to run checks monitoring services you are dependent on, e.g. :

application.rb

...
class Application < Rails::Application

  NewRelicPing.configure do |c|
    # This database check is defined for you by default if you're using ActiveRecord
    # though you can override it by redefining it in your configuration
    c.monitor('database') do
      ActiveRecord::Base.connection.execute("select count(*) from schema_migrations")
    end
    c.monitor('redis') do
      Redis.client.get('test-key')
    end
  end
...

These blocks will be executed when the /health action is called, and the additional information set in the HTTP headers of the request. X-{service}-Response will be set to the return value of the block, X-{Service}-Time will show the execution time of the given block: "X.XXXXXX seconds".

The return value of the monitoring blocks does not determine success or failure conditions, an HTTP error status will only be returned if the block raises an exception.

You can now configure any monitoring/alerting tools that you use, such as pingdom, or new relic to 'ping' this url, checking if your application is alive.

curl -v http://localhost:3000/status/ping
curl -v http://localhost:3000/status/health

Planned Features

  • Capistrano integration for enabling/disabling new relic pinging during deploys
  • suggestions welcome

Contributing to NewRelicPing

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright (c) 2013 Jeremy Olliver, released under the MIT license

new_relic_ping's People

Contributors

jeremyolliver avatar

Stargazers

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

Watchers

 avatar

new_relic_ping's Issues

Support for Rails 4

Need to run the tests with Rails 4 (and test on both 3.2 and 4.0 via appraisal)

after that's confirmed we can bump the version constraint in the gemspec to allow installation with rails 4.

Add a `/live` monitor for load balancing

A common deployment pattern is to have multiple application servers behind a load balancer such as nginx or haproxy. HAproxy in particular provides an httpcheck URL, and if that http call doesn't return a successful response, the server will be taken out of rotation.

Addition of a /live route which performs will return an okay response if the individual application server is available AND if it should be included in the live application pool.

Implementation plan:

I've used in existing production setup's a flag file in the application tmp directory, which makes enabling or disabling as easy as touch tmp/LIVE or rm tmp/LIVE

Lightweight implementation pure rack endpoint

This is no issue for including in rails applications, but given the desired interface of mounting a rack endpoint, a rails engine is a rather large dependency. Implementing as something lighter weight would make inclusion in other ruby rack-based frameworks feasible, and reduce the support required for supporting multiple rails releases.

Rails 5: Accessing mime types via constants is deprecated

Hi! Firstly, thanks for making this library, I've been using it for a long time.

In one of my apps that I'm upgrading from Rails 5.0 to 5.1, New Relic Ping causes this deprecation warning:

ActiveSupport::DeprecationException:
    DEPRECATION WARNING: Accessing mime types via constants is deprecated. Please change `Mime::TEXT` to `Mime[:text]`

This should be as simple as changing it in

render :text => status_msg.to_s, :status => status_msg, :content_type => Mime::TEXT

However, I'm not sure how I would add tests to it for a PR, since you'd still want it to have the old behavior in previous versions of Rails. Suggestions?

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.