Class: NewRelic::F5Plugin::Interfaces

Inherits:
Object
  • Object
show all
Defined in:
lib/newrelic_f5_plugin/interfaces.rb

Constant Summary collapse

INTERFACE_ENABLED_STATES =
{
  0 => 'Disabled',
  1 => 'Enabled',
}
INTERFACE_STATUS_STATES =
{
  0 => 'Up',
  1 => 'Down',
  3 => 'Uninitialized',
  5 => 'Unpopulated',
}
INTERFACE_DUPLEX_STATES =
{
  0 => 'None',
  1 => 'Half',
  2 => 'Full',
}
OID_SYS_INTERFACES =
"1.3.6.1.4.1.3375.2.1.2.4"
OID_SYS_INTERFACE =

Config

"#{OID_SYS_INTERFACES}.1"
OID_SYS_INTERFACE_ENTRY =
"#{OID_SYS_INTERFACE}.2.1"
OID_SYS_INTERFACE_NAME =
"#{OID_SYS_INTERFACE_ENTRY}.1"
OID_SYS_INTERFACE_MEDIA_MAX_SPEED =
"#{OID_SYS_INTERFACE_ENTRY}.2"
OID_SYS_INTERFACE_MEDIA_MAX_DUPLEX =
"#{OID_SYS_INTERFACE_ENTRY}.3"
OID_SYS_INTERFACE_MEDIA_ACTIVE_SPEED =
"#{OID_SYS_INTERFACE_ENTRY}.4"
OID_SYS_INTERFACE_MEDIA_ACTIVE_DUPLEX =
"#{OID_SYS_INTERFACE_ENTRY}.5"
OID_SYS_INTERFACE_MAC_ADDR =
"#{OID_SYS_INTERFACE_ENTRY}.6"
OID_SYS_INTERFACE_MTU =
"#{OID_SYS_INTERFACE_ENTRY}.7"
OID_SYS_INTERFACE_ENABLED =
"#{OID_SYS_INTERFACE_ENTRY}.8"
OID_SYS_INTERFACE_STATUS =
"#{OID_SYS_INTERFACE_ENTRY}.17"
OID_SYS_INTERFACE_STAT =

Stats

"#{OID_SYS_INTERFACES}.4"
OID_SYS_INTERFACE_STAT_ENTRY =
"#{OID_SYS_INTERFACE_STAT}.3.1"
OID_SYS_INTERFACE_STAT_NAME =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.1"
OID_SYS_INTERFACE_STAT_PKTS_IN =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.2"
OID_SYS_INTERFACE_STAT_BYTES_IN =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.3"
OID_SYS_INTERFACE_STAT_PKTS_OUT =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.4"
OID_SYS_INTERFACE_STAT_BYTES_OUT =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.5"
OID_SYS_INTERFACE_STAT_MCAST_IN =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.6"
OID_SYS_INTERFACE_STAT_MCAST_OUT =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.7"
OID_SYS_INTERFACE_STAT_ERRORS_IN =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.8"
OID_SYS_INTERFACE_STAT_ERRORS_OUT =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.9"
OID_SYS_INTERFACE_STAT_DROPS_IN =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.10"
OID_SYS_INTERFACE_STAT_DROPS_OUT =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.11"
OID_SYS_INTERFACE_STAT_COLLISIONS =
"#{OID_SYS_INTERFACE_STAT_ENTRY}.12"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snmp = nil) ⇒ Interfaces

Init



104
105
106
107
108
109
110
111
112
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 104

def initialize(snmp = nil)
  @names = [ ]

  if snmp
    @snmp_manager = snmp
  else
    @snmp_manager = nil
  end
end

Instance Attribute Details

#namesObject

Returns the value of attribute names.



48
49
50
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 48

def names
  @names
end

#snmp_managerObject

Returns the value of attribute snmp_manager.



48
49
50
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 48

def snmp_manager
  @snmp_manager
end

Instance Method Details

#get_collisions(snmp = nil) ⇒ Object

Gather Collisions



334
335
336
337
338
339
340
341
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 334

def get_collisions(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Collisions", @names, OID_SYS_INTERFACE_STAT_COLLISIONS, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Collision metrics")
  return res
end

#get_drops_in(snmp = nil) ⇒ Object

Gather Drops Inbound



306
307
308
309
310
311
312
313
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 306

def get_drops_in(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Drops/In", @names, OID_SYS_INTERFACE_STAT_DROPS_IN, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Inbound drop metrics")
  return res
end

#get_drops_out(snmp = nil) ⇒ Object

Gather Drops Outbound



320
321
322
323
324
325
326
327
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 320

def get_drops_out(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Drops/Out", @names, OID_SYS_INTERFACE_STAT_DROPS_OUT, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Outbound drop metrics")
  return res
end

#get_errors_in(snmp = nil) ⇒ Object

Gather Errors Inbound



278
279
280
281
282
283
284
285
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 278

def get_errors_in(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Errors/In", @names, OID_SYS_INTERFACE_STAT_ERRORS_IN, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Inbound error metrics")
  return res
end

#get_errors_out(snmp = nil) ⇒ Object

Gather Errors Outbound



292
293
294
295
296
297
298
299
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 292

def get_errors_out(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Errors/Out", @names, OID_SYS_INTERFACE_STAT_ERRORS_OUT, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Outbound error metrics")
  return res
end

#get_mcast_in(snmp = nil) ⇒ Object

Gather Multicast Packets Inbound



250
251
252
253
254
255
256
257
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 250

def get_mcast_in(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Multicast/In", @names, OID_SYS_INTERFACE_STAT_MCAST_IN, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Inbound multicast metrics")
  return res
end

