Projet

Général

Profil

Révision b0b39b01

IDb0b39b018e200cd0b771675fd0a6489f6ee9f045
Parent 26c29daa
Enfant 809639ab

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

Ruby plugins: apply style changes as suggested by "rubocop --fix-layout"

Voir les différences:

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

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

  
22 22
class PortMonit < Munin::Plugin
23

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

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

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

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

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

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

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

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

  
57 56
  def retrieve_values
58

  
59
    @_netstat   = %x[netstat -n -P tcp | egrep "\.#{PORT} "].split( "\n" )
60

  
61

  
62
    { :ESTABLISHED  => count( @_netstat, 'ESTABLISHED' ),
63
      :CLOSE_WAIT   => count( @_netstat, 'CLOSE_WAIT' ),
64
      :CLOSING      => count( @_netstat, 'CLOSING' ),
65
      :LAST_ACK     => count( @_netstat, 'LAST_ACK' ),
66
      :FIN_WAIT_1   => count( @_netstat, 'FIN_WAIT_1' ),
67
      :FIN_WAIT_2   => count( @_netstat, 'FIN_WAIT_2' ),
68
      :TIME_WAIT    => count( @_netstat, 'TIME_WAIT' ) }
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') }
69 66
  end
70 67

  
71 68
  private
72
  def count( source, regex )
69

  
70
  def count(source, regex)
73 71
    @_result = 0
74 72

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

  
77 75
    return @_result
78 76
  end

Formats disponibles : Unified diff