Sha256: 664441a47e2356db7483443125f16883255ba040254d58cdcdc25014df94bfe6

Contents?: true

Size: 880 Bytes

Versions: 35

Compression:

Stored size: 880 Bytes

Contents

class Riemann::Babbler::NetStat < Riemann::Babbler

  def init
    plugin.set_default(:service, 'netstat')
    plugin.set_default(:interval, 5)
    plugin.set_default(:ports, [80, 3994])
    plugin.states.set_default(:warning, nil)
    plugin.states.set_default(:critical, nil)
  end

  def get_conn_count
    filter = nil
    plugin.ports.each do |port|
      if filter == nil
        filter = "\\( src *:#{port}"
      else
        filter += " or src *:#{port}"
      end
    end
    filter += " \\) and not dst 127.0.0.1:*"
    cmd = "ss -t -4 -n state established " + filter + " | wc -l"
    shell(cmd).to_i - 1
  end

  def collect
    count = get_conn_count()
    {
      :service => "#{plugin.service} tcp #{plugin.ports.join(', ')}",
      :metric => count, 
      :description => "count established connects: #{count} to ports #{plugin.ports.join(', ')}"
    }
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
riemann-babbler-1.2.6 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.2.5 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.2.4 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.2.3 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.2.2 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.2.1 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.2.0 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.1.9 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.1.7 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.1.6 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.0.8.8 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.0.8.7 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.0.8.6 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.0.8.5 lib/riemann/babbler/plugins/net_stat.rb
riemann-babbler-1.0.8.4 lib/riemann/babbler/plugins/net_stat.rb