#get_mcast_out(snmp = nil) ⇒ Object

Gather Multicast Packets Outbound



264
265
266
267
268
269
270
271
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 264

def get_mcast_out(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Multicast/Out", @names, OID_SYS_INTERFACE_STAT_MCAST_OUT, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Outbound multicast metrics")
  return res
end

#get_names(snmp = nil) ⇒ Object

Get the list of Interface names



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 166

def get_names(snmp = nil)
  snmp = snmp_manager unless snmp

  if snmp
    @names.clear

    begin
      snmp.walk([OID_SYS_INTERFACE_NAME]) do |row|
        row.each do |vb|
          @names.push(vb.value)
        end
      end
    rescue Exception => e
      NewRelic::PlatformLogger.error("Unable to gather Interface names with error: #{e}")
    end

    NewRelic::PlatformLogger.debug("Interfaces: Found #{@names.size} interfaces")
    return @names
  end
end

#get_packets_in(snmp = nil) ⇒ Object

Gather Packets Inbound



222
223
224
225
226
227
228
229
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 222

def get_packets_in(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Packets/In", @names, OID_SYS_INTERFACE_STAT_PKTS_IN, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Inbound packet metrics")
  return res
end

#get_packets_out(snmp = nil) ⇒ Object

Gather Packets Outbound



236
237
238
239
240
241
242
243
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 236

def get_packets_out(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Packets/Out", @names, OID_SYS_INTERFACE_STAT_PKTS_OUT, snmp)
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Outbound packet metrics")
  return res
end

#get_status(snmp = nil) ⇒ Object

Gather Interface Status



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 348

def get_status(snmp = nil)
  snmp = snmp_manager unless snmp
  metrics = { }
  counter = 0

  if snmp
    # Init all the states with zeros so we always get them
    base_name = "Interfaces/Status"
    INTERFACE_STATUS_STATES.each do |key,value|
      metrics["#{base_name}/#{value}"] = { :label => "interfaces", :count => 0 }
    end

    # ltmNodeAddrMonitorStatus
    begin
      snmp.walk([OID_SYS_INTERFACE_STATUS]) do |row|
        row.each do |vb|
          metric_name = "#{base_name}/#{INTERFACE_STATUS_STATES[vb.value.to_i]}"
          metrics[metric_name][:count]  += 1
          counter += 1
        end
      end
    rescue Exception => e
      NewRelic::PlatformLogger.error("Unable to gather Interface status metrics with error: #{e}")
    end
  end

  NewRelic::PlatformLogger.debug("Interfaces: Got #{counter} Status metrics")
  return metrics
end

#get_throughput_in(snmp = nil) ⇒ Object

Gather Throughput Inbound (returns in bits)



192
193
194
195
196
197
198
199
200
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 192

def get_throughput_in(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Throughput/In", @names, OID_SYS_INTERFACE_STAT_BYTES_IN, snmp)
  res = res.each_key { |n| res[n] *= 8 }
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Inbound Throughput metrics")
  return res
end

#get_throughput_out(snmp = nil) ⇒ Object

Gather Throughput Inbound (returns in bits)



207
208
209
210
211
212
213
214
215
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 207

def get_throughput_out(snmp = nil)
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Interfaces/Throughput/Out", @names, OID_SYS_INTERFACE_STAT_BYTES_OUT, snmp)
  res = res.each_key { |n| res[n] *= 8 }
  NewRelic::PlatformLogger.debug("Interfaces: Got #{res.size}/#{@names.size} Outbound Throughput metrics")
  return res
end

#poll(agent, snmp) ⇒ Object

Perform polling and reportings of metrics



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/newrelic_f5_plugin/interfaces.rb', line 119

def poll(agent, snmp)
  @snmp_manager = snmp

  unless get_names.empty?
    throughput_in = get_throughput_in
    throughput_in.each_key { |m| agent.report_counter_metric m, "bits/sec", throughput_in[m] } unless throughput_in.nil?

    throughput_out = get_throughput_out
    throughput_out.each_key { |m| agent.report_counter_metric m, "bits/sec", throughput_out[m] } unless throughput_out.nil?

    packets_in = get_packets_in
    packets_in.each_key { |m| agent.report_counter_metric m, "pkts/sec", packets_in[m] } unless packets_in.nil?

    packets_out = get_packets_out
    packets_out.each_key { |m| agent.report_counter_metric m, "pkts/sec", packets_out[m] } unless packets_out.nil?

    mcast_in = get_mcast_in
    mcast_in.each_key { |m| agent.report_counter_metric m, "pkts/sec", mcast_in[m] } unless mcast_in.nil?

    mcast_out = get_mcast_out
    mcast_out.each_key { |m| agent.report_counter_metric m, "pkts/sec", mcast_out[m] } unless mcast_out.nil?

    errors_in = get_errors_in
    errors_in.each_key { |m| agent.report_counter_metric m, "errors/sec", errors_in[m] } unless errors_in.nil?

    errors_out = get_errors_out
    errors_out.each_key { |m| agent.report_counter_metric m, "errors/sec", errors_out[m] } unless errors_out.nil?

    drops_in = get_drops_in
    drops_in.each_key { |m| agent.report_counter_metric m, "drops/sec", drops_in[m] } unless drops_in.nil?

    drops_out = get_drops_out
    drops_out.each_key { |m| agent.report_counter_metric m, "drops/sec", drops_out[m] } unless drops_out.nil?

    collisions = get_collisions
    collisions.each_key { |m| agent.report_counter_metric m, "collisions/sec", collisions[m] } unless collisions.nil?

    status = get_status
    status.each_key { |m| agent.report_metric m, status[m][:label], status[m][:count] } unless status.nil?
  end
end