author | Mahlon E. Smith <mahlon@martini.nu> |
Sat, 01 Aug 2020 14:17:45 -0700 | |
changeset 29 | 40bcd1565627 |
parent 26 | 54f2f57cc0b0 |
permissions | -rw-r--r-- |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
1 |
# -*- ruby -*- |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
2 |
# vim: set noet nosta sw=4 ts=4 : |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
3 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
4 |
require 'arborist/monitor/snmp' unless defined?( Arborist::Monitor::SNMP ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
5 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
6 |
# Machine load/cpu checks. |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
7 |
# |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
8 |
# Sets current 1, 5, and 15 minute loads under the 'load' attribute, |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
9 |
# and calculates/warns on cpu overutilization. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
10 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
11 |
class Arborist::Monitor::SNMP::CPU |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
12 |
include Arborist::Monitor::SNMP |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
13 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
14 |
extend Configurability, Loggability |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
15 |
log_to :arborist_snmp |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
16 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
17 |
# OIDS for discovering system load. |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
18 |
# |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
19 |
OIDS = { |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
20 |
load: '1.3.6.1.4.1.2021.10.1.3', |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
21 |
cpu: '1.3.6.1.2.1.25.3.3.1.2' |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
22 |
} |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
23 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
24 |
# When walking load OIDS, the iterator count matches |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
25 |
# these labels. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
26 |
# |
19
77084121952b
Remove the unnecessary Hash.
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
27 |
LOADKEYS = %i[ load1 load5 load15 ] |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
28 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
29 |
|
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
30 |
# Global defaults for instances of this monitor |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
31 |
# |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
32 |
configurability( 'arborist.snmp.cpu' ) do |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
33 |
# What overutilization percentage qualifies as a warning |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
34 |
setting :warn_at, default: 80 |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
35 |
end |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
36 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
37 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
38 |
### Return the properties used by this monitor. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
39 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
40 |
def self::node_properties |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
41 |
return USED_PROPERTIES |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
42 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
43 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
44 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
45 |
### Class #run creates a new instance and immediately runs it. |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
46 |
### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
47 |
def self::run( nodes ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
48 |
return new.run( nodes ) |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
49 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
50 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
51 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
52 |
### Perform the monitoring checks. |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
53 |
### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
54 |
def run( nodes ) |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
55 |
super do |host, snmp| |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
56 |
self.find_load( host, snmp ) |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
57 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
58 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
59 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
60 |
|
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
61 |
######### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
62 |
protected |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
63 |
######### |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
64 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
65 |
### Find load data, add additional niceties for reporting. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
66 |
### |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
67 |
def format_load( snmp ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
68 |
info = { cpu: {}, load: {} } |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
69 |
cpus = snmp.walk( oid: OIDS[:cpu] ).each_with_object( [] ) do |(_, value), acc| |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
70 |
acc << value |
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
71 |
end |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
72 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
73 |
info[ :cpu ][ :count ] = cpus.size |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
74 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
75 |
# Windows SNMP doesn't have a concept of "load" over time, |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
76 |
# so we have to just use the current averaged CPU usage. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
77 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
78 |
# This means that windows machines will very likely want to |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
79 |
# adjust the default "overutilization" number, considering |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
80 |
# it's really just how much of the CPU is used at the time of |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
81 |
# the monitor run, along with liberal use of the Observer "only |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
82 |
# alert after X events" pragmas. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
83 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
84 |
if self.system =~ /windows\s+/i |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
85 |
info[ :cpu ][ :usage ] = cpus.inject( :+ ).to_f / cpus.size |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
86 |
info[ :message ] = "System is %0.1f%% in use." % [ info[ :cpu ][ :usage ] ] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
87 |
|
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
88 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
89 |
# UCDavis stuff is better for alerting only after there has been |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
90 |
# an extended load event. Use the 5 minute average to avoid |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
91 |
# state changes on transient spikes. |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
92 |
# |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
93 |
else |
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
94 |
snmp.walk( oid: OIDS[:load] ).each_with_index do |(_, value), idx| |
19
77084121952b
Remove the unnecessary Hash.
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
95 |
next unless LOADKEYS[ idx ] |
77084121952b
Remove the unnecessary Hash.
Mahlon E. Smith <mahlon@martini.nu>
parents:
14
diff
changeset
|
96 |
info[ :load ][ LOADKEYS[idx] ] = value.to_f |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
97 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
98 |
|
14
d5cb8bd33170
Although faster, once aiming a few thousand nodes at net-snmp2 it leaks memory like a sieve. Use 'netsnmp' instead.
Mahlon E. Smith <mahlon@martini.nu>
parents:
8
diff
changeset
|
99 |
percentage = (( ( info[:load][ :load5 ] / cpus.size) - 1 ) * 100 ).round( 1 ) |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
100 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
101 |
if percentage < 0 |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
102 |
info[ :message ] = "System is %0.1f%% idle." % [ percentage.abs ] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
103 |
info[ :cpu ][ :usage ] = percentage + 100 |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
104 |
else |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
105 |
info[ :message ] = "System is %0.1f%% overloaded." % [ percentage ] |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
106 |
info[ :cpu ][ :usage ] = percentage |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
107 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
108 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
109 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
110 |
return info |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
111 |
end |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
112 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
113 |
|
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
114 |
### Collect the load information for +host+ from an existing |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
115 |
### (and open) +snmp+ connection. |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
116 |
### |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
117 |
def find_load( host, snmp ) |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
118 |
info = self.format_load( snmp ) |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
119 |
|
26
54f2f57cc0b0
Automatically clear stale mounts from node properties during disk checks.
Mahlon E. Smith <mahlon@martini.nu>
parents:
19
diff
changeset
|
120 |
config = self.identifiers[ host ].last['config'] || {} |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
121 |
warn_at = config[ 'warn_at' ] || self.class.warn_at |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
122 |
usage = info.dig( :cpu, :usage ) || 0 |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
123 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
124 |
if usage >= warn_at |
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
125 |
info[ :warning ] = "%0.1f utilization exceeds %0.1f percent" % [ usage, warn_at ] |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
126 |
end |
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
127 |
|
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
128 |
self.results[ host ] = info |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
129 |
end |
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
130 |
|
8
e0b7c95a154f
Refactor for real world usage and latest Arborist behaviors.
Mahlon E. Smith <mahlon@martini.nu>
parents:
4
diff
changeset
|
131 |
end # class Arborist::Monitor::SNMP::CPU |
4
e6eb11b1e00d
Refactor. Move all SNMP "sections" to their own classes.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
132 |