newrelic_plugin 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +31 -0
- data/README.md +3 -3
- data/lib/newrelic_plugin.rb +1 -0
- data/lib/newrelic_plugin/agent.rb +1 -1
- data/lib/newrelic_plugin/logger.rb +19 -0
- data/lib/newrelic_plugin/new_relic_message.rb +10 -10
- data/lib/newrelic_plugin/processors/rate_processor.rb +2 -2
- data/lib/newrelic_plugin/run.rb +8 -8
- data/lib/newrelic_plugin/version.rb +1 -1
- data/test/logger_test.rb +21 -0
- metadata +5 -2
data/CHANGELOG.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
## New Relic Ruby SDK Change Log ##
|
2
|
+
|
3
|
+
### vNext - Future Date ###
|
4
|
+
|
5
|
+
**Features**
|
6
|
+
|
7
|
+
* To fill in
|
8
|
+
### v1.0.3 - June 25, 2013 ###
|
9
|
+
|
10
|
+
**Features**
|
11
|
+
|
12
|
+
* Added timestamps to output to improve debugging experience.
|
13
|
+
|
14
|
+
### v1.0.2 - June 19, 2013 ###
|
15
|
+
|
16
|
+
**Features**
|
17
|
+
|
18
|
+
* Released on [RubyGems](http://rubygems.org/gems/newrelic_plugin)
|
19
|
+
|
20
|
+
### v1.0.1 - June 18, 2013 ###
|
21
|
+
|
22
|
+
**Features**
|
23
|
+
|
24
|
+
* Added configuration option for SSL hostname verification
|
25
|
+
|
26
|
+
### v1.0.0 - June 14, 2013 ###
|
27
|
+
|
28
|
+
**Features**
|
29
|
+
|
30
|
+
* Initial public release version of the New Relic Platform Ruby SDK
|
31
|
+
|
data/README.md
CHANGED
@@ -13,11 +13,11 @@ the New Relic platform. If you are looking to build or use a platform
|
|
13
13
|
component, please refer to the
|
14
14
|
[getting started documentation](http://newrelic.com/docs/platform/plugin-development).
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
Install this gem by running `gem install newrelic_plugin` or add it to your
|
17
|
+
[bundler](http://gembundler.com/) Gemfile like this:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
gem "newrelic_plugin"
|
20
|
+
gem "newrelic_plugin"
|
21
21
|
```
|
22
22
|
|
23
23
|
Alternatively you can build and install the gem locally:
|
data/lib/newrelic_plugin.rb
CHANGED
@@ -79,7 +79,7 @@ module NewRelic
|
|
79
79
|
if @guid=="guid" or @guid=="_TYPE_YOUR_GUID_HERE_"
|
80
80
|
#this feels tightly coupled to the config class, testing this is difficult, thinking about refactoring (NH)
|
81
81
|
@guid = NewRelic::Plugin::Config.config.newrelic['guids'][agent_info[:ident].to_s] if NewRelic::Plugin::Config.config.newrelic['guids']
|
82
|
-
|
82
|
+
Logger.write "NOTE: GUID updated for #{instance_label} at run-time to '#{@guid}'"
|
83
83
|
end
|
84
84
|
raise "Did not set GUID" if @guid.nil? or @guid=="" or @guid=="guid" or @guid=="_TYPE_YOUR_GUID_HERE_"
|
85
85
|
@guid
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module NewRelic
|
2
|
+
module Plugin
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
class Logger
|
6
|
+
def self.write(message)
|
7
|
+
Logger.output "[#{Logger.timestamp}] #{message}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.output(message)
|
11
|
+
puts message
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.timestamp
|
15
|
+
Time.iso8601(Time.now.utc.iso8601).to_s
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -56,7 +56,7 @@ module NewRelic
|
|
56
56
|
|
57
57
|
def send_metrics
|
58
58
|
return_errors = []
|
59
|
-
|
59
|
+
Logger.write "Metrics for #{@component_name}[#{@component_guid}] for last #{@duration_in_seconds} seconds:" if new_relic_connection.log_metrics?
|
60
60
|
#
|
61
61
|
# Send all metrics in a single transaction
|
62
62
|
#
|
@@ -78,7 +78,7 @@ module NewRelic
|
|
78
78
|
end
|
79
79
|
return metrics_hash
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
def build_request_payload
|
83
83
|
data = {
|
84
84
|
"agent" => {
|
@@ -92,7 +92,7 @@ module NewRelic
|
|
92
92
|
"guid" => @component_guid,
|
93
93
|
"duration" => @duration_in_seconds,
|
94
94
|
"metrics" => build_metrics_hash
|
95
|
-
}
|
95
|
+
}
|
96
96
|
]
|
97
97
|
}
|
98
98
|
return data.to_json
|
@@ -106,7 +106,7 @@ module NewRelic
|
|
106
106
|
req.body = build_request_payload
|
107
107
|
end
|
108
108
|
rescue => err
|
109
|
-
|
109
|
+
Logger.write "HTTP Connection Error: #{err.inspect} #{err.message}"
|
110
110
|
end
|
111
111
|
|
112
112
|
return response
|
@@ -123,7 +123,7 @@ module NewRelic
|
|
123
123
|
return_status = "FAILED[#{response.status}] <#{new_relic_connection.url}>: #{last_result["error"]}"
|
124
124
|
end
|
125
125
|
elsif response && response.status == 403 && response.body == "DISABLE_NEW_RELIC"
|
126
|
-
|
126
|
+
Logger.write "Agent has been disabled remotely by New Relic"
|
127
127
|
abort "Agent has been disabled remotely by New Relic"
|
128
128
|
else
|
129
129
|
begin
|
@@ -144,23 +144,23 @@ module NewRelic
|
|
144
144
|
if return_status
|
145
145
|
if response and response.status == 503 and !new_relic_connection.log_metrics?
|
146
146
|
# If logging not enabled, and it's a 503...be less error-ish...
|
147
|
-
|
147
|
+
Logger.write " Collector temporarily unavailable...continuing"
|
148
148
|
else
|
149
149
|
# Otherwise, in all cases (logging enabled or not) print an error message
|
150
|
-
|
150
|
+
Logger.write " ****ERROR: #{return_status}"
|
151
151
|
end
|
152
152
|
end
|
153
|
-
end
|
153
|
+
end
|
154
154
|
|
155
155
|
def log_send_metrics
|
156
156
|
if new_relic_connection.log_metrics?
|
157
|
-
|
157
|
+
Logger.write " Sent #{metrics.size} metrics to New Relic [#{new_relic_connection.url}]:"
|
158
158
|
metrics.each do |metric|
|
159
159
|
val_strs = []
|
160
160
|
[:count,:total,:min,:max,:sum_of_squares].each do |key|
|
161
161
|
val_strs << "#{key}: #{metric[key]}" if metric[key]
|
162
162
|
end
|
163
|
-
|
163
|
+
Logger.write " #{metric[:metric_name]}: #{val_strs.join(', ')}"
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
@@ -15,8 +15,8 @@ module NewRelic::Processor
|
|
15
15
|
#
|
16
16
|
class Rate<NewRelic::Plugin::Processor::Base
|
17
17
|
def initialize
|
18
|
-
|
19
|
-
|
18
|
+
Logger.write "OBSOLESCENCE WARNING: The 'Rate' processor is obsolete and should not be used."
|
19
|
+
Logger.write "OBSOLESCENCE WARNING: It will be completely removed in the near future."
|
20
20
|
super :rate,"Rate"
|
21
21
|
end
|
22
22
|
def process val
|
data/lib/newrelic_plugin/run.rb
CHANGED
@@ -19,11 +19,11 @@ module NewRelic
|
|
19
19
|
def initialize
|
20
20
|
@poll_cycle = (NewRelic::Plugin::Config.config.newrelic["poll"] || 60).to_i
|
21
21
|
@poll_cycle = 60 if (@poll_cycle <= 0) or (@poll_cycle >= 600)
|
22
|
-
|
22
|
+
Logger.write "WARNING: Poll cycle differs from 60 seconds (current is #{@poll_cycle})" if @poll_cycle!=60
|
23
23
|
end
|
24
24
|
def installed_agents
|
25
25
|
if Setup.installed_agents.size==0
|
26
|
-
|
26
|
+
Logger.write "No agents installed!"
|
27
27
|
raise NoAgents, "No agents installed"
|
28
28
|
end
|
29
29
|
Setup.installed_agents
|
@@ -71,12 +71,12 @@ module NewRelic
|
|
71
71
|
if configured_agents.size==0
|
72
72
|
err_msg = "No agents configured!"
|
73
73
|
err_msg+= " Check the agents portion of your yml file." unless NewRelic::Plugin::Config.config.options.empty?
|
74
|
-
|
74
|
+
Logger.write err_msg
|
75
75
|
raise NoAgents, err_msg
|
76
76
|
end
|
77
77
|
installed_agents.each do |agent_id,installed_agent|
|
78
78
|
version = installed_agent[:agent_class].version
|
79
|
-
|
79
|
+
Logger.write "Agent #{installed_agent[:label]} is at version #{version}" if version
|
80
80
|
end
|
81
81
|
configured_agents.each do |agent|
|
82
82
|
agent.startup if agent.respond_to? :startup
|
@@ -94,22 +94,22 @@ module NewRelic
|
|
94
94
|
begin
|
95
95
|
cnt+=agent.run @poll_cycle
|
96
96
|
rescue => err
|
97
|
-
|
97
|
+
Logger.write "Error occurred in poll cycle: #{err}"
|
98
98
|
end
|
99
99
|
end
|
100
|
-
|
100
|
+
Logger.write "Gathered #{cnt} statistics"
|
101
101
|
#
|
102
102
|
# Delay until next run
|
103
103
|
secs_to_delay=@poll_cycle-(Time.now-@last_run_time)
|
104
104
|
sleep secs_to_delay if secs_to_delay>0
|
105
105
|
end
|
106
106
|
rescue Interrupt =>err
|
107
|
-
|
107
|
+
Logger.write "Shutting down..."
|
108
108
|
end
|
109
109
|
configured_agents.each do |agent|
|
110
110
|
agent.shutdown if agent.respond_to? :shutdown
|
111
111
|
end
|
112
|
-
|
112
|
+
Logger.write "Shutdown complete"
|
113
113
|
end
|
114
114
|
#private
|
115
115
|
def agent_setup
|
data/test/logger_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LoggerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context 'self.write' do
|
6
|
+
should 'build expected log string and output it' do
|
7
|
+
NewRelic::Plugin::Logger.expects(:timestamp).returns('foobar')
|
8
|
+
NewRelic::Plugin::Logger.expects(:output).with('[foobar] test')
|
9
|
+
NewRelic::Plugin::Logger.write('test')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'self.timestamp' do
|
14
|
+
should 'format timestamp in iso8601' do
|
15
|
+
test_time = Time.new(2013, 6, 24, 0, 0, 0, "+00:00")
|
16
|
+
Time.expects(:now).twice.returns(test_time)
|
17
|
+
assert_equal '2013-06-24 00:00:00 UTC', NewRelic::Plugin::Logger.timestamp
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: newrelic_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -86,6 +86,7 @@ extra_rdoc_files:
|
|
86
86
|
- LICENSE
|
87
87
|
files:
|
88
88
|
- .gitignore
|
89
|
+
- CHANGELOG.md
|
89
90
|
- Gemfile
|
90
91
|
- LICENSE
|
91
92
|
- README.md
|
@@ -95,6 +96,7 @@ files:
|
|
95
96
|
- lib/newrelic_plugin/config.rb
|
96
97
|
- lib/newrelic_plugin/data_collector.rb
|
97
98
|
- lib/newrelic_plugin/error.rb
|
99
|
+
- lib/newrelic_plugin/logger.rb
|
98
100
|
- lib/newrelic_plugin/new_relic_connection.rb
|
99
101
|
- lib/newrelic_plugin/new_relic_message.rb
|
100
102
|
- lib/newrelic_plugin/processor.rb
|
@@ -107,6 +109,7 @@ files:
|
|
107
109
|
- newrelic_plugin.gemspec
|
108
110
|
- test/agent_test.rb
|
109
111
|
- test/fixtures/valid_payload.json
|
112
|
+
- test/logger_test.rb
|
110
113
|
- test/manual_test.rb
|
111
114
|
- test/new_relic_message_test.rb
|
112
115
|
- test/test_helper.rb
|