Class: NewRelic::F5Plugin::Pools

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

Constant Summary collapse

MAX_RESULTS =
150
OID_LTM_POOLS =
"1.3.6.1.4.1.3375.2.2.5"
OID_LTM_POOL_STAT =
"#{OID_LTM_POOLS}.2"
OID_LTM_POOL_ENTRY =
"#{OID_LTM_POOL_STAT}.3.1"
OID_LTM_POOL_STAT_NAME =
"#{OID_LTM_POOL_ENTRY}.1"
OID_LTM_POOL_STAT_SERVER_PKTS_IN =
"#{OID_LTM_POOL_ENTRY}.2"
OID_LTM_POOL_STAT_SERVER_BYTES_IN =
"#{OID_LTM_POOL_ENTRY}.3"
OID_LTM_POOL_STAT_SERVER_PKTS_OUT =
"#{OID_LTM_POOL_ENTRY}.4"
OID_LTM_POOL_STAT_SERVER_BYTES_OUT =
"#{OID_LTM_POOL_ENTRY}.5"
OID_LTM_POOL_STAT_SERVER_TOT_CONNS =
"#{OID_LTM_POOL_ENTRY}.7"
OID_LTM_POOL_STAT_SERVER_CUR_CONNS =
"#{OID_LTM_POOL_ENTRY}.8"
OID_LTM_POOL_STAT_TOT_REQUESTS =
"#{OID_LTM_POOL_ENTRY}.30"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snmp = nil) ⇒ Pools

Init



63
64
65
66
67
68
69
70
71
72
# File 'lib/newrelic_f5_plugin/pools.rb', line 63

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

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

Instance Attribute Details

#namesObject

Returns the value of attribute names.



43
44
45
# File 'lib/newrelic_f5_plugin/pools.rb', line 43

def names
  @names
end

#snmp_managerObject

Returns the value of attribute snmp_manager.



43
44
45
# File 'lib/newrelic_f5_plugin/pools.rb', line 43

def snmp_manager
  @snmp_manager
end

Instance Method Details

#get_conns_current(snmp = nil) ⇒ Object

Gather Connection count



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/newrelic_f5_plugin/pools.rb', line 153

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

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Pools/Current Connections", @names, OID_LTM_POOL_STAT_SERVER_CUR_CONNS, snmp)
  NewRelic::PlatformLogger.debug("Pools: Got #{res.size}/#{@names.size} Current Connection metrics")

  unless res.nil?
    sorted_report = res.sort_by { |k,v| v }.reverse
    sorted_report.each_with_index do |row, index|
      @f5_agent.report_metric row[0], "conns", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#get_conns_total(snmp = nil) ⇒ Object

Gather Connection rate



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/newrelic_f5_plugin/pools.rb', line 174

def get_conns_total(snmp = nil)
  @conn_rate ||= { }
  report       = { }
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Pools/Connection Rate", @names, OID_LTM_POOL_STAT_SERVER_TOT_CONNS, snmp)
  NewRelic::PlatformLogger.debug("Pools: Got #{res.size}/#{@names.size} Connection Rate metrics")

  unless res.nil?
    res.each_key do |metric|
      @conn_rate[metric] ||= NewRelic::Processor::EpochCounter.new
      report[metric] = @conn_rate[metric].process(res[metric])
    end

    sorted_report = report.sort_by { |k,v| v }.reverse
    sorted_report.each_with_index do |row, index|
      @f5_agent.report_metric row[0], "conn/sec", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#get_names(snmp = nil) ⇒ Object

Get the list of Pool names



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/newrelic_f5_plugin/pools.rb', line 99

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

  if snmp
    @names.clear

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

    NewRelic::PlatformLogger.debug("Pools: Found #{@names.size} pools, reporting the top #{MAX_RESULTS} (max)")
    return @names
  end
end

#get_packets_in(snmp = nil) ⇒ Object

Gather Packets Inbound



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/newrelic_f5_plugin/pools.rb', line 202

