mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 18:41:03 +00:00
Ruby plugins: apply code changes as suggested by "rubocop --auto-correct"
This commit is contained in:
parent
b0b39b018e
commit
809639ab65
33 changed files with 904 additions and 910 deletions
|
@ -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 <dot.doom@gmail.com>
|
||||
|
||||
|
||||
#%# 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue