Projet

Général

Profil

Révision 809639ab

ID809639ab65d5460442c3b88beea0dace7665f416
Parent b0b39b01
Enfant 758c3ecd

Ajouté par Lars Kruse il y a plus de 5 ans

Ruby plugins: apply code changes as suggested by "rubocop --auto-correct"

Voir les différences:

plugins/other/port_
16 16
require 'munin'
17 17

  
18 18
SERVICE   = $0.split('_').last
19
SERVICE_F = '/etc/services'
20
PORT      = /^[\d]+(\.[\d]+){0,1}$/ === SERVICE ? SERVICE : %x[grep #{SERVICE} #{SERVICE_F}].split("\t\t")[1].split('/')[0]
19
SERVICE_F = '/etc/services'.freeze
20
PORT      = SERVICE =~ /^\d+(\.\d+){0,1}$/ ? SERVICE : `grep #{SERVICE} #{SERVICE_F}`.split("\t\t")[1].split('/')[0]
21 21

  
22 22
class PortMonit < Munin::Plugin
23 23
  graph_attributes "#{SERVICE} port usage, known as #{PORT}",
24
                   :category => 'network',
25
                   :info => 'This graph shows connection split by the state of the socket.',
26
                   :vlabel => 'Current connections'
24
                   category: 'network',
25
                   info: 'This graph shows connection split by the state of the socket.',
26
                   vlabel: 'Current connections'
27 27

  
28 28
  declare_field :ESTABLISHED,
29
                :label => 'Established', :draw => :AREA,
30
                :type => :GAUGE, :min => 0
29
                label: 'Established', draw: :AREA,
30
                type: :GAUGE, min: 0
31 31

  
32 32
  declare_field :CLOSE_WAIT,
33
                :label => 'Waiting close', :draw => :STACK,
34
                :type => :GAUGE, :min => 0
33
                label: 'Waiting close', draw: :STACK,
34
                type: :GAUGE, min: 0
35 35

  
36 36
  declare_field :TIME_WAIT,
37
                :label => 'Waiting after close', :draw => :STACK,
38
                :type => :GAUGE, :min => 0
37
                label: 'Waiting after close', draw: :STACK,
38
                type: :GAUGE, min: 0
39 39

  
40 40
  declare_field :CLOSING,
41
                :label => 'Closing', :draw => :STACK,
42
                :type => :GAUGE, :min => 0
41
                label: 'Closing', draw: :STACK,
42
                type: :GAUGE, min: 0
43 43

  
44 44
  declare_field :LAST_ACK,
45
                :label => 'Waiting for acknowledgement', :draw => :STACK,
46
                :type => :GAUGE, :min => 0
45
                label: 'Waiting for acknowledgement', draw: :STACK,
46
                type: :GAUGE, min: 0
47 47

  
48 48
  declare_field :FIN_WAIT_1,
49
                :label => 'Socket closed, connection shutting down', :draw => :STACK,
50
                :type => :GAUGE, :min => 0
49
                label: 'Socket closed, connection shutting down', draw: :STACK,
50
                type: :GAUGE, min: 0
51 51

  
52 52
  declare_field :FIN_WAIT_2,
53
                :label => 'Connection closed, Socket still waiting', :draw => :STACK,
54
                :type => :GAUGE, :min => 0
53
                label: 'Connection closed, Socket still waiting', draw: :STACK,
54
                type: :GAUGE, min: 0
55 55

  
56 56
  def retrieve_values
57
    @_netstat = %x[netstat -n -P tcp | egrep "\.#{PORT} "].split("\n")
58

  
59
    { :ESTABLISHED => count(@_netstat, 'ESTABLISHED'),
60
      :CLOSE_WAIT => count(@_netstat, 'CLOSE_WAIT'),
61
      :CLOSING => count(@_netstat, 'CLOSING'),
62
      :LAST_ACK => count(@_netstat, 'LAST_ACK'),
63
      :FIN_WAIT_1 => count(@_netstat, 'FIN_WAIT_1'),
64
      :FIN_WAIT_2 => count(@_netstat, 'FIN_WAIT_2'),
65
      :TIME_WAIT => count(@_netstat, 'TIME_WAIT') }
57
    @_netstat = `netstat -n -P tcp | egrep "\.#{PORT} "`.split("\n")
58

  
59
    { ESTABLISHED: count(@_netstat, 'ESTABLISHED'),
60
      CLOSE_WAIT: count(@_netstat, 'CLOSE_WAIT'),
61
      CLOSING: count(@_netstat, 'CLOSING'),
62
      LAST_ACK: count(@_netstat, 'LAST_ACK'),
63
      FIN_WAIT_1: count(@_netstat, 'FIN_WAIT_1'),
64
      FIN_WAIT_2: count(@_netstat, 'FIN_WAIT_2'),
65
      TIME_WAIT: count(@_netstat, 'TIME_WAIT') }
66 66
  end
67 67

  
68 68
  private
......
72 72

  
73 73
    source.each { |obj| @_result += 1 if obj.match(regex) }
74 74

  
75
    return @_result
75
    @_result
76 76
  end
77 77
end
78 78

  

Formats disponibles : Unified diff