def get_packets_in(snmp = nil)
  @packet_in_rate ||= { }
  report            = { }
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Pools/Packets/In", @names, OID_LTM_POOL_STAT_SERVER_PKTS_IN, snmp)
  NewRelic::PlatformLogger.debug("Pools: Got #{res.size}/#{@names.size} Inbound Packet metrics")

  unless res.nil?
    res.each_key do |metric|
      @packet_in_rate[metric] ||= NewRelic::Processor::EpochCounter.new
      report[metric] = @packet_in_rate[metric].process(res[metric] * 8)
    end

    sorted_report = report.sort_by { |k,v| v }.reverse
    sorted_report.each_with_index do |row, index|
      @f5_agent.report_metric row[0], "packets/sec", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#get_packets_out(snmp = nil) ⇒ Object

Gather Packets Outbound



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/newrelic_f5_plugin/pools.rb', line 230

def get_packets_out(snmp = nil)
  @packet_out_rate ||= { }
  report             = { }
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Pools/Packets/Out", @names, OID_LTM_POOL_STAT_SERVER_PKTS_OUT, snmp)
  NewRelic::PlatformLogger.debug("Pools: Got #{res.size}/#{@names.size} Outbound Packet metrics")

  unless res.nil?
    res.each_key do |metric|
      @packet_out_rate[metric] ||= NewRelic::Processor::EpochCounter.new
      report[metric] = @packet_out_rate[metric].process(res[metric] * 8)
    end

    sorted_report = report.sort_by { |k,v| v }.reverse
    sorted_report.each_with_index do |row, index|
      @f5_agent.report_metric row[0], "packets/sec", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#get_requests(snmp = nil) ⇒ Object

Gather Total Requests



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/newrelic_f5_plugin/pools.rb', line 125

def get_requests(snmp = nil)
  @req_rate ||= { }
  report      = { }
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Pools/Requests", @names, OID_LTM_POOL_STAT_TOT_REQUESTS, snmp)
  NewRelic::PlatformLogger.debug("Pools: Got #{res.size}/#{@names.size} Request metrics")

  unless res.nil?
    res.each_key do |metric|
      @req_rate[metric] ||= NewRelic::Processor::EpochCounter.new
      report[metric] = @req_rate[metric].process(res[metric])
    end

    sorted_report = report.sort_by { |k,v| v }.reverse
    sorted_report.each_with_index do |row, index|
      @f5_agent.report_metric row[0], "req/sec", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#get_throughput_in(snmp = nil) ⇒ Object

Gather Throughput Inbound (returns in bits)



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/newrelic_f5_plugin/pools.rb', line 258

def get_throughput_in(snmp = nil)
  @throughput_in_rate ||= { }
  report                = { }
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Pools/Throughput/In", @names, OID_LTM_POOL_STAT_SERVER_BYTES_IN, snmp)
  NewRelic::PlatformLogger.debug("Pools: Got #{res.size}/#{@names.size} Inbound Throughput metrics")

  unless res.nil?
    res.each_key do |metric|
      @throughput_in_rate[metric] ||= NewRelic::Processor::EpochCounter.new
      report[metric] = @throughput_in_rate[metric].process(res[metric] * 8)
    end

    sorted_report = report.sort_by { |k,v| v }.reverse
    sorted_report.each_with_index do |row, index|
      @f5_agent.report_metric row[0], "bits/sec", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#get_throughput_out(snmp = nil) ⇒ Object

Gather Throughput Outbound (returns in bits)



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/newrelic_f5_plugin/pools.rb', line 286

def get_throughput_out(snmp = nil)
  @throughput_out_rate ||= { }
  report                 = { }
  snmp = snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Pools/Throughput/Out", @names, OID_LTM_POOL_STAT_SERVER_BYTES_OUT, snmp)
  NewRelic::PlatformLogger.debug("Pools: Got #{res.size}/#{@names.size} Outbound Throughput metrics")

  unless res.nil?
    res.each_key do |metric|
      @throughput_out_rate[metric] ||= NewRelic::Processor::EpochCounter.new
      report[metric] = @throughput_out_rate[metric].process(res[metric] * 8)
    end

    sorted_report = report.sort_by { |k,v| v }.reverse
    sorted_report.each_with_index do |row, index|
      @f5_agent.report_metric row[0], "bits/sec", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#poll(agent, snmp) ⇒ Object

Perform polling and reportings of metrics



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/newrelic_f5_plugin/pools.rb', line 79

def poll(agent, snmp)
  @snmp_manager = snmp
  @f5_agent     = agent

  unless get_names.empty?
    get_requests
    get_conns_current
    get_conns_total
    get_packets_in
    get_packets_out
    get_throughput_in
    get_throughput_out
  end
end