newrelic_tag 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +22 -0
- data/README.md +27 -0
- data/lib/newrelic_tag.rb +78 -0
- data/lib/newrelic_tag/version.rb +8 -0
- metadata +83 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Copyright (c) 2011 Viximo, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
NewRelic Tag
|
2
|
+
============
|
3
|
+
|
4
|
+
Enable newrelic monitor on a host-by-host basis by checking for the presence of an AWS tag. By default,
|
5
|
+
the tag is called 'NewRelic' and the expected setting is 'true'.
|
6
|
+
|
7
|
+
Configuration
|
8
|
+
-------------
|
9
|
+
|
10
|
+
Add newrelic_tag to your Gemfile.
|
11
|
+
|
12
|
+
At the top of newrelic.yml, require the library and configure it.
|
13
|
+
|
14
|
+
<%
|
15
|
+
require 'newrelic_tag'
|
16
|
+
NewrelicTag.configure do |c|
|
17
|
+
c.aws_access_key_id = '..key here..'
|
18
|
+
c.aws_secret_access_key = '..secret here..'
|
19
|
+
c.tag = 'new-relic'
|
20
|
+
c.value = 'on'
|
21
|
+
end
|
22
|
+
%>
|
23
|
+
|
24
|
+
For each environment which should be controlled by tagging, set monitor_mode:
|
25
|
+
|
26
|
+
production:
|
27
|
+
monitor_mode: <%= NewrelicTag.enabled? %>
|
data/lib/newrelic_tag.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'fog'
|
4
|
+
|
5
|
+
class NewrelicTag
|
6
|
+
autoload :Version, 'newrelic_tag/version'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
attr_accessor :tag
|
10
|
+
attr_accessor :value
|
11
|
+
attr_accessor :aws_access_key_id
|
12
|
+
attr_accessor :aws_secret_access_key
|
13
|
+
attr_accessor :instance_id_url
|
14
|
+
attr_accessor :allowed_environments
|
15
|
+
end
|
16
|
+
|
17
|
+
self.tag = 'NewRelic'
|
18
|
+
self.value = 'true'
|
19
|
+
self.instance_id_url = 'http://169.254.169.254/latest/meta-data/instance-id'
|
20
|
+
self.allowed_environments = %q(staging production)
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def instance
|
24
|
+
@instance ||= self.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset!
|
28
|
+
@instance = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def configure
|
32
|
+
yield(self) if block_given?
|
33
|
+
end
|
34
|
+
|
35
|
+
def enabled?
|
36
|
+
instance.enabled?
|
37
|
+
end
|
38
|
+
|
39
|
+
def compute
|
40
|
+
@compute ||= Fog::Compute.new(
|
41
|
+
:provider => 'AWS',
|
42
|
+
:aws_access_key_id => aws_access_key_id,
|
43
|
+
:aws_secret_access_key => aws_secret_access_key)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def enabled?
|
48
|
+
@enabled = begin
|
49
|
+
environment_allowed? && has_tag?
|
50
|
+
rescue => e
|
51
|
+
puts "Error reading NewRelic tag: #{e}"
|
52
|
+
false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def has_tag?
|
57
|
+
!self.class.compute.tags.all('key' => self.class.tag, 'value' => self.class.value,
|
58
|
+
'resource-id' => instance_id).empty?
|
59
|
+
end
|
60
|
+
|
61
|
+
def environment_allowed?
|
62
|
+
self.class.allowed_environments.include?(environment)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def environment
|
68
|
+
ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
69
|
+
end
|
70
|
+
|
71
|
+
def instance_id
|
72
|
+
url = URI.parse(self.class.instance_id_url)
|
73
|
+
request = Net::HTTP::Get.new(url.path)
|
74
|
+
result = Net::HTTP.start(url.host, url.port) { |http| http.request(request) }
|
75
|
+
result.body.chomp
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: newrelic_tag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Matt Griffin
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-09-06 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: fog
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: " Enable newrelic reporting based on an EC2 tag.\n"
|
36
|
+
email: matt@griffinonline.org
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- README.md
|
45
|
+
- LICENSE
|
46
|
+
- lib/newrelic_tag/version.rb
|
47
|
+
- lib/newrelic_tag.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://github.com/Viximo/newrelic_tag
|
50
|
+
licenses: []
|
51
|
+
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.5.3
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: Enable newrelic reporting based on an EC2 tag.
|
82
|
+
test_files: []
|
83
|
+
|