Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated load averages to take option for number of processors

  • Loading branch information...
commit 0aece8044bf7ccc92ef7df86a3900286afb77f1f 1 parent 7c99292
Andre Lewis authored
Showing with 41 additions and 14 deletions.
  1. +41 −7 load_averages/load_averages.rb
  2. +0 −7 load_averages/load_averages.yml
View
48 load_averages/load_averages.rb
@@ -1,15 +1,49 @@
+#
+# Modified load_averages to show load/processor, as this is a more accurate
+# measurement of CPU utilization.
+#
+# Requires /proc/cpuinfo
+#
class LoadAverages < Scout::Plugin
- TEST_USAGE = "#{File.basename($0)} max_load MAX_LOAD"
+
+ OPTIONS=<<-EOS
+ num_processors:
+ name: Number of Processors
+ notes: For calculating CPU load. If left blank, autodetects through /proc/cpuinfo
+ default: 1
+ EOS
def build_report
if `uptime` =~ /load average(s*): ([\d.]+)(,*) ([\d.]+)(,*) ([\d.]+)\Z/
- report :last_minute => $2,
- :last_five_minutes => $4,
- :last_fifteen_minutes => $6
+ report :last_minute => $2.to_f/num_processors,
+ :last_five_minutes => $4.to_f/num_processors,
+ :last_fifteen_minutes => $6.to_f/num_processors
else
- raise "Unexpected output format"
+ raise "Couldn't use `uptime` as expected."
end
rescue Exception
- error "Couldn't use `uptime` as expected.", $!.message
+ error "Error determining load", $!.message
+ end
+
+ def num_processors
+ # first, check if the options provided is > 0. So leave the options blank to auto-detect
+ processors = option('num_processors').to_i
+ return processors if processors > 0
+
+ # otherwise, pull it from memory
+ processors = memory(:processors)
+
+ # if we didn't get it from memory, try to auto-detect through /proc/cpuinfo
+ unless processors && processors > 0
+ if `cat /proc/cpuinfo | grep 'model name' | wc -l` =~ /(\d+)/
+ processors = $1.to_i
+ else
+ raise "Couldn't use /proc/cpuinfo as expected."
+ end
+ raise "Couldn't use /proc/cpuinfo as expected." unless processors > 0
+ end
+ remember(:processors, processors)
+ return processors
end
-end
+end
View
7 load_averages/load_averages.yml
@@ -10,10 +10,3 @@ triggers:
- type: peak
dname: last_minute
max_value: 3
- - type: trend
- dname: last_minute
- direction: UP
- percentage_change: 60
- duration: 60
- window_reference: LAST_WEEK
- min_value: 0.2
Please sign in to comment.
Something went wrong with that request. Please try again.