operations_middleware 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ doc
20
21
 
21
22
  ## PROJECT::SPECIFIC
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Emily Price
1
+ Copyright (c) 2010 PRIMEDIA Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,6 +1,36 @@
1
- = operation_middleware
1
+ = Operations Middleware
2
2
 
3
- Description goes here.
3
+ This library provides a piece of Rack middleware for monitoring application status. To include it in a rails application, you need to provide the following minimum configuration:
4
+
5
+ config.gem 'operations_middleware'
6
+ require 'operations_middleware'
7
+ config.middleware.use OperationsMiddleware do |ops|
8
+ ops.file_root = RAILS_ROOT
9
+ end
10
+
11
+ == Version Page
12
+
13
+ This will provide a page at <tt>/ops/version</tt> which shows, in development mode, the current git branch and last commit SHA. In all other modes, it shows the same information, but taken from the contents of VERSION and REVISION files in the <tt>file_root</tt> directory. If you are deploying with Capistrano, the REVISION file will be created for you. If you want the VERSION file, you'll need to add that to your project or your Capistrano scripts.
14
+
15
+ == Heartbeat Page
16
+
17
+ It also provides a simple page at <tt>/ops/heartbeat</tt> which returns a 200 'OK' as long as the application is running.
18
+
19
+ The application name is taken from the enclosing folder of the <tt>file_root</tt> option. If that folder is a Capistrano timestamped release, it goes up 2 additional levels for the name, stripping <tt>.com</tt> from the end of the directory if necessary. If this logic does not get the correct application name, it can be set manually in the configuration block:
20
+
21
+ ops.app_name = 'Custom Application Name'
22
+
23
+ === Adding Custom Heartbeats
24
+
25
+ Additionally, you can specify custom heartbeat monitoring pages as follows:
26
+
27
+ ops.heartbeat[:mysql] = lambda do
28
+ conn = ActiveRecord::Base.connection
29
+ migrations = conn.select_all("SELECT COUNT(1) FROM schema_migrations;")
30
+ conn.disconnect!
31
+ end
32
+
33
+ The mysql example shown above would be accessed at <tt>ops/heartbeat/mysql</tt>. The heartbeat can be set to any object which responds to <tt>call</tt>. The heartbeat page will return a 200 'OK' as long as the provided lambda does not raise an error. If an error is raised, a 500 will be returned instead.
4
34
 
5
35
  == Note on Patches/Pull Requests
6
36
 
@@ -14,4 +44,4 @@ Description goes here.
14
44
 
15
45
  == Copyright
16
46
 
17
- Copyright (c) 2010 Emily Price. See LICENSE for details.
47
+ Copyright (c) 2010 PRIMEDIA Inc. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -10,7 +10,9 @@ class OperationsMiddleware
10
10
 
11
11
  def call(env)
12
12
  return @app.call(env) unless env['PATH_INFO'] =~ %r{^/ops/(heartbeat|version)(?:/(\w+))?/?$}
13
-
13
+
14
+ @request_headers = env
15
+
14
16
  @status = 200
15
17
  @headers = {}
16
18
 
@@ -108,7 +110,7 @@ class OperationsMiddleware
108
110
  end
109
111
 
110
112
  def headers
111
- hh = @headers.select{|k,v| k.match(/^HTTP.*/) }
113
+ hh = @request_headers.select{|k,v| k.match(/^[-A-Z_].*$/) }
112
114
  return if hh.nil? || hh.empty?
113
115
  ret = "<table border='1' style='width:100%'>"
114
116
  hh.each { |k, v| ret += "<tr><td>#{k}</td><td>#{v}</td></tr>" }
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{operations_middleware}
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Primedia Team"]
12
- s.date = %q{2010-07-19}
12
+ s.date = %q{2010-07-06}
13
13
  s.description = %q{Rack middleware to provide route for heartbeat and version pages. Includes links to github repo. }
14
14
  s.email = %q{}
15
15
  s.extra_rdoc_files = [
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rubygems'
3
4
  gem 'rack', '1.0.1'
5
+ require 'rack'
4
6
  require 'operations_middleware'
5
7
  require 'spec'
6
8
  require 'spec/autorun'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 0
9
- version: 0.3.0
8
+ - 1
9
+ version: 0.3.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Primedia Team
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-19 00:00:00 -04:00
17
+ date: 2010-07-06 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency