newrelic_f5_plugin 1.0.4 → 1.0.6

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.
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'newrelic_plugin'
4
+ require 'snmp'
5
+
6
+
7
+
8
+ #
9
+ # Walk the SNMP OIDs
10
+ #
11
+ def gather_snmp_metrics_by_name(metric_prefix, metric_names, oids, snmp)
12
+ metrics = { }
13
+ index = 0
14
+
15
+ if metric_prefix.nil? or metric_prefix.empty?
16
+ NewRelic::PlatformLogger.debug("Invalid metric_prefix passed to gather_snmp_metrics_by_name")
17
+ return metrics
18
+ end
19
+
20
+ if metric_names.nil? or metric_names.empty? or not metric_names.kind_of?(Array)
21
+ NewRelic::PlatformLogger.debug("Invalid metric_names passed to gather_snmp_metrics_by_name")
22
+ return metrics
23
+ end
24
+
25
+ if oids.nil? or oids.empty?
26
+ NewRelic::PlatformLogger.debug("Invalid oids passed to gather_snmp_metrics_by_name")
27
+ return metrics
28
+ end
29
+
30
+ # Convert to Array if not passed as one
31
+ oids = [oids] if not oids.kind_of?(Array)
32
+
33
+ metric_prefix = "#{metric_prefix}/" unless metric_prefix.end_with?("/")
34
+
35
+ if snmp
36
+ begin
37
+ snmp.walk(oids) do |row|
38
+ row.each do |vb|
39
+ metrics["#{metric_prefix}#{metric_names[index]}"] = vb.value.to_i
40
+ index += 1
41
+ end
42
+ end
43
+ rescue Exception => e
44
+ NewRelic::PlatformLogger.error("Unable to gather SNMP metrics with error: #{e}")
45
+ end
46
+ end
47
+
48
+ return metrics
49
+ end
50
+
51
+
52
+ #
53
+ # Return all of the OID values in an array
54
+ #
55
+ def gather_snmp_metrics_array(oids, snmp)
56
+ metrics = [ ]
57
+
58
+ if oids.nil? or oids.empty?
59
+ NewRelic::PlatformLogger.debug("Invalid oids passed to gather_snmp_metrics_array")
60
+ return metrics
61
+ end
62
+
63
+ # Convert to Array if not passed as one
64
+ oids = [oids] if not oids.kind_of?(Array)
65
+
66
+ if snmp
67
+ begin
68
+ metrics = snmp.get_value(oids)
69
+ rescue Exception => e
70
+ NewRelic::PlatformLogger.error("Unable to gather SNMP metrics with error: #{e}")
71
+ return
72
+ end
73
+ end
74
+
75
+ return metrics
76
+ end
77
+
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'newrelic_plugin'
4
- require 'snmp'
5
4
 
6
5
  #LtmVirtualServStatEntry
7
6
  # ltmVirtualServStatName LongDisplayString,
@@ -83,12 +82,17 @@ module NewRelic
83
82
  if snmp
84
83
  @vs_names.clear
85
84
 
86
- snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_NAME]) do |row|
87
- row.each do |vb|
88
- @vs_names.push(vb.value)
85
+ begin
86
+ snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_NAME]) do |row|
87
+ row.each do |vb|
88
+ @vs_names.push(vb.value)
89
+ end
89
90
  end
91
+ rescue Exception => e
92
+ NewRelic::PlatformLogger.error("Unable to gather Virtual Server names with error: #{e}")
90
93
  end
91
94
 
95
+ NewRelic::PlatformLogger.debug("Virtual Servers: Found #{@vs_names.size} virtual servers")
92
96
  return @vs_names
93
97
  end
94
98
  end
@@ -99,22 +103,12 @@ module NewRelic
99
103
  # Gather VS Total Requests
100
104
  #
101
105
  def get_requests(snmp = nil)
102
- metrics = { }
103
- index = 0
104
- snmp = snmp_manager unless snmp
105
-
106
- if snmp
107
- get_names(snmp) if @vs_names.empty?
108
-
109
- snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_TOT_REQUESTS]) do |row|
110
- row.each do |vb|
111
- metrics["Virtual Servers/Requests/#{@vs_names[index]}"] = vb.value.to_i
112
- index += 1
113
- end
114
- end
106
+ snmp = snmp_manager unless snmp
115
107
 
116
- return metrics
117
- end
108
+ get_names(snmp) if @vs_names.empty?
109
+ res = gather_snmp_metrics_by_name("Virtual Servers/Requests", @vs_names, OID_LTM_VIRTUAL_SERV_STAT_TOT_REQUESTS, snmp)
110
+ NewRelic::PlatformLogger.debug("Virtual Servers: Got #{res.size}/#{@vs_names.size} Request metrics")
111
+ return res
118
112
  end
119
113
 
120
114
 
@@ -123,22 +117,12 @@ module NewRelic
123
117
  # Gather VS Connection count
124
118
  #
125
119
  def get_conns_current(snmp = nil)
126
- metrics = { }
127
- index = 0
128
- snmp = snmp_manager unless snmp
129
-
130
- if snmp
131
- get_names(snmp) if @vs_names.empty?
132
-
133
- snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_CLIENT_CUR_CONNS]) do |row|
134
- row.each do |vb|
135
- metrics["Virtual Servers/Current Connections/#{@vs_names[index]}"] = vb.value.to_i
136
- index += 1
137
- end
138
- end
120
+ snmp = snmp_manager unless snmp
139
121
 
140
- return metrics
141
- end
122
+ get_names(snmp) if @vs_names.empty?
123
+ res = gather_snmp_metrics_by_name("Virtual Servers/Current Connections", @vs_names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_CUR_CONNS, snmp)
124
+ NewRelic::PlatformLogger.debug("Virtual Servers: Got #{res.size}/#{@vs_names.size} Current Connection metrics")
125
+ return res
142
126
  end
143
127
 
144
128
 
@@ -147,22 +131,12 @@ module NewRelic
147
131
  # Gather VS Connection rate
148
132
  #
149
133
  def get_conns_total(snmp = nil)
150
- metrics = { }
151
- index = 0
152
- snmp = snmp_manager unless snmp
153
-
154
- if snmp
155
- get_names(snmp) if @vs_names.empty?
156
-
157
- snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_CLIENT_TOT_CONNS]) do |row|
158
- row.each do |vb|
159
- metrics["Virtual Servers/Connection Rate/#{@vs_names[index]}"] = vb.value.to_i
160
- index += 1
161
- end
162
- end
134
+ snmp = snmp_manager unless snmp
163
135
 
164
- return metrics
165
- end
136
+ get_names(snmp) if @vs_names.empty?
137
+ res = gather_snmp_metrics_by_name("Virtual Servers/Connection Rate", @vs_names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_TOT_CONNS, snmp)
138
+ NewRelic::PlatformLogger.debug("Virtual Servers: Got #{res.size}/#{@vs_names.size} Connection Rate metrics")
139
+ return res
166
140
  end
167
141
 
168
142
 
@@ -171,46 +145,28 @@ module NewRelic
171
145
  # Gather VS Throughput Inbound (returns in bits)
172
146
  #
173
147
  def get_throughput_in(snmp = nil)
174
- metrics = { }
175
- index = 0
176
- snmp = snmp_manager unless snmp
177
-
178
- if snmp
179
- get_names(snmp) if @vs_names.empty?
180
-
181
- snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_IN]) do |row|
182
- row.each do |vb|
183
- metrics["Virtual Servers/Throughput/In/#{@vs_names[index]}"] = (vb.value.to_f * 8)
184
- index += 1
185
- end
186
- end
148
+ snmp = snmp_manager unless snmp
187
149
 
188
- return metrics
189
- end
150
+ get_names(snmp) if @vs_names.empty?
151
+ res = gather_snmp_metrics_by_name("Virtual Servers/Throughput/In", @vs_names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_IN, snmp)
152
+ res = res.each_key { |n| res[n] *= 8 }
153
+ NewRelic::PlatformLogger.debug("Virtual Servers: Got #{res.size}/#{@vs_names.size} Inbound Throughput metrics")
154
+ return res
190
155
  end
191
156
 
192
157
 
193
158
 
194
159
  #
195
- # Gather VS Throughput Inbound (returns in bits)
160
+ # Gather VS Throughput Outbound (returns in bits)
196
161
  #
197
162
  def get_throughput_out(snmp = nil)
198
- metrics = { }
199
- index = 0
200
- snmp = snmp_manager unless snmp
201
-
202
- if snmp
203
- get_names(snmp) if @vs_names.empty?
204
-
205
- snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_OUT]) do |row|
206
- row.each do |vb|
207
- metrics["Virtual Servers/Throughput/Out/#{@vs_names[index]}"] = (vb.value.to_f * 8)
208
- index += 1
209
- end
210
- end
163
+ snmp = snmp_manager unless snmp
211
164
 
212
- return metrics
213
- end
165
+ get_names(snmp) if @vs_names.empty?
166
+ res = gather_snmp_metrics_by_name("Virtual Servers/Throughput/Out", @vs_names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_OUT, snmp)
167
+ res = res.each_key { |n| res[n] *= 8 }
168
+ NewRelic::PlatformLogger.debug("Virtual Servers: Got #{res.size}/#{@vs_names.size} Outbound Throughput metrics")
169
+ return res
214
170
  end
215
171
 
216
172
 
@@ -219,26 +175,14 @@ module NewRelic
219
175
  # Gather VS Connection rate
220
176
  #
221
177
  def get_cpu_usage_1m(snmp = nil)
222
- metrics = { }
223
- index = 0
224
- snmp = snmp_manager unless snmp
225
-
226
- if snmp
227
- get_names(snmp) if @vs_names.empty?
228
-
229
- snmp.walk([OID_LTM_VIRTUAL_SERV_STAT_VS_USAGE_RATIO_1M]) do |row|
230
- row.each do |vb|
231
- metrics["Virtual Servers/CPU Usage/1m/#{@vs_names[index]}"] = vb.value.to_i
232
- index += 1
233
- end
234
- end
178
+ snmp = snmp_manager unless snmp
235
179
 
236
- return metrics
237
- end
180
+ get_names(snmp) if @vs_names.empty?
181
+ res = gather_snmp_metrics_by_name("Virtual Servers/CPU Usage/1m", @vs_names, OID_LTM_VIRTUAL_SERV_STAT_VS_USAGE_RATIO_1M, snmp)
182
+ NewRelic::PlatformLogger.debug("Virtual Servers: Got #{res.size}/#{@vs_names.size} CPU metrics")
183
+ return res
238
184
  end
239
185
 
240
-
241
-
242
186
  end
243
187
  end
244
188
  end
@@ -1,4 +1,6 @@
1
1
  require 'rubygems'
2
+ require 'newrelic_f5_plugin/util'
3
+ require 'newrelic_f5_plugin/device'
2
4
  require 'newrelic_f5_plugin/nodes'
3
5
  require 'newrelic_f5_plugin/pools'
4
6
  require 'newrelic_f5_plugin/virtuals'
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'newrelic_f5_plugin'
16
- s.version = '1.0.4'
17
- s.date = '2013-09-16'
16
+ s.version = '1.0.6'
17
+ s.date = '2013-10-23'
18
18
  s.rubyforge_project = 'newrelic_f5_plugin'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -51,7 +51,7 @@ This is the New Relic plugin for monitoring F5 devices developed by New Relic, I
51
51
  ## The newrelic_plugin needs to be installed. Prior to public release, the
52
52
  # gem needs to be downloaded from git@github.com:newrelic-platform/newrelic_plugin.git
53
53
  # and built using the "rake build" command
54
- s.add_dependency('newrelic_plugin', "= 1.0.2")
54
+ s.add_dependency('newrelic_plugin', "~> 1.3.0")
55
55
  s.add_dependency('snmp', ">= 1.1.0")
56
56
 
57
57
  s.post_install_message = <<-EOF
@@ -75,11 +75,14 @@ to find out how to install and run the plugin agent.
75
75
  config/newrelic_plugin.yml
76
76
  lib/newrelic_f5_plugin.rb
77
77
  lib/newrelic_f5_plugin/agent.rb
78
+ lib/newrelic_f5_plugin/device.rb
78
79
  lib/newrelic_f5_plugin/nodes.rb
79
80
  lib/newrelic_f5_plugin/pools.rb
81
+ lib/newrelic_f5_plugin/util.rb
80
82
  lib/newrelic_f5_plugin/virtuals.rb
81
83
  newrelic_f5_plugin.gemspec
82
84
  test/f5_monitor_test.rb
85
+ test/nodes_test.rb
83
86
  test/plugin_test.rb
84
87
  test/test_helper.rb
85
88
  ]
@@ -0,0 +1,72 @@
1
+ require 'test_helper.rb'
2
+ require 'snmp'
3
+
4
+ #
5
+ # Custom transport, based on the snmp test suite
6
+ # https://github.com/hallidave/ruby-snmp/
7
+ #
8
+ class NodeTransport
9
+ def initialize
10
+ end
11
+
12
+ def close
13
+ end
14
+
15
+ def send(data, host, port)
16
+ @data = data
17
+ end
18
+
19
+ def recv(max_bytes)
20
+ SNMP::Message.decode(@data).response.encode[0,max_bytes]
21
+ end
22
+ end
23
+
24
+
25
+ class NodeTest < Test::Unit::TestCase
26
+
27
+ include SNMP
28
+
29
+ def setup
30
+ @manager = Manager.new(:Transport => NodeTransport.new)
31
+ @status = {
32
+ :empty => {
33
+ "Nodes/Monitor Status/checking" => {:count=>0, :label=>"nodes"},
34
+ "Nodes/Monitor Status/disabled" => {:count=>0, :label=>"nodes"},
35
+ "Nodes/Monitor Status/down" => {:count=>0, :label=>"nodes"},
36
+ "Nodes/Monitor Status/down-manual-resume" => {:count=>0, :label=>"nodes"},
37
+ "Nodes/Monitor Status/forced-down" => {:count=>0, :label=>"nodes"},
38
+ "Nodes/Monitor Status/forced-up" => {:count=>0, :label=>"nodes"},
39
+ "Nodes/Monitor Status/inband" => {:count=>0, :label=>"nodes"},
40
+ "Nodes/Monitor Status/inband-down" => {:count=>0, :label=>"nodes"},
41
+ "Nodes/Monitor Status/irule-down" => {:count=>0, :label=>"nodes"},
42
+ "Nodes/Monitor Status/maint" => {:count=>0, :label=>"nodes"},
43
+ "Nodes/Monitor Status/unchecked" => {:count=>0, :label=>"nodes"},
44
+ "Nodes/Monitor Status/up" => {:count=>0, :label=>"nodes"},
45
+ },
46
+ }
47
+ end
48
+
49
+ def teardown
50
+ @manager.close
51
+ end
52
+
53
+
54
+
55
+ def test_init
56
+ @nodes = NewRelic::F5Plugin::Nodes.new @manager
57
+ assert_equal(@manager, @nodes.snmp_manager)
58
+ end
59
+
60
+ def test_get_status_default
61
+ @nodes = NewRelic::F5Plugin::Nodes.new @manager
62
+ @node_status = @nodes.get_status
63
+ assert_equal(@node_status, @status[:empty])
64
+ end
65
+
66
+ def test_get_status_args
67
+ @nodes = NewRelic::F5Plugin::Nodes.new @manager
68
+ @node_status = @nodes.get_status @manager
69
+ assert_equal(@node_status, @status[:empty])
70
+ end
71
+ end
72
+
data/test/plugin_test.rb CHANGED
@@ -13,17 +13,18 @@ newrelic:
13
13
  agents:
