Class: NewRelic::F5Plugin::Virtuals

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

Constant Summary collapse

MAX_RESULTS =
150
OID_LTM_VIRTUAL_SERVERS =
"1.3.6.1.4.1.3375.2.2.10"
OID_LTM_VIRTUAL_SERV_STAT =
"#{OID_LTM_VIRTUAL_SERVERS}.2"
OID_LTM_VIRTUAL_SERV_ENTRY =
"#{OID_LTM_VIRTUAL_SERV_STAT}.3.1"
OID_LTM_VIRTUAL_SERV_STAT_NAME =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.1"
OID_LTM_VIRTUAL_SERV_STAT_CLIENT_PKTS_IN =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.6"
OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_IN =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.7"
OID_LTM_VIRTUAL_SERV_STAT_CLIENT_PKTS_OUT =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.8"
OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_OUT =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.9"
OID_LTM_VIRTUAL_SERV_STAT_CLIENT_TOT_CONNS =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.11"
OID_LTM_VIRTUAL_SERV_STAT_CLIENT_CUR_CONNS =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.12"
OID_LTM_VIRTUAL_SERV_STAT_TOT_REQUESTS =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.27"
OID_LTM_VIRTUAL_SERV_STAT_VS_USAGE_RATIO_1M =
"#{OID_LTM_VIRTUAL_SERV_ENTRY}.32"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snmp = nil) ⇒ Virtuals

Init



66
67
68
69
70
71
72
73
74
75
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 66

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.



45
46
47
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 45

def names
  @names
end

#snmp_managerObject

Returns the value of attribute snmp_manager.



45
46
47
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 45

def snmp_manager
  @snmp_manager
end

Instance Method Details

#get_conns_current(snmp = nil) ⇒ Object

Gather VS Connection count



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 157

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

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Virtual Servers/Current Connections", @names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_CUR_CONNS, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: 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 VS Connection rate



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 178

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("Virtual Servers/Connection Rate", @names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_TOT_CONNS, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: 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_cpu_usage_1m(snmp = nil) ⇒ Object

Gather VS Connection rate



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 318

def get_cpu_usage_1m(snmp = nil)
  snmp = @snmp_manager unless snmp

  get_names(snmp) if @names.empty?
  res = gather_snmp_metrics_by_name("Virtual Servers/CPU Usage/1m", @names, OID_LTM_VIRTUAL_SERV_STAT_VS_USAGE_RATIO_1M, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: Got #{res.size}/#{@names.size} CPU 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], "%", row[1]
      break if index >= (MAX_RESULTS - 1)
    end
  end
end

#get_names(snmp = nil) ⇒ Object

Get the list of Virtual Server names



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 103

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

  if snmp
    @names.clear

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

    NewRelic::PlatformLogger.debug("Virtual Servers: Found #{@names.size} virtual servers, reporting the top #{MAX_RESULTS} (max)")
    return @names
  end
end

#get_packets_in(snmp = nil) ⇒ Object

Gather VS Packets Inbound



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 206

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("Virtual Servers/Packets/In", @names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_PKTS_IN, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: 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 VS Packets Outbound



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 234

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("Virtual Servers/Packets/Out", @names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_PKTS_OUT, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: 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 VS Total Requests



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 129

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("Virtual Servers/Requests", @names, OID_LTM_VIRTUAL_SERV_STAT_TOT_REQUESTS, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: 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 VS Throughput Inbound (returns in bits)



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 262

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("Virtual Servers/Throughput/In", @names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_IN, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: 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 VS Throughput Outbound (returns in bits)



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 290

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("Virtual Servers/Throughput/Out", @names, OID_LTM_VIRTUAL_SERV_STAT_CLIENT_BYTES_OUT, snmp)
  NewRelic::PlatformLogger.debug("Virtual Servers: 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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/newrelic_f5_plugin/virtuals.rb', line 82

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
    get_cpu_usage_1m
  end
end