# HG changeset patch # User Mahlon E. Smith # Date 1522873796 25200 # Node ID 6723f3b07536beadd9002dcdeccede0b4bb640ae # Parent 17400a52624bbfb779b90954f17504ce2d657c43 Swap was folded into the mempry module. diff -r 17400a52624b -r 6723f3b07536 Rakefile --- a/Rakefile Wed Apr 04 13:25:00 2018 -0700 +++ b/Rakefile Wed Apr 04 13:29:56 2018 -0700 @@ -111,7 +111,6 @@ __END__ lib/arborist/snmp.rb lib/arborist/monitor/snmp.rb -lib/arborist/monitor/snmp/swap.rb lib/arborist/monitor/snmp/disk.rb lib/arborist/monitor/snmp/process.rb lib/arborist/monitor/snmp/memory.rb diff -r 17400a52624b -r 6723f3b07536 lib/arborist/monitor/snmp/swap.rb --- a/lib/arborist/monitor/snmp/swap.rb Wed Apr 04 13:25:00 2018 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -# -*- ruby -*- -# vim: set noet nosta sw=4 ts=4 : - -require 'arborist/monitor/snmp' unless defined?( Arborist::Monitor::SNMP ) - -# SNMP swap usage checks. -# Returns swap used in a 'swap_in_use' attribute. -# -class Arborist::Monitor::SNMP::Swap - include Arborist::Monitor::SNMP - - extend Loggability - log_to :arborist - - # Global defaults for instances of this monitor - # - DEFAULT_OPTIONS = { - error_at: 95, # in percent full - } - - # OIDS for discovering memory usage. - # - MEMORY = { - swap_total: '1.3.6.1.4.1.2021.4.3.0', - swap_avail: '1.3.6.1.4.1.2021.4.4.0', - } - - - ### This monitor is complex enough to require creating an instance from the caller. - ### Provide a friendlier error message the class was provided to exec() directly. - ### - def self::run( nodes ) - return new.run( nodes ) - end - - - ### Create a new instance of this monitor. - ### - def initialize( options=DEFAULT_OPTIONS ) - options = DEFAULT_OPTIONS.merge( options || {} ) - options.each do |name, value| - self.public_send( "#{name.to_s}=", value ) - end - end - - # Set an error if used swap exceeds this percentage. - attr_accessor :error_at - - - ### Perform the monitoring checks. - ### - def run( nodes ) - super do |snmp, host| - self.gather_swap( snmp, host ) - end - end - - - ######### - protected - ######### - - ### Collect used swap information for +host+ from an existing (and - ### open) +snmp+ connection. - ### - def gather_swap( snmp, host ) - self.log.debug "Getting used swap for: %s" % [ host ] - - swap_total = snmp.get( SNMP::ObjectId.new(MEMORY[:swap_total]) ).varbind_list.first.value.to_f - swap_avail = snmp.get( SNMP::ObjectId.new(MEMORY[:swap_avail]) ).varbind_list.first.value.to_f - swap_in_use = (( swap_avail.to_f / swap_total * 100 ) - 100 ).abs - self.log.debug " Swap in use on %s: %0.1f%%" % [ host, swap_in_use ] - - config = @identifiers[ host ].last || {} - if swap_in_use >= ( config['error_at'] || self.error_at ) - @results[ host ] = { - error: "%0.1f%% swap in use" % [ swap_in_use ], - swap_in_use: swap_avail - } - else - @results[ host ] = { swap_in_use: swap_in_use } - end - end - -end # class Arborist::Monitor::SNMP::Swap -