Class: NewRelic::F5Plugin::Platform

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

Constant Summary collapse

OID_SYS_GLOBAL_HOST =

Create the OIDs if they do not exist

"1.3.6.1.4.1.3375.2.1.1.2.20"
OID_SYS_GLOBAL_HOST_CPU_COUNT =
"#{OID_SYS_GLOBAL_HOST}.4.0"
OID_SYS_GLOBAL_HOST_CPU_IDLE_1M =
"#{OID_SYS_GLOBAL_HOST}.25.0"
OID_SYS_GLOBAL_HOST_CPU_IOWAIT_1M =
"#{OID_SYS_GLOBAL_HOST}.28.0"
OID_SYS_GLOBAL_HOST_CPU_IRQ_1M =
"#{OID_SYS_GLOBAL_HOST}.26.0"
OID_SYS_GLOBAL_HOST_CPU_NICE_1M =
"#{OID_SYS_GLOBAL_HOST}.23.0"
OID_SYS_GLOBAL_HOST_CPU_SOFTIRQ_1M =
"#{OID_SYS_GLOBAL_HOST}.27.0"
OID_SYS_GLOBAL_HOST_CPU_SYSTEM_1M =
"#{OID_SYS_GLOBAL_HOST}.24.0"
OID_SYS_GLOBAL_HOST_CPU_USER_1M =
"#{OID_SYS_GLOBAL_HOST}.22.0"
OID_SYS_HOST_MEMORY_USED =
"1.3.6.1.4.1.3375.2.1.7.1.2.0"
OID_SYS_PLATFORM =
"1.3.6.1.4.1.3375.2.1.3"
OID_SYS_PLATFORM_INFO =
"#{OID_SYS_PLATFORM}.5"
OID_SYS_PLATFORM_INFO_NAME =
"#{OID_SYS_PLATFORM_INFO}.1.0"
OID_SYS_PLATFORM_INFO_MARKETING_NAME =
"#{OID_SYS_PLATFORM_INFO}.2.0"
OID_SYS_PRODUCT =
"1.3.6.1.4.1.3375.2.1.4"
OID_SYS_PRODUCT_NAME =
"#{OID_SYS_PRODUCT}.1.0"
OID_SYS_PRODUCT_VERSION =
"#{OID_SYS_PRODUCT}.2.0"
OID_SYS_PRODUCT_BUILD =
"#{OID_SYS_PRODUCT}.3.0"
OID_SYS_PRODUCT_EDITION =
"#{OID_SYS_PRODUCT}.4.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snmp = nil) ⇒ Platform

Init



38
39
40
41
42
43
44
45
46
# File 'lib/newrelic_f5_plugin/platform.rb', line 38

def initialize(snmp = nil)
  @version = 'Unknown!'

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

Instance Attribute Details

#snmp_managerObject

Returns the value of attribute snmp_manager.



10
11
12
# File 'lib/newrelic_f5_plugin/platform.rb', line 10

def snmp_manager
  @snmp_manager
end

Instance Method Details

#get_cpu(snmp = nil) ⇒ Object

Gather CPU Related metrics and report them in %



107
108
109
110
111
112
113
114
115
116
117
118
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
# File 'lib/newrelic_f5_plugin/platform.rb', line 107

def get_cpu(snmp = nil)
  metrics = { }
  snmp    = snmp_manager unless snmp

  if snmp
    res = gather_snmp_metrics_array([OID_SYS_GLOBAL_HOST_CPU_COUNT, OID_SYS_GLOBAL_HOST_CPU_USER_1M, OID_SYS_GLOBAL_HOST_CPU_NICE_1M,
                                     OID_SYS_GLOBAL_HOST_CPU_SYSTEM_1M, OID_SYS_GLOBAL_HOST_CPU_IRQ_1M, OID_SYS_GLOBAL_HOST_CPU_SOFTIRQ_1M,
                                     OID_SYS_GLOBAL_HOST_CPU_IOWAIT_1M],
                                     snmp)

    # Bail out if we didn't get anything
    return metrics if res.empty?

    # In order to show the CPU usage as a total percentage, we divide by the number of cpus for older versions
    case @version
    when /^11\.[0-4]\.0/
      cpu_count = res[0].to_i
    else
      # 11.4.1 HF3 reports average CPU not total, so don't divide by CPU count
      cpu_count = 1
    end

    vals = res[1..6].map { |i| i.to_f / cpu_count }

    metrics["CPU/Global/User"]     = vals[0]
    metrics["CPU/Global/Nice"]     = vals[1]
    metrics["CPU/Global/System"]   = vals[2]
    metrics["CPU/Global/IRQ"]      = vals[3]
    metrics["CPU/Global/Soft IRQ"] = vals[4]
    metrics["CPU/Global/IO Wait"]  = vals[5]

    # Add it all up, and send a summary metric
    metrics["CPU/Total/Global"] = vals.inject(0.0){ |a,b| a + b }

  end

  return metrics
end

#get_memory(snmp = nil) ⇒ Object

Gather Memory related metrics and report them in bytes



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/newrelic_f5_plugin/platform.rb', line 150

def get_memory(snmp = nil)
  metrics = { }
  snmp    = snmp_manager unless snmp

  if snmp
    res = gather_snmp_metrics_array([OID_SYS_HOST_MEMORY_USED], snmp)

    # Bail out if we didn't get anything
    return metrics if res.empty?

    metrics["Memory/Host"] = res[0]
  end

  return metrics
end

#get_platform_info(snmp = nil) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/newrelic_f5_plugin/platform.rb', line 89

def get_platform_info(snmp = nil)
  platform = "Unknown!"
  snmp     = snmp_manager unless snmp

  if snmp
    res = gather_snmp_metrics_array([OID_SYS_PLATFORM_INFO_MARKETING_NAME, OID_SYS_PLATFORM_INFO_NAME], snmp)

    platform = "#{res[0]} (#{res[1]})"
  end

  return platform
end

#get_version(snmp = nil) ⇒ Object

Gather Version information



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/newrelic_f5_plugin/platform.rb', line 74

def get_version(snmp = nil)
  version = "Unknown!"
  snmp    = snmp_manager unless snmp

  if snmp
    res = gather_snmp_metrics_array([OID_SYS_PRODUCT_VERSION, OID_SYS_PRODUCT_BUILD], snmp)

    version = "#{res[0]}.#{res[1]}" unless res.empty?
  end

  return version
end

#poll(agent, snmp) ⇒ Object

Perform polling and reportings of metrics



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/newrelic_f5_plugin/platform.rb', line 53

def poll(agent, snmp)
  @snmp_manager = snmp

  system_platform = get_platform_info
  @version        = get_version
  NewRelic::PlatformLogger.debug("Found a #{system_platform} running version #{@version}")


  system_cpu = get_cpu
  system_cpu.each_key { |m| agent.report_metric m, "%", system_cpu[m] } unless system_cpu.nil?

  system_memory = get_memory
  system_memory.each_key { |m| agent.report_metric m, "bytes", system_memory[m] } unless system_memory.nil?

end