check_tcp_memory 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adc34fac21de8d3fb84f76fd96c88ff78eaa1881
4
+ data.tar.gz: 5f33fc6fae3edc589a73a42e5d03aa6e4859d80f
5
+ SHA512:
6
+ metadata.gz: 53d42aa0c4610cf9ce652c98c04ec35dce3f1cbfa278de291757e4ce2daca8633ffbd851f63af1e263b2cfdd72fc38c518253e86305a7a054c88f85a1c6a1506
7
+ data.tar.gz: 72e970b6ead8bddc1c9b48db0904670e31f1c7c4fc68043bc93958735d03e0032aae42a899de8719fba1c2dfeb090d10ab7763ef9733d3e82bb9115e8db85cb6
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in check_tcp_memory.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ # CheckTCPMemory
2
+
3
+ This is a simple Nagios/Sensu check that checks that the current TCP memory usage is below the maximum allowed in the Linux kernel. This will find leaking TCP sockets.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'check_tcp_memory'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install check_tcp_memory
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ $ check_tcp_memory -h
25
+ Usage: check_tcp_memory -w <warn percent> -c <critical percent>
26
+ -w, --warn-percent PERCENT Warning when percentage of total TCP memory is over this threashold. Default: 50%
27
+ -c, --crit-percent PERCENT Critical when percentage of total TCP memory is over this threashold. Default: 60%
28
+ -h, --help Show this message
29
+ --version Show version
30
+ ```
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Altiscale/check_tcp_memory. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "check_tcp_memory"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'check_tcp_memory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "check_tcp_memory"
8
+ spec.version = CheckTCPMemory::VERSION
9
+ spec.authors = ["Travis Thompson"]
10
+ spec.email = ["travis@altiscale.com"]
11
+
12
+ spec.summary = %q{Nagios/Sensu check to check amount of TCP memory allocated as a percentage of available TCP memory.}
13
+ spec.description = File.read(File.join(__dir__, 'README.md'))
14
+ spec.homepage = "https://github.com/Altiscale/check_tcp_memory"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "nagiosplugin", "~> 3.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'check_tcp_memory'
4
+ require 'check_tcp_memory/cli'
5
+ require 'check_tcp_memory/check'
6
+
7
+ CheckTCPMemory::Check.run! CheckTCPMemory::CLI.parse(ARGV)
@@ -0,0 +1,5 @@
1
+ require "check_tcp_memory/version"
2
+
3
+ module CheckTCPMemory
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,38 @@
1
+ require 'check_tcp_memory'
2
+ require 'nagiosplugin'
3
+
4
+ module CheckTCPMemory
5
+ class Check < Nagios::Plugin
6
+ def initialize(options)
7
+ @warn_percent = options[:warn_percent]
8
+ @crit_percent = options[:crit_percent]
9
+ end
10
+
11
+ def critical?
12
+ @percent_used >= @crit_percent
13
+ end
14
+
15
+ def warning?
16
+ @percent_used >= @warn_percent
17
+ end
18
+
19
+ def ok?
20
+ true
21
+ end
22
+
23
+ def check
24
+ #@mem_max = File.read('/proc/sys/net/ipv4/tcp_mem').split()[2]
25
+ @mem_max = File.read('/tmp/tcp_mem').split()[2].to_f
26
+ #@current_usage = File.read('/proc/net/sockstat').gsub(':','').split("\n")\
27
+ @current_usage = File.read('/tmp/sockstat').gsub(':','').split("\n")\
28
+ .map{|a| b=a.split; Hash[b.shift, Hash[*b]]}\
29
+ .reduce({}, :merge)['TCP']['mem'].to_f
30
+ @percent_used = @current_usage / @mem_max
31
+ end
32
+
33
+ def message
34
+ "Percent Used: #{"%5.2f" % (@percent_used * 100)}%, "\
35
+ "Current Usage: #{@current_usage}, Max TCP Memory: #{@mem_max}"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,46 @@
1
+ require 'check_tcp_memory'
2
+ require 'optparse'
3
+ require 'ostruct'
4
+
5
+ module CheckTCPMemory
6
+ class CLI
7
+ def self.parse(args)
8
+ options = OpenStruct.new
9
+ options[:warn_percent] = 0.5
10
+ options[:crit_percent] = 0.6
11
+
12
+ opt_parser = OptionParser.new do |opts|
13
+ opts.banner = "Usage: #{$0} -w <warn percent> -c <critical percent>"
14
+ opts.on('-w', '--warn-percent PERCENT', 'Warning when percentage of total TCP memory is over this threashold. Default: 50%') do |ret|
15
+ if ret.to_f > 100 || ret.to_f <= 0
16
+ puts "Warning percent out of range! must be between 1-100"
17
+ exit 1
18
+ end
19
+ options[:warn_percent] = ret.to_f / 100.0
20
+ end
21
+
22
+ opts.on('-c', '--crit-percent PERCENT', 'Critical when percentage of total TCP memory is over this threashold. Default: 60%') do |ret|
23
+ if ret.to_f > 100 || ret.to_f <= 0
24
+ puts "Critical percent out of range! must be between 1-100"
25
+ exit 1
26
+ end
27
+ options[:crit_percent] = ret.to_f / 100.0
28
+ end
29
+
30
+ opts.on_tail("-h", "--help", "Show this message") do
31
+ puts opts
32
+ exit
33
+ end
34
+
35
+ opts.on_tail("--version", "Show version") do
36
+ puts CheckTCPMemory::VERSION
37
+ exit
38
+ end
39
+ end
40
+
41
+ opt_parser.parse!(args)
42
+
43
+ return options
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module CheckTCPMemory
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_tcp_memory
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Travis Thompson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nagiosplugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |+
70
+ # CheckTCPMemory
71
+
72
+ This is a simple Nagios/Sensu check that checks that the current TCP memory usage is below the maximum allowed in the Linux kernel. This will find leaking TCP sockets.
73
+
74
+ ## Installation
75
+
76
+ Add this line to your application's Gemfile:
77
+
78
+ ```ruby
79
+ gem 'check_tcp_memory'
80
+ ```
81
+
82
+ And then execute:
83
+
84
+ $ bundle
85
+
86
+ Or install it yourself as:
87
+
88
+ $ gem install check_tcp_memory
89
+
90
+ ## Usage
91
+
92
+ ```
93
+ $ check_tcp_memory -h
94
+ Usage: check_tcp_memory -w <warn percent> -c <critical percent>
95
+ -w, --warn-percent PERCENT Warning when percentage of total TCP memory is over this threashold. Default: 50%
96
+ -c, --crit-percent PERCENT Critical when percentage of total TCP memory is over this threashold. Default: 60%
97
+ -h, --help Show this message
98
+ --version Show version
99
+ ```
100
+
101
+ ## Development
102
+
103
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
104
+
105
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
106
+
107
+ ## Contributing
108
+
109
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Altiscale/check_tcp_memory. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
110
+
111
+ email:
112
+ - travis@altiscale.com
113
+ executables:
114
+ - check_tcp_memory
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - check_tcp_memory.gemspec
128
+ - exe/check_tcp_memory
129
+ - lib/check_tcp_memory.rb
130
+ - lib/check_tcp_memory/check.rb
131
+ - lib/check_tcp_memory/cli.rb
132
+ - lib/check_tcp_memory/version.rb
133
+ homepage: https://github.com/Altiscale/check_tcp_memory
134
+ licenses: []
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.6
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Nagios/Sensu check to check amount of TCP memory allocated as a percentage
156
+ of available TCP memory.
157
+ test_files: []