Permalink
Browse files

Merge branch 'master' of github.com:scoutapp/scout-plugins

  • Loading branch information...
2 parents 6b5e01d + 8997a31 commit 43d267a1cfa80c734ad841a52ea08469e1f37a1f @itsderek23 itsderek23 committed Nov 9, 2012
Showing with 172 additions and 19 deletions.
  1. +105 −0 passenger/passenger.rb
  2. +66 −0 passenger/passenger.yml
  3. +1 −1 swappiness/README
  4. +0 −18 swappiness/swappiness.yml
View
@@ -0,0 +1,105 @@
+#
+# This combines the passenger_memory_stats and passenger_status plugins
+# and removes the notification that should be triggers
+#
+# Combination by Eric Lindvall <eric@sevenscale.com>
+#
+
+class PassengerStats < Scout::Plugin
+
+ OPTIONS=<<-EOS
+ passenger_memory_stats_command:
+ name: The Passenger Memory Stats Command
+ notes: The full path to the passenger-memory-stats command (possibly with sudo).
+ default: sudo /usr/bin/passenger-memory-stats
+ passenger_status_command:
+ name: The Passenger Status Command
+ notes: The full path to the passenger-status command (possibly with sudo).
+ default: sudo /usr/bin/passenger-status
+ EOS
+
+ def build_report
+ passenger_status
+ memory_stats
+ rescue Exception => e
+ error "Error while executing plugin: #{e.class}: #{e.message}"
+ end
+
+ private
+ def passenger_status
+ cmd = option(:passenger_status_command) || "passenger-status"
+ data = `#{cmd} 2>&1`
+ unless $?.success?
+ error "Could not get data from command: #{cmd}", "Error: #{data}"
+ return
+ end
+
+ stats = {}
+
+ data.each_line do |line|
+ if line =~ /^max\s+=\s(\d+)/
+ stats["passenger_max_pool_size"] = $1
+ elsif line =~ /^count\s+=\s(\d+)/
+ stats["passenger_process_current"] = $1
+ elsif line =~ /^active\s+=\s(\d+)/
+ stats["passenger_process_active"] = $1
+ elsif line =~ /^inactive\s+=\s(\d+)/
+ stats["passenger_process_inactive"] = $1
+ elsif line =~ /^Waiting on global queue: (\d+)/
+ stats["passenger_queue_depth"] = $1
+ end
+ end
+
+ report(stats)
+ end
+
+ def memory_stats
+ cmd = option(:passenger_memory_stats_command) || "passenger-memory-stats"
+ data = `#{cmd} 2>&1`
+ unless $?.success?
+ error "Could not get data from command: #{cmd}", "Error: #{data}"
+ return
+ end
+
+ table = nil
+ headers = nil
+ field_format = nil
+ stats = Hash.new { |h,k| h[k] = 0.0 }
+
+ data.each_line do |line|
+ line = line.gsub(/\e\[\d+m/,'')
+ if line =~ /^\s*-+\s+(Apache|Passenger|Nginx)\s+processes/
+ table = $1.downcase
+ headers = nil
+ field_format = nil
+ elsif table and line =~ /^\s*###\s+Processes:\s*(\d+)/ and table != 'passenger'
+ stats["#{table}_processes"] = $1
+ elsif table and line =~ /^[A-Za-z]/
+ headers = line.scan(/\S+\s*/)
+ field_format = headers.map { |h| "A#{h.size - 1}" }.join("x").
+ sub(/\d+\z/, "*")
+ headers.map! { |h| h.strip.downcase }
+ elsif table and headers and line =~ /^\d/
+ fields = Hash[*headers.zip(line.strip.unpack(field_format)).flatten]
+ stats["#{table}_vmsize_total"] += as_mb(fields["vmsize"])
+ stats["#{table}_private_total"] += as_mb(fields["private"])
+ end
+ end
+
+ report(stats)
+ end
+
+ def as_mb(memory_string)
+ num = memory_string.to_f
+ case memory_string
+ when /\bB/i
+ num / 1024.0 / 1024.0
+ when /\bKB/i
+ num / 1024.0
+ when /\bGB/i
+ num * 1024.0
+ else
+ num
+ end
+ end
+end
@@ -0,0 +1,66 @@
+metadata:
+ passenger_max_pool_size:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Passenger Max Pool Size
+ passenger_process_current:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Passenger Running Processes
+ passenger_process_active:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Passenger Active Processes
+ passenger_process_inactive:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Passenger Inactive Processes
+ passenger_queue_depth:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Passenger Global Queue Depth
+ apache_private_total:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Apache private total
+ apache_processes:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Apache processes
+ passenger_vmsize_total:
+ units: "MB"
+ delimiter: ","
+ precision: "0"
+ label: Passenger vmsize total
+ nginx_vmsize_total:
+ units: "MB"
+ delimiter: ","
+ precision: "0"
+ label: Nginx vmsize total
+ nginx_processes:
+ units: ""
+ delimiter: ","
+ precision: "0"
+ label: Nginx processes
+ passenger_private_total:
+ units: "MB"
+ delimiter: ","
+ precision: "0"
+ label: Passenger private total
+ nginx_private_total:
+ units: "MB"
+ delimiter: ","
+ precision: "0"
+ label: Nginx private total
+ apache_vmsize_total:
+ units: "MB"
+ delimiter: ","
+ precision: "0"
+ label: Apache vmsize total
View
@@ -5,7 +5,7 @@ Created by [Eric Lindvall](http://twitter.com/lindvall)
Overview
------------
-Reports on various SWAP-related memory metrics, generating alerts if Swap-Ins and/or Swap-Outs increase significantly.
+Reports on various SWAP-related memory metrics. Can generate alerts if Swap-Ins and/or Swap-Outs increase significantly.
Dependencies
------------
@@ -1,44 +1,26 @@
metadata:
Swap-ins:
units: "KB/s"
- larger_is_better: "0"
delimiter: ","
precision: "0"
label: Swap-ins
Swap-outs:
units: "KB/s"
- larger_is_better: "0"
delimiter: ","
precision: "0"
label: Swap-outs
Page-ins:
units: "pages/s"
- larger_is_better: "0"
delimiter: ","
precision: "0"
label: Page-ins
Page-outs:
units: "pages/s"
- larger_is_better: "0"
delimiter: ","
precision: "0"
label: Page-outs
Page Faults:
units: "faults/s"
- larger_is_better: "0"
delimiter: ","
precision: "0"
label: Page faults
-triggers:
-- percentage_change: 100
- type: trend
- min_value: 0
- window_reference: PRECEDING_WINDOW
- dname: Swap-ins
- direction: UP
-- percentage_change: 100
- type: trend
- min_value: 0
- window_reference: PRECEDING_WINDOW
- dname: Swap-outs
- direction: UP

0 comments on commit 43d267a

Please sign in to comment.