Top Level Namespace

Defined Under Namespace

Modules: NewRelic

Instance Method Summary collapse

Instance Method Details

#bytes_to_bits(vals) ⇒ Object

Convert bytes to bits



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/newrelic_f5_plugin/util.rb', line 88

def bytes_to_bits(vals)
  ret = nil

  if vals.class == Array
    ret = vals.map { |i| i.to_f * 8 }
  elsif vals.class == Hash
    ret = { }
    vals.keys.each do |k,v|
      if v.nil?
        ret[k] = v
      else
        ret[k] = v.to_f * 8
      end
    end
  end

  return ret
end

#gather_snmp_metrics_array(oids, snmp) ⇒ Object

Return all of the OID values in an array



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/newrelic_f5_plugin/util.rb', line 55

def gather_snmp_metrics_array(oids, snmp)
  metrics = [ ]

  if oids.nil? or oids.empty?
    NewRelic::PlatformLogger.debug("Invalid oids passed to gather_snmp_metrics_array")
    return metrics
  end

  # Convert to Array if not passed as one
  oids = [oids] if not oids.kind_of?(Array)

  if snmp
    begin
      metrics = snmp.get_value(oids).map do |val|
        # If an OID is missing, just return zero for that metric
        if val.to_s == 'noSuchObject'
          0
        else
          val
        end
      end
    rescue Exception => e
      NewRelic::PlatformLogger.error("Unable to gather SNMP metrics with error: #{e}")
    end
  end

  return metrics
end

#gather_snmp_metrics_by_name(metric_prefix, metric_names, oids, snmp) ⇒ Object

Walk the SNMP OIDs



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/newrelic_f5_plugin/util.rb', line 11

def gather_snmp_metrics_by_name(metric_prefix, metric_names, oids, snmp)
  metrics = { }
  index   = 0

  if metric_prefix.nil? or metric_prefix.empty?
    NewRelic::PlatformLogger.debug("Invalid metric_prefix passed to gather_snmp_metrics_by_name")
    return metrics
  end

  if metric_names.nil? or metric_names.empty? or not metric_names.kind_of?(Array)
    NewRelic::PlatformLogger.debug("Invalid metric_names passed to gather_snmp_metrics_by_name")
    return metrics
  end

  if oids.nil? or oids.empty?
    NewRelic::PlatformLogger.debug("Invalid oids passed to gather_snmp_metrics_by_name")
    return metrics
  end

  # Convert to Array if not passed as one
  oids = [oids] if not oids.kind_of?(Array)

  metric_prefix = "#{metric_prefix}/" unless metric_prefix.end_with?("/")

  if snmp
    begin
      snmp.walk(oids) do |row|
        row.each do |vb|
          metrics["#{metric_prefix}#{metric_names[index]}"] = vb.value.to_i
          index += 1
        end
      end
    rescue Exception => e
      NewRelic::PlatformLogger.error("Unable to gather SNMP metrics with error: #{e}")
    end
  end

  return metrics
end