14
14
  f5:
15
15
  -
16
- name: 'My F5 LTM'
17
16
  hostname: 'my-f5'
18
17
  port: 161
19
18
  snmp_community: 'public'
20
- EOF
19
+ EOF
21
20
  NewRelic::Plugin::Setup.install_agent :f5, NewRelic::F5Plugin
22
21
  end
23
22
 
24
23
  should "create a run" do
25
24
  # The run loop is stubbed out so this just verifies the agent initializes correctly.
26
25
  NewRelic::Plugin::Run.any_instance.expects :setup_from_config
26
+ NewRelic::Plugin::Run.any_instance.expects :setup_no_config_agents
27
+ NewRelic::Plugin::Run.any_instance.expects :agent_startup
27
28
  NewRelic::Plugin::Run.any_instance.expects :loop_forever
28
29
  NewRelic::F5Plugin.run
29
30
  end
@@ -40,37 +41,9 @@ agents:
40
41
  end
41
42
 
42
43
  should "have one configured agent" do
43
- assert_equal "My F5 LTM", @agent.name
44
+ assert_equal "my-f5", @agent.hostname
44
45
  end
45
46
 
46
- #context "test db" do
47
- # setup do
48
- # # Setup a test database
49
- # @client = Mysql2::Client.new :host => 'localhost', :username => 'root'
50
- # @client.query "create database nr_mysql_plugin" rescue nil
51
- # @client.query "create table nr_mysql_plugin.example (id int)"
52
- # @client.query "create table nr_mysql_plugin.ignored (id int)"
53
- # @client.query "insert into nr_mysql_plugin.example values (1),(2),(3),(4),(5)"
54
- # end
55
- # teardown do
56
- # @client.query "drop database nr_mysql_plugin" rescue nil
57
- # end
58
- # should "get table stats" do
59
- # schemas = @agent.mysql_table_stats
60
- # assert_equal 1, schemas.size
61
- # tables = schemas['nr_mysql_plugin']
62
- # assert_equal 1, tables.size
63
- # rec = tables.first
64
- # assert_equal "example", rec.name
65
- # assert_equal 5, rec.rows
66
- # end
67
- # should "poll" do
68
- # # This stubs out the remote connection--we're not testing the plugin agent here
69
- # NewRelic::Plugin::DataCollector.any_instance.stubs :process
70
- # @agent.run 60 # seconds
71
- # end
72
- #end
73
-
74
47
  end
75
48
 
76
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newrelic_f5_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-16 00:00:00.000000000 Z
12
+ date: 2013-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: newrelic_plugin
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - '='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.0.2
21
+ version: 1.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - '='
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.0.2
29
+ version: 1.3.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: snmp
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -66,11 +66,14 @@ files:
66
66
  - config/newrelic_plugin.yml
67
67
  - lib/newrelic_f5_plugin.rb
68
68
  - lib/newrelic_f5_plugin/agent.rb
69
+ - lib/newrelic_f5_plugin/device.rb
69
70
  - lib/newrelic_f5_plugin/nodes.rb
70
71
  - lib/newrelic_f5_plugin/pools.rb
72
+ - lib/newrelic_f5_plugin/util.rb
71
73
  - lib/newrelic_f5_plugin/virtuals.rb
72
74
  - newrelic_f5_plugin.gemspec
73
75
  - test/f5_monitor_test.rb
76
+ - test/nodes_test.rb
74
77
  - test/plugin_test.rb
75
78
  - test/test_helper.rb
76
79
  homepage: http://newrelic.com