es-diag 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+
4
+
5
+ # Specify your gem's dependencies in es-diag.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ # ES-Diag
2
+
3
+ `es-diag` is a command line tool that evaluates your machine and setup, points out typical machine misconfiguration for Elastic Search, sniffs out health parameters from a running Elastic Search instance (not impl. yet), and recommends ways to amend it.
4
+
5
+
6
+
7
+
8
+ ## Getting Started
9
+
10
+ You need to have a recent Ruby on your system.
11
+
12
+ $ gem install es-diag
13
+ $ es-diag status
14
+ # should output a lot of useful data if your system
15
+ # isn't healthy. a list of things it checked otherwise.
16
+
17
+
18
+ ## Adding checks
19
+
20
+ `es-diag` will run a series of predefined checks. My hope is that you can add checks and
21
+ submit pull requests very easily.
22
+
23
+
24
+ Writing a check is designed to be VERY easy, using a simple DSL. Lets take a look at an
25
+ example:
26
+
27
+ # set the check title
28
+ title "ulimit set appropriately - avoid 'Too many open files'"
29
+
30
+ # specify actions to take to amend problems that can be detected
31
+ # by this check.
32
+ how_to """
33
+ To raise the limit add to /etc/security/limits.conf the lines:
34
+
35
+ elasticsearch soft nofile 32000
36
+ elasticsearch hard nofile 32000
37
+
38
+ If you still see the previous limit, run:
39
+
40
+ $ egrep -r pam_limits /etc/pam.d/
41
+
42
+ and check that all pam_limits.so are not commented out.
43
+
44
+ Now you can run to verify:
45
+
46
+ $ bin/elasticsearch -f -Des.max-open-files=true
47
+ [2011-04-05 04:12:02,687][INFO ][bootstrap] max_open_files [32000]
48
+ """
49
+
50
+ # Here, you have a property bag called 'data' that is
51
+ # exposed via Opscode/ohai [here is a sample](https://gist.github.com/2381589).
52
+ # If you want to sample your own system:
53
+ #
54
+ # $ gem install ohai
55
+ # $ ohai
56
+ #
57
+ # It is most probably that `data` will contain additional properties
58
+ # not originating from ohai in the future.
59
+ #
60
+ if data.ulimit['soft']['nofiles'] < 32_000
61
+ warn "Increment your soft file limit (#{data.ulimit['soft']['nofiles']}) to 32000"
62
+ end
63
+ if data.ulimit['hard']['nofiles'] < 32_000
64
+ warn "Increment your hard file limit (#{data.ulimit['hard']['nofiles']}) to 32000"
65
+ end
66
+
67
+ Next, put all of this in a file and drop it in the `lib/checks` folder.
68
+ It will be picked up automatically.
69
+
70
+
71
+ # Contributing
72
+
73
+ Fork, implement, add tests, pull request, get my everlasting thanks and a respectable place here :).
74
+
75
+
76
+ # Copyright
77
+
78
+
79
+ Copyright (c) 2012 [Dotan Nahum](http://gplus.to/dotan) [@jondot](http://twitter.com/jondot). See MIT-LICENSE for further details.
80
+
81
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/es-diag ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "es-diag/cli"
4
+
5
+ ES::Diag::CLI.start
6
+
data/es-diag.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "es-diag/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "es-diag"
7
+ s.version = ES::Diag::VERSION
8
+ s.authors = ["Dotan Nahum"]
9
+ s.email = ["jondotan@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Elastic Search diagnostics tool}
12
+ s.description = %q{Elastic Search diagnostics tool}
13
+
14
+ s.rubyforge_project = "es-diag"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "thor"
24
+ s.add_runtime_dependency "ohai"
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ title "ulimit set appropriately - avoid 'Too many open files'"
2
+
3
+ how_to """
4
+ To raise the limit add to /etc/security/limits.conf the lines:
5
+
6
+ elasticsearch soft nofile 32000
7
+ elasticsearch hard nofile 32000
8
+
9
+ If you still see the previous limit, run:
10
+
11
+ $ egrep -r pam_limits /etc/pam.d/
12
+
13
+ and check that all pam_limits.so are not commented out.
14
+
15
+ Now you can run to verify:
16
+
17
+ $ bin/elasticsearch -f -Des.max-open-files=true
18
+ [2011-04-05 04:12:02,687][INFO ][bootstrap] max_open_files [32000]
19
+ """
20
+ if data.ulimit['soft']['nofiles'] < 32_000
21
+ warn "Increment your soft file limit (#{data.ulimit['soft']['nofiles']}) to 32000"
22
+ end
23
+ if data.ulimit['hard']['nofiles'] < 32_000
24
+ warn "Increment your hard file limit (#{data.ulimit['hard']['nofiles']}) to 32000"
25
+ end
@@ -0,0 +1,45 @@
1
+ class ES::Diag::Check
2
+ def initialize(ui)
3
+ @ui = ui
4
+ end
5
+
6
+ def title(text)
7
+ @run_context[:title] = text
8
+ end
9
+
10
+ def data
11
+ ES::Diag::Context.data
12
+ end
13
+
14
+ def how_to(text)
15
+ @run_context[:help ] = text
16
+ end
17
+
18
+ def warn(text)
19
+ @run_context[:warnings] ||= []
20
+ @run_context[:warnings] << text
21
+ end
22
+
23
+
24
+ def all_checks
25
+ Dir[File.expand_path('../checks/*.rb', File.dirname(__FILE__))].each do |fcheck|
26
+ run_check(fcheck)
27
+ end
28
+ end
29
+
30
+ def run_check(filename)
31
+ @run_context = {}
32
+ self.instance_eval(IO.read(filename), filename, 1)
33
+ @ui.title @run_context[:title] || "#{filename}"
34
+ if @run_context[:warnings] && @run_context[:warnings].length > 0
35
+ @ui.warn "#{@run_context[:warnings].length} problem(s) found:"
36
+ @run_context[:warnings].each do | warning |
37
+ @ui.warn "- #{warning}"
38
+ end
39
+ if @run_context[:help]
40
+ @ui.info "\n\nUse these instructions to amend the problems:"
41
+ @ui.info @run_context[:help] + "\n"
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,32 @@
1
+ require 'es-diag'
2
+ require 'thor'
3
+ require 'es-diag'
4
+
5
+
6
+ class ES::Diag::CLI < Thor
7
+
8
+ desc "status", "report back current status and recommendations."
9
+ def status
10
+ say "Checking..."
11
+ c = ES::Diag::Check.new(self)
12
+ c.all_checks
13
+
14
+ end
15
+
16
+
17
+
18
+ no_tasks do
19
+ def title(text)
20
+ say "* #{text}"
21
+ end
22
+
23
+ def info(detail=nil)
24
+ say detail, :green
25
+ end
26
+
27
+ def warn(detail)
28
+ say detail, :yellow
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,5 @@
1
+ module ES
2
+ module Diag
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/es-diag.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "es-diag/version"
2
+ require 'ohai'
3
+
4
+
5
+ module ES
6
+ module Diag
7
+ module Context
8
+ def self.data
9
+ unless @ohai
10
+ Ohai::Config[:plugin_path] << File.expand_path('ohai_plugins', File.dirname(__FILE__))
11
+ @ohai= Ohai::System.new
12
+ @ohai.all_plugins
13
+ end
14
+ @ohai
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require 'es-diag/check'
21
+
@@ -0,0 +1,24 @@
1
+ provides "ulimit"
2
+
3
+
4
+ ulimits = Mash.new
5
+ ulimits['soft'] = Mash.new
6
+ ulimits['hard'] = Mash.new
7
+
8
+
9
+ [["sh -c 'ulimit -Sa'", ulimits['soft']],
10
+ ["sh -c 'ulimit -Ha'", ulimits['hard']]
11
+ ].each do |cmd,uhash|
12
+ popen4(cmd) do |pid, stdin, stdout, stderr|
13
+ stdin.close
14
+
15
+ stdout.each do |line|
16
+ case line
17
+ when /^(.+)\s+(.+)$/
18
+ uhash[$1.split('(')[0].strip] = $2 == "unlimited" ? "unlimited" : $2.to_i
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ ulimit ulimits
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: es-diag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dotan Nahum
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-14 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &74162070 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *74162070
25
+ - !ruby/object:Gem::Dependency
26
+ name: ohai
27
+ requirement: &74161740 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *74161740
36
+ description: Elastic Search diagnostics tool
37
+ email:
38
+ - jondotan@gmail.com
39
+ executables:
40
+ - es-diag
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - bin/es-diag
49
+ - es-diag.gemspec
50
+ - lib/checks/ulimits.rb
51
+ - lib/es-diag.rb
52
+ - lib/es-diag/check.rb
53
+ - lib/es-diag/cli.rb
54
+ - lib/es-diag/version.rb
55
+ - lib/ohai_plugins/ulimit.rb
56
+ homepage: ''
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project: es-diag
76
+ rubygems_version: 1.8.10
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Elastic Search diagnostics tool
80
+ test_files: []