forked from munin-monitoring/contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ruby plugins: apply code changes as suggested by "rubocop --auto-corr…
…ect"
- Loading branch information
1 parent
b0b39b0
commit 809639a
Showing
33 changed files
with
924 additions
and
930 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Allow "=begin"/"=end" multiline comments in order to protect munin's | ||
# magic markers ("#%#"). | ||
Style/BlockComments: | ||
Enabled: false | ||
|
||
AllCops: | ||
NewCops: enable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,24 +9,22 @@ This plugin shows various statistics from 'netstat -m' | |
Required privileges: none | ||
OS: | ||
Supposed: BSD | ||
Tested: FreeBSD 8.2 | ||
Supposed: BSD | ||
Tested: FreeBSD 8.2 | ||
Author: Artem Sheremet <[email protected]> | ||
#%# family=auto | ||
#%# capabilities=autoconf suggest | ||
=end | ||
|
||
|
||
# original filename | ||
PLUGIN_NAME = 'netstat_bsd_m_' | ||
PLUGIN_NAME = 'netstat_bsd_m_'.freeze | ||
|
||
class String | ||
def escape | ||
self.gsub /[^\w]/, '_' | ||
gsub(/[^\w]/, '_') | ||
end | ||
|
||
unless method_defined? :start_with? | ||
|
@@ -37,17 +35,20 @@ class String | |
end | ||
|
||
def netstat_m(filter = nil) | ||
Hash[`netstat -m`.split($/).map { |line| | ||
if line =~ /^([\d\/K]+) (.*) \(([\w\/+]+)\)$/ | ||
Hash[`netstat -m`.split($/).map do |line| | ||
if line =~ %r{^([\d/K]+) (.*) \(([\w/+]+)\)$} | ||
# 7891K/22385K/30276K bytes allocated to network (current/cache/total) | ||
values, desc, names = $1, $2, $3 | ||
[desc, names.split('/').zip(values.split '/')] if filter.nil? or desc.escape == filter | ||
values = Regexp.last_match(1) | ||
desc = Regexp.last_match(2) | ||
names = Regexp.last_match(3) | ||
[desc, names.split('/').zip(values.split('/'))] if filter.nil? || (desc.escape == filter) | ||
elsif line =~ /^(\d+) (.*)$/ | ||
# 12327 requests for I/O initiated by sendfile | ||
value, desc = $1, $2 | ||
[desc, [[:value, value]]] if filter.nil? or desc.escape == filter | ||
value = Regexp.last_match(1) | ||
desc = Regexp.last_match(2) | ||
[desc, [[:value, value]]] if filter.nil? || (desc.escape == filter) | ||
end | ||
}.compact] | ||
end.compact] | ||
end | ||
|
||
stat_name = File.basename($0, '.*').escape | ||
|
@@ -74,7 +75,7 @@ when 'config' | |
CONFIG | ||
puts values.map { |name, _| | ||
esc_name = name.to_s.escape | ||
"#{esc_name}.draw " + if %w(total max).include? name | ||
"#{esc_name}.draw " + if %w[total max].include? name | ||
'LINE' | ||
elsif stack | ||
if first | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,59 +34,58 @@ Contributors: Adam Jacob (<[email protected]>) | |
=end | ||
|
||
|
||
module Munin | ||
class MongrelProcessMemory | ||
def run | ||
pid_port_map = get_pids() | ||
port_list = Hash.new | ||
pid_port_map = get_pids | ||
port_list = {} | ||
pid_port_map.sort.each do |pid, port| | ||
rss = `pmap -x #{pid} | grep total`.split(" ")[3] | ||
rss = `pmap -x #{pid} | grep total`.split(' ')[3] | ||
puts "mongrel_#{port}.value #{rss}" | ||
end | ||
end | ||
|
||
def get_pids | ||
h = Hash.new | ||
h = {} | ||
pids = [] | ||
pids += `pgrep mongrel_rails`.split("\n") | ||
pids += `pgrep ruby`.split("\n") | ||
pids.each { |pid| | ||
pids.each do |pid| | ||
l = `pargs -l #{pid}` | ||
l =~ /-p (\d+)/ | ||
h[pid] = $1 if $1 | ||
} | ||
h[pid] = Regexp.last_match(1) if Regexp.last_match(1) | ||
end | ||
h | ||
end | ||
|
||
def autoconf | ||
get_pids().length > 0 | ||
get_pids.length > 0 | ||
end | ||
end | ||
end | ||
|
||
mpm = Munin::MongrelProcessMemory.new | ||
|
||
case ARGV[0] | ||
when "config" | ||
puts "graph_title Mongrel Memory" | ||
puts "graph_vlabel RSS" | ||
puts "graph_category memory" | ||
puts "graph_args --base 1024 -l 0" | ||
puts "graph_scale yes" | ||
puts "graph_info Tracks the size of individual mongrel processes" | ||
when 'config' | ||
puts 'graph_title Mongrel Memory' | ||
puts 'graph_vlabel RSS' | ||
puts 'graph_category memory' | ||
puts 'graph_args --base 1024 -l 0' | ||
puts 'graph_scale yes' | ||
puts 'graph_info Tracks the size of individual mongrel processes' | ||
mpm.get_pids.values.sort.each do |port| | ||
puts "mongrel_#{port}.label mongrel_#{port}" | ||
puts "mongrel_#{port}.info Process memory" | ||
puts "mongrel_#{port}.type GAUGE" | ||
puts "mongrel_#{port}.min 0" | ||
end | ||
when "autoconf" | ||
when 'autoconf' | ||
if mpm.autoconf | ||
puts "yes" | ||
puts 'yes' | ||
exit 0 | ||
end | ||
puts "no" | ||
puts 'no' | ||
exit 0 | ||
else | ||
mpm.run | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,27 +28,24 @@ Contributors: Adam Jacob (<[email protected]>) | |
=end | ||
|
||
|
||
module Munin | ||
class MongrelProcessMemory | ||
def run | ||
h = get_pids() | ||
ps_output = "" | ||
h = get_pids | ||
ps_output = '' | ||
# I have no doubt that this is a terrible way of doing this. | ||
h.each do |k, v| | ||
ps_output = ps_output + `ps --no-heading l #{k}` | ||
h.each do |k, _v| | ||
ps_output += `ps --no-heading l #{k}` | ||
end | ||
|
||
if ps_output | ||
port_list = Hash.new | ||
port_list = {} | ||
ps_output.each_line do |l| | ||
if l =~ /-p (\d+)/ | ||
port = $1 | ||
l_ary = l.split(/\s+/) | ||
if l_ary.length > 6 | ||
port_list[port] = l_ary[7].to_i * 1024 | ||
end | ||
end | ||
next unless l =~ /-p (\d+)/ | ||
|
||
port = Regexp.last_match(1) | ||
l_ary = l.split(/\s+/) | ||
port_list[port] = l_ary[7].to_i * 1024 if l_ary.length > 6 | ||
end | ||
port_list.sort.each do |port| | ||
puts "mongrel_#{port[0]}.value #{port[1]}" | ||
|
@@ -58,14 +55,14 @@ module Munin | |
end | ||
|
||
def get_pids | ||
h = Hash.new | ||
h = {} | ||
pids = [] | ||
pids = `pgrep mongrel_rails` | ||
pids.each { |p| | ||
pids.each do |p| | ||
l = `ps #{p}` | ||
l =~ /-p (\d+)/ | ||
h[p] = $1 | ||
} | ||
h[p] = Regexp.last_match(1) | ||
end | ||
h | ||
end | ||
|
||
|
@@ -78,25 +75,25 @@ end | |
mpm = Munin::MongrelProcessMemory.new | ||
|
||
case ARGV[0] | ||
when "config" | ||
puts "graph_title Mongrel Memory" | ||
puts "graph_vlabel RSS" | ||
puts "graph_category memory" | ||
puts "graph_args --base 1024 -l 0" | ||
puts "graph_scale yes" | ||
puts "graph_info Tracks the size of individual mongrel processes" | ||
when 'config' | ||
puts 'graph_title Mongrel Memory' | ||
puts 'graph_vlabel RSS' | ||
puts 'graph_category memory' | ||
puts 'graph_args --base 1024 -l 0' | ||
puts 'graph_scale yes' | ||
puts 'graph_info Tracks the size of individual mongrel processes' | ||
mpm.get_pids.values.sort.each do |port| | ||
puts "mongrel_#{port}.label mongrel_#{port}" | ||
puts "mongrel_#{port}.info Process memory" | ||
puts "mongrel_#{port}.type GAUGE" | ||
puts "mongrel_#{port}.min 0" | ||
end | ||
when "autoconf" | ||
when 'autoconf' | ||
if mpm.autoconf | ||
puts "yes" | ||
puts 'yes' | ||
exit 0 | ||
end | ||
puts "no" | ||
puts 'no' | ||
exit 0 | ||
else | ||
mpm.run | ||
|
Oops, something went wrong.