Skip to content

Commit

Permalink
Merge branch 'master' of github.com:highgroove/scout-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Lewis committed Apr 5, 2012
2 parents 40840ca + 4fa9061 commit 796e180
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 24 deletions.
4 changes: 2 additions & 2 deletions haproxy_monitoring/haproxy_monitoring.rb
Expand Up @@ -64,9 +64,9 @@ def build_report
counter(:bytes_out, row['bout'].to_i, :per => :second) if row['bout']

report(:active_sessions => row['scur'])
report(:queued_sessions => row['qcur'])
report(:queued_sessions => row['qcur']) if row['qcur']

report(:active_servers => row['act'])
report(:active_servers => row['act']) if row['act']

report(:proxy_up=>%w(UP OPEN).find {|s| s == row['status']} ? 1 : 0)
end
Expand Down
4 changes: 2 additions & 2 deletions haproxy_monitoring/haproxy_monitoring.yml
Expand Up @@ -26,11 +26,11 @@ metadata:
units: /sec
precision: 1
active_sessions:
label: Active Sessions
label: Sessions Active
units: sessions
precision: 0
queued_sessions:
label: Queued Sessions
label: Sessions Queued
units: sessions
precision: 0
active_servers:
Expand Down
34 changes: 29 additions & 5 deletions process_memory/process_usage.rb
@@ -1,6 +1,20 @@
class ProcessUsage < Scout::Plugin
MEM_CONVERSION = 1024

OPTIONS=<<-EOS
command_name:
name: Command Name
notes: The name of the process you want to monitor.
ps_command:
name: The Process Status (ps) Command
notes: The command with options. The default works on most systems.
default: ps auxww
ps_regex:
name: The regex used to match a command name.
notes: "By default, this matches a command name anywhere in the ps output line. The word COMMAND get's replaced with the command you gave (regex escaped). You may wish to try the following pattern if you only want to match a command in the last column: (?i:COMMAND\\s+$)"
default: "(?i:\\bCOMMAND\\b)"
EOS

def build_report
if option(:command_name).nil? or option(:command_name) == ""
return error("Please specify the name of the process you want to monitor.")
Expand All @@ -19,16 +33,24 @@ def build_report
return error( "RSS or PID field not found.",
"The output from `#{ps_command}` did not include the needed RSS and PID fields." )
end
unless cpu_index = fields.index("%cpu")
return error( "%CPU field not found.",
"The output from `#{ps_command}` did not include the needed %CPU field." )
end

# narrow the ps lines to just those mentioning the process we're interested in
process_lines = ps_lines.grep(Regexp.new(ps_regex))

if process_lines.any?
rss_values = process_lines.map { |com| Float(com.split[memory_index]).abs }
pids = process_lines.map { |com| Integer(com.split[pid_index]) }
highest = rss_values.max
total = rss_values.inject(0){|s,value| s + value }
highest_rss = rss_values.max
total_rss = rss_values.inject(0){|s,value| s + value }
restarts = 0

cpu_values = process_lines.map { |com| Float(com.split[cpu_index]).abs }
highest_cpu = cpu_values.max
total_cpu = cpu_values.inject(0){|s,value| s + value }

if remembered_pids = memory(:pids)
# Find how many new pids we haven't seen before
Expand All @@ -42,10 +64,12 @@ def build_report
restarts = new_pids - started_pids
end

report(:memory => (highest/MEM_CONVERSION).to_i,
:total_rss => (total/MEM_CONVERSION).to_i,
report(:memory => (highest_rss/MEM_CONVERSION).to_i,
:total_rss => (total_rss/MEM_CONVERSION).to_i,
:num_processes => process_lines.size,
:restarts => restarts)
:restarts => restarts,
:cpu => highest_cpu,
:total_cpu => total_cpu)

remember(:pids => pids)
else
Expand Down
25 changes: 10 additions & 15 deletions process_memory/process_usage.yml
@@ -1,23 +1,10 @@
options:
command_name:
name: Command Name
notes: The name of the process you want to monitor.
ps_command:
name: The Process Status (ps) Command
notes: The command with options. The default works on most systems.
default: ps auxww
ps_regex:
name: The regex used to match a command name.
notes: "By default, this matches a command name anywhere in the ps output line. The word COMMAND get's replaced with the command you gave (regex escaped). You may wish to try the following pattern if you only want to match a command in the last column: (?i:COMMAND\\s+$)"
default: "(?i:\\bCOMMAND\\b)"

metadata:
memory:
label: Largest Process Memory Usage
label: Memory Usage (Largest Process)
units: MB
precision: 0
total_rss:
label: Total Memory Usage
label: Memory Usage (Total)
units: MB
precision: 0
num_processes:
Expand All @@ -28,6 +15,14 @@ metadata:
label: Restarts
units: ""
precision: 0
cpu:
label: CPU Usage (Largest Process)
units: %
precision: 1
total_cpu:
label: CPU Usage (Total)
units: %
precision: 1

triggers:
- type: peak
Expand Down

0 comments on commit 796e180

Please sign in to